copy and paste in program
Joel Christensen
joelcnz at gmail.com
Mon Sep 12 15:02:57 PDT 2011
Thanks so much Jimmy. You put in a bit of effort. :-)
I just added this code to my general library:
>>
extern(Windows) {
bool OpenClipboard(void*);
void* GetClipboardData(uint);
void* SetClipboardData(uint, void*);
bool EmptyClipboard();
bool CloseClipboard();
void* GlobalAlloc(uint, size_t);
void* GlobalLock(void*);
bool GlobalUnlock(void*);
}
string getTextClipBoard() {
if (OpenClipboard(null)) {
scope( exit ) CloseClipboard();
auto cstr = cast(char*)GetClipboardData( 1 );
if(cstr)
return cstr[0..strlen(cstr)].idup;
}
return null;
}
string setTextClipboard( string mystr ) {
if (OpenClipboard(null)) {
scope( exit ) CloseClipboard();
EmptyClipboard();
void* handle = GlobalAlloc(2, mystr.length + 1);
void* ptr = GlobalLock(handle);
memcpy(ptr, toStringz(mystr), mystr.length + 1);
GlobalUnlock(handle);
SetClipboardData( 1, handle);
}
return mystr;
}
<<
More information about the Digitalmars-d-learn
mailing list