How can send message to an notepad ? [modified]
-
I open an notepad application :
void CTestMessageView::OnHelpStartapplication()
{
// TODO: Add your command handler code hereShellExecute(m\_hWnd,"open","notepad.exe",NULL,NULL,SW\_SHOWNORMAL);
}
and I want to send some message to notepad :
void CTestMessageView::OnHelpSendmessage()
{
// TODO: Add your command handler code hereCString sTemp = "Test message\\n"; HWND hWnd = ::FindWindow("Notepad",NULL); if(hWnd) {
// ::PostMessage(hWnd,WM_CLOSE,0,0);
::PostMessage(hWnd,WM_CHAR,(WPARAM)'1',0);
::PostMessage(hWnd,WM_KEYDOWN,'1',0);
::PostMessage(hWnd,WM_SETTEXT,0,(LPARAM)(LPCTSTR)sTemp);
::PostMessage(hWnd,EM_REPLACESEL,0,(LPARAM)(LPCTSTR)sTemp);
}
}but only first message WM_CLOSE ( comment one ) is receipt by notepad , other , not . I think that other message then WM_CLOSE is addressed for view of notepad , not the main frame window of the notepad . My question is , how can I send message to the view , not the main frame window of notepad ?
modified on Saturday, January 1, 2011 9:13 AM
-
I open an notepad application :
void CTestMessageView::OnHelpStartapplication()
{
// TODO: Add your command handler code hereShellExecute(m\_hWnd,"open","notepad.exe",NULL,NULL,SW\_SHOWNORMAL);
}
and I want to send some message to notepad :
void CTestMessageView::OnHelpSendmessage()
{
// TODO: Add your command handler code hereCString sTemp = "Test message\\n"; HWND hWnd = ::FindWindow("Notepad",NULL); if(hWnd) {
// ::PostMessage(hWnd,WM_CLOSE,0,0);
::PostMessage(hWnd,WM_CHAR,(WPARAM)'1',0);
::PostMessage(hWnd,WM_KEYDOWN,'1',0);
::PostMessage(hWnd,WM_SETTEXT,0,(LPARAM)(LPCTSTR)sTemp);
::PostMessage(hWnd,EM_REPLACESEL,0,(LPARAM)(LPCTSTR)sTemp);
}
}but only first message WM_CLOSE ( comment one ) is receipt by notepad , other , not . I think that other message then WM_CLOSE is addressed for view of notepad , not the main frame window of the notepad . My question is , how can I send message to the view , not the main frame window of notepad ?
modified on Saturday, January 1, 2011 9:13 AM
Do an EnumChildWindows[^] on your hWnd and locate the edit control Regards Espen Harlinn
-
Do an EnumChildWindows[^] on your hWnd and locate the edit control Regards Espen Harlinn
Thanks , can you give me an little sample code of what I get of the view child window ?
modified on Saturday, January 1, 2011 11:00 AM
-
I open an notepad application :
void CTestMessageView::OnHelpStartapplication()
{
// TODO: Add your command handler code hereShellExecute(m\_hWnd,"open","notepad.exe",NULL,NULL,SW\_SHOWNORMAL);
}
and I want to send some message to notepad :
void CTestMessageView::OnHelpSendmessage()
{
// TODO: Add your command handler code hereCString sTemp = "Test message\\n"; HWND hWnd = ::FindWindow("Notepad",NULL); if(hWnd) {
// ::PostMessage(hWnd,WM_CLOSE,0,0);
::PostMessage(hWnd,WM_CHAR,(WPARAM)'1',0);
::PostMessage(hWnd,WM_KEYDOWN,'1',0);
::PostMessage(hWnd,WM_SETTEXT,0,(LPARAM)(LPCTSTR)sTemp);
::PostMessage(hWnd,EM_REPLACESEL,0,(LPARAM)(LPCTSTR)sTemp);
}
}but only first message WM_CLOSE ( comment one ) is receipt by notepad , other , not . I think that other message then WM_CLOSE is addressed for view of notepad , not the main frame window of the notepad . My question is , how can I send message to the view , not the main frame window of notepad ?
modified on Saturday, January 1, 2011 9:13 AM
What exactly are you trying to do here? Opening notepad and then sending it a
WM_CLOSE
does not make sense. Notepad also takes a command line parameter if you want to open a file in it. For eample -notepad.exe c:\windows\win.ini
«_Superman_» _I love work. It gives me something to do between weekends.
-
What exactly are you trying to do here? Opening notepad and then sending it a
WM_CLOSE
does not make sense. Notepad also takes a command line parameter if you want to open a file in it. For eample -notepad.exe c:\windows\win.ini
«_Superman_» _I love work. It gives me something to do between weekends.
-
I open an notepad application :
void CTestMessageView::OnHelpStartapplication()
{
// TODO: Add your command handler code hereShellExecute(m\_hWnd,"open","notepad.exe",NULL,NULL,SW\_SHOWNORMAL);
}
and I want to send some message to notepad :
void CTestMessageView::OnHelpSendmessage()
{
// TODO: Add your command handler code hereCString sTemp = "Test message\\n"; HWND hWnd = ::FindWindow("Notepad",NULL); if(hWnd) {
// ::PostMessage(hWnd,WM_CLOSE,0,0);
::PostMessage(hWnd,WM_CHAR,(WPARAM)'1',0);
::PostMessage(hWnd,WM_KEYDOWN,'1',0);
::PostMessage(hWnd,WM_SETTEXT,0,(LPARAM)(LPCTSTR)sTemp);
::PostMessage(hWnd,EM_REPLACESEL,0,(LPARAM)(LPCTSTR)sTemp);
}
}but only first message WM_CLOSE ( comment one ) is receipt by notepad , other , not . I think that other message then WM_CLOSE is addressed for view of notepad , not the main frame window of the notepad . My question is , how can I send message to the view , not the main frame window of notepad ?
modified on Saturday, January 1, 2011 9:13 AM
you can't just pass pointers from one process to another process; they must be meaningful and accessible for the receiver, and in general buffers at the sender are neither to the receiver. It would take some calls to VirtualAllocEx, WriteProcessMemory, and the like to achieve such things. But then, why would you? if you want to open Notepad on an empty document and then "type" some, why not simply create a text file first, then open it with Notepad? You wouldn't need any Win32 API function to do that. :)
Luc Pattyn [Forum Guidelines] [My Articles] [My CP bug tracking] Nil Volentibus Arduum
Season's Greetings to all CPians.