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.
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!
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
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.
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
Fasecero,
Thanks for the update, that works well.
Andy.