April 19, 2024, 01:37:54 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Sending a large string to the clipboard

Started by Andy, October 27, 2017, 12:39:24 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

This is probably something simple.

I have an istring called "text" which is larger then 254 characters - how can I send this to the clipboard?

I've tried istring in this code but I get an error:

handle = GlobalAlloc(@GHND,2000)
lock = GlobalLock(handle)   
#<STRING>lock = text
GlobalUnlock(handle)
OpenClipboard(win.hWnd)
EmptyClipboard()
SetClipboardData(@CFTEXT,handle)
CloseClipboard()


Thanks,
Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy

It's strange because I can get a large string like this:

hMem = GetClipboardData(@CFTEXT)
text = #<string>hMem


All I'm doing then is splitting the text istring up into an array of lines 254 characters each.

Sorting them, and then building up a new text istring to send back to the clipboard.

Help please!
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

fasecero

I made an example based on your code and it's working for me. Maybe you are exceeding the limit of 2000 characters you are using.



$INCLUDE "windowssdk.inc"

DIALOG d1
CREATEDIALOG d1,0,0,300,383,0x80C80080,0,"Caption",&d1_handler

DOMODAL d1

SUB d1_handler
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
/* Initialize any controls here */
OnInit()
CASE @IDCLOSEWINDOW
CLOSEDIALOG d1,@IDOK
ENDSELECT
RETURN
ENDSUB

SUB OnInit()
ISTRING ibuff[10000] = ""

INT j
FOR j = 1 TO 500
ibuff += STR$(j)
NEXT j

CopyStringToClipboard(d1.hwnd, ibuff)
ENDSUB

SUB CopyStringToClipboard(INT hwnd, string text)
HGLOBAL handle =  GlobalAlloc(GHND, LEN(text) + 1)
pointer lock = GlobalLock(handle)
#<STRING>lock = text
GlobalUnlock(handle)
OpenClipboard(hwnd)
EmptyClipboard()
SetClipboardData(CF_TEXT, handle)
CloseClipboard()
ENDSUB


Andy

October 28, 2017, 12:10:00 AM #3 Last Edit: October 28, 2017, 12:14:32 AM by Andy
Fasecero,

I tried your amended code, but it can only see 80 or so across the screen.

I amended it to add a carriage return but I only get 53 lines not 500??

Andy.


Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

fasecero

sorry. I end up copying my first try.


SUB CopyStringToClipboard(INT hwnd, string text)
HGLOBAL handle =  GlobalAlloc(GHND, LEN(text) + 1)
pointer lock = GlobalLock(handle)
memcpy(lock, text, LEN(text) + 1)
GlobalUnlock(handle)
OpenClipboard(hwnd)
EmptyClipboard()
SetClipboardData(CF_TEXT, handle)
CloseClipboard()
GlobalFree(handle) 'note: this line is not present in any example at all but I'm pretty sure that its absence will produce a memory leak :/
ENDSUB

Andy

Fasecero,

Thanks for the update, that works well.

Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.