digitalmars.D.learn - copy and paste in program
- Joel Christensen (5/5) Sep 11 2011 Hi,
- Jimmy Cao (4/9) Sep 11 2011 Well, it doesn't matter what you've used in the past :-)
- Joel Christensen (7/18) Sep 11 2011 Thanks for the reply Jimmy.
- Vladimir Panteleev (8/10) Sep 11 2011 Search engines often return Windows CE results for API searches.
- Joel Christensen (2/9) Sep 11 2011
- Jimmy Cao (15/31) Sep 11 2011 Here's an example I've quickly put together for you:
- Joel Christensen (22/22) Sep 11 2011 Thanks Jimmy. Your example worked. Or though I haven't managed to get
- Joel Christensen (3/25) Sep 12 2011 I mean, I can't copy text from my program to the clipboard.
- Jimmy Cao (31/53) Sep 12 2011 The other way is a bit more complicated.
- Joel Christensen (34/35) Sep 12 2011 extern(Windows) {
Hi, I've got a text program I'm working on. It has game like print. But I want to be able to copy to the clip board and paste from it in my program etc. I'm using Windows 7. I have used a bit of Ubuntu in the past. - Joelcnz
Sep 11 2011
Well, it doesn't matter what you've used in the past :-) Take a look: http://msdn.microsoft.com/en-us/library/ms907128.aspx On Sun, Sep 11, 2011 at 5:29 PM, Joel Christensen <joelcnz gmail.com> wrote:Hi, I've got a text program I'm working on. It has game like print. But I want to be able to copy to the clip board and paste from it in my program etc. I'm using Windows 7. I have used a bit of Ubuntu in the past. - Joelcnz
Sep 11 2011
Thanks for the reply Jimmy. I was thinking more like SDL (has SDL_GetClipboardText, SDL_SetClipboardText, http://wiki.libsdl.org/moin.cgi/CategoryClipboard). I'm not sure I would be able to get Windows CE Clipboard stuff working for me. - Joelcnz On 12-Sep-11 1:23 PM, Jimmy Cao wrote:Well, it doesn't matter what you've used in the past :-) Take a look: http://msdn.microsoft.com/en-us/library/ms907128.aspx On Sun, Sep 11, 2011 at 5:29 PM, Joel Christensen <joelcnz gmail.com <mailto:joelcnz gmail.com>> wrote: Hi, I've got a text program I'm working on. It has game like print. But I want to be able to copy to the clip board and paste from it in my program etc. I'm using Windows 7. I have used a bit of Ubuntu in the past. - Joelcnz
Sep 11 2011
On Mon, 12 Sep 2011 04:39:52 +0300, Joel Christensen <joelcnz gmail.com> wrote:I'm not sure I would be able to get Windows CE Clipboard stuff working for me.Search engines often return Windows CE results for API searches. Here's the clipboard developer documentation for full Windows versions: http://msdn.microsoft.com/en-us/library/ms648709(v=VS.85).aspx -- Best regards, Vladimir mailto:vladimir thecybershadow.net
Sep 11 2011
So how would I got about doing it in D? On 12-Sep-11 1:52 PM, Vladimir Panteleev wrote:On Mon, 12 Sep 2011 04:39:52 +0300, Joel Christensen <joelcnz gmail.com> wrote:I'm not sure I would be able to get Windows CE Clipboard stuff working for me.Search engines often return Windows CE results for API searches. Here's the clipboard developer documentation for full Windows versions: http://msdn.microsoft.com/en-us/library/ms648709(v=VS.85).aspx
Sep 11 2011
Here's an example I've quickly put together for you: import std.stdio; import core.stdc.string; extern(Windows) { void* GetClipboardData(uint); bool OpenClipboard(void*); } void main() { if (OpenClipboard(null)) { auto cstr = cast(char*)GetClipboardData(1); if (cstr) writeln(std.conv.to!string(cast(char*)cstr[0..strlen(cstr)])); } } On Sun, Sep 11, 2011 at 9:22 PM, Joel Christensen <joelcnz gmail.com> wrote:So how would I got about doing it in D? On 12-Sep-11 1:52 PM, Vladimir Panteleev wrote:On Mon, 12 Sep 2011 04:39:52 +0300, Joel Christensen <joelcnz gmail.com> wrote: I'm not sure I would be able to get Windows CE Clipboard stuff workingfor me.Search engines often return Windows CE results for API searches. Here's the clipboard developer documentation for full Windows versions: http://msdn.microsoft.com/en-**us/library/ms648709(v=VS.85).**aspx<http://msdn.microsoft.com/en-us/library/ms648709(v=VS.85).aspx>
Sep 11 2011
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]
Sep 11 2011
I mean, I can't copy text from my program to the clipboard. - Joelcnz On 12-Sep-11 3:50 PM, Joel Christensen 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]
Sep 12 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 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]
Sep 12 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; } <<
Sep 12 2011