Click here to Skip to main content
15,893,663 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
I have an application which has a button on Click of button am trying to paste the text already available to Notepad. My application gathers the text first and puts it on the clipboard(this is working perfectly fine), I am facing problem with the Paste part. Here is the code, Please let me know where am i going wrong.

C++
CWnd *pCwnd = FindWindow(NULL, _T("Untitled - Notepad"));
    HWND handle = pCwnd->GetSafeHwnd();
    pCwnd->PostMessageA(WM_PASTE,0,0);

I am using Notepad to test it so the name is ("Untitled - Notepad"). Please help me. Thanks in advance.
Posted
Updated 5-Dec-13 21:30pm
v2

1 solution

Read This:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms649028%28v=vs.85%29.aspx

WM_PASTE is sended to an edit control or a combo box.
You are sending the message to the main window.

You have to find the child window

Use FindWindowEx function
 
Share this answer
 
Comments
Mayur S7789 6-Dec-13 23:34pm    
If suppose an application window has two Edit control, then how to get handle of the second Edit control. I am able to get the Handle of first, but wondering how to get the next ?. Also i want to Simulate TAB key press, i.e after Edit control gets the text, then TAB key press should be done so it goes to next edit control. Please help and guide me through it. Thanks in advance.
Optimistic76 8-Dec-13 5:35am    
is the application the target you want to past the text instead of Notepad?
HWND WINAPI FindWindowEx(
_In_opt_ HWND hwndParent,
_In_opt_ HWND hwndChildAfter,
_In_opt_ LPCTSTR lpszClass,
_In_opt_ LPCTSTR lpszWindow );

when you call for the first time FidWindowEx, you will get the handle of the first edit. You should call another time FindWindowEx using the result of the first call as the hwndchildafter parameter

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900