|
-
April 5th, 2009, 11:52 AM
#1
Pasting to any window
I managed to paste text that is currently in the clipboard using this:
CString csText = "Test";
HGLOBAL hglbCopy;
if(OpenClipboard())
{
EmptyClipboard();
TCHAR *wcBuffer = 0;
hglbCopy = GlobalAlloc( GMEM_MOVEABLE, (csText.GetLength() + 1) * sizeof (TCHAR));
wcBuffer = (TCHAR*)GlobalLock(hglbCopy);
_tcscpy(wcBuffer, csText);
GlobalUnlock(hglbCopy);
SetClipboardData(CF_TEXT, hglbCopy);
CloseClipboard();
}
}
// And then:
POINT pt;
GetCursorPos(&pt);
CWnd* editControl;
editControl = WindowFromPoint(pt);
editControl->GetFocus();
editControl->SendMessage(WM_PASTE, 0, 0);
It does work for notepad but it does not work for other apps ( for example - Word and a textbox in a browser window)
I've also tried to programatically click Ctrl+V and cause a paste like this:
editControl->SendMessage(WM_CHAR, 22, 0x56);
But it seems to have the same problem - only works in some places (notepad...)
Any idea how can I make this work for any input control ?
(just like Ctrl+V works for every control)
Last edited by Yovav; April 5th, 2009 at 12:00 PM.
Best Regards - Yovav
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
|