copy and paste in program
Jimmy Cao
jcao219 at gmail.com
Mon Sep 12 14:33:40 PDT 2011
The other way is a bit more complicated.
Try this:
import std.stdio;
import core.stdc.string;
import std.string;
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*);
}
void main() {
if (OpenClipboard(null)) {
auto cstr = cast(char*)GetClipboardData( 1 );
if(cstr)
writeln(cstr[0..strlen(cstr)]);
EmptyClipboard();
auto mystr = "my data";
void* handle = GlobalAlloc(2, mystr.length + 1);
void* ptr = GlobalLock(handle);
memcpy(ptr, toStringz(mystr), mystr.length + 1);
GlobalUnlock(handle);
SetClipboardData( 1, handle);
CloseClipboard();
}
}
On Sun, Sep 11, 2011 at 10:50 PM, Joel Christensen <joelcnz at gmail.com>wrote:
> Thanks Jimmy. Your example worked. Or though I haven't managed to get the
> other way to work.
>
> [code]
>
> import std.stdio;
> //import core.stdc.string;
> import std.c.string;
> import std.string;
> import std.conv;
>
> extern(Windows) {
> bool OpenClipboard(void*);
> void* GetClipboardData(uint);
> void* SetClipboardData(uint, void*);
>
> }
>
> void main() {
> if (OpenClipboard(null)) {
> auto cstr = cast(char*)GetClipboardData( 1 );
> if (cstr)
> writeln(to!string(cast(char*)**cstr[0..strlen(cstr)]));
>
> SetClipboardData( 1, cast(char*)toStringz( "data set" ) );
> }
> }
> [/code]
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20110912/f9a69720/attachment.html>
More information about the Digitalmars-d-learn
mailing list