|
-
April 19th, 1999, 03:58 PM
#1
Clipboard program
So I got a grip over the weekend and eliminated most of my problems, however, one remains. When I try to use the function GetClipboardData, it returns a handle to clipboard object and I am trying to convert that into an char array, but it just puts garbage in the array.
Here is the function - any suggestions would be appreciated.
void From_Clipboard(HWND TextEdit, HWND hwnd2){
char destination[20];
if(OpenClipboard(hwnd2)){
static HGLOBAL clipbuffer;
static char * buffer;
clipbuffer = GlobalAlloc(GMEM_MOVEABLE, strlen(destination)+1);
buffer = (char*)GlobalLock(clipbuffer);
clipbuffer = GetClipboardData(CF_TEXT);
lstrcpy(destination, LPCSTR(buffer));
GlobalUnlock(clipbuffer);
SetWindowText(TextEdit, destination);
}
else{
MessageBox(NULL, "Unable to read from clipboard!", "Error",
MB_OK | MB_ICONINFORMATION);
}
CloseClipboard();
}
-
April 19th, 1999, 06:00 PM
#2
Re: Clipboard program
This has not been tested:
if(OpenClipboard(hwnd2)){
static HGLOBAL clipbuffer;
static char * buffer;
// Get handle to clipboard data
clipbuffer = GetClipboardData(CF_TEXT);
// Now lock the handle and return pointer to lock
buffer = (char*)GlobalLock(clipbuffer);
// No need to allocate again, buffer points to the clipboard data.
//Why duplicate what the clipboard is supposed to do, namely store the string?
// What if text > 20 characters???
lstrcpy(destination, LPCSTR(buffer));
GlobalUnlock(clipbuffer);
// You forgot to close clipboard
CloseClipboard();
SetWindowText(TextEdit, destination);
}
Regards,
Paul McKenzie
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|