insert text into notepad
-
i am trying to insert text into notepad.
CWnd *myWnd = FindWindow(_T("Notepad"), _T("Untitled - Notepad"));
if(myWnd)
{
::PostMessage(myWnd->GetSafeHwnd(),WM_CHAR,(BYTE)'a',0x000e0001);
//::PostMessage(myWnd->GetSafeHwnd(),WM_DESTROY,0,0);
}if i enable the second line, notepad is quitting. how to insert a character? it is not working.
:rose:
-
i am trying to insert text into notepad.
CWnd *myWnd = FindWindow(_T("Notepad"), _T("Untitled - Notepad"));
if(myWnd)
{
::PostMessage(myWnd->GetSafeHwnd(),WM_CHAR,(BYTE)'a',0x000e0001);
//::PostMessage(myWnd->GetSafeHwnd(),WM_DESTROY,0,0);
}if i enable the second line, notepad is quitting. how to insert a character? it is not working.
:rose:
http://dictionary.reference.com/browse/destroy[^] Destroy:
- to reduce (an object) to useless fragments, a useless form, or remains, as by rending, burning, or dissolving; injure beyond repair or renewal; demolish; ruin; annihilate.
You're getting the main window for notepad.exe - so it shouldn't come as a great shock that if you send a DESTROY! message, it closes. What did you expect? Even if you actually had the text area for notepad, why on earth would you think WM_DESTROY would help you put a character there? I hope I'm missing out on something in your question that you didn't write down. Your idea of sending a WM_CHAR isn't bad - but you're sending it to the main window for the application. If I use Spy++ on notepad, there are two child windows - a big edit one, and a status bar window. You could get the child window, and try sending the WM_CHAR to that. But that is implementation dependent. For all I know, notepad.exe under Vista is built completely differently. Maybe it uses a richedit window, rather than an edit one? Or Notepad under windows 2000 didn't have subwindows, it just worked as you expected. I would have a look at WM_PASTE message. It's likely the notepad's parent window would pass it on to the child edit window to handle, and that would paste the contents of the clipboard into notepad. It is harder to set up some text on the clipboard - but there are samples on codeproject - and it would allow you to do more than one letter at a time. I hope that helps, Iain.
Iain Clarke appearing in spite of being begged not to by CPallini.
-
i am trying to insert text into notepad.
CWnd *myWnd = FindWindow(_T("Notepad"), _T("Untitled - Notepad"));
if(myWnd)
{
::PostMessage(myWnd->GetSafeHwnd(),WM_CHAR,(BYTE)'a',0x000e0001);
//::PostMessage(myWnd->GetSafeHwnd(),WM_DESTROY,0,0);
}if i enable the second line, notepad is quitting. how to insert a character? it is not working.
:rose:
-
http://dictionary.reference.com/browse/destroy[^] Destroy:
- to reduce (an object) to useless fragments, a useless form, or remains, as by rending, burning, or dissolving; injure beyond repair or renewal; demolish; ruin; annihilate.
You're getting the main window for notepad.exe - so it shouldn't come as a great shock that if you send a DESTROY! message, it closes. What did you expect? Even if you actually had the text area for notepad, why on earth would you think WM_DESTROY would help you put a character there? I hope I'm missing out on something in your question that you didn't write down. Your idea of sending a WM_CHAR isn't bad - but you're sending it to the main window for the application. If I use Spy++ on notepad, there are two child windows - a big edit one, and a status bar window. You could get the child window, and try sending the WM_CHAR to that. But that is implementation dependent. For all I know, notepad.exe under Vista is built completely differently. Maybe it uses a richedit window, rather than an edit one? Or Notepad under windows 2000 didn't have subwindows, it just worked as you expected. I would have a look at WM_PASTE message. It's likely the notepad's parent window would pass it on to the child edit window to handle, and that would paste the contents of the clipboard into notepad. It is harder to set up some text on the clipboard - but there are samples on codeproject - and it would allow you to do more than one letter at a time. I hope that helps, Iain.
Iain Clarke appearing in spite of being begged not to by CPallini.
Iain Clarke wrote:
Iain Clarke appearing in spite of being begged not to by CPallini.
:-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
[my articles] -
baerten wrote:
WM_KEY_DOWN
Uhmmm, are you sure the notepad is aware of such a message? :-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
[my articles] -
Iain Clarke wrote:
Iain Clarke appearing in spite of being begged not to by CPallini.
:-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
[my articles]I was wondering when you'd spot that... I'm going to have to change it now! Iain.
Iain Clarke appearing in spite of being begged not to by CPallini.
-
http://dictionary.reference.com/browse/destroy[^] Destroy:
- to reduce (an object) to useless fragments, a useless form, or remains, as by rending, burning, or dissolving; injure beyond repair or renewal; demolish; ruin; annihilate.
You're getting the main window for notepad.exe - so it shouldn't come as a great shock that if you send a DESTROY! message, it closes. What did you expect? Even if you actually had the text area for notepad, why on earth would you think WM_DESTROY would help you put a character there? I hope I'm missing out on something in your question that you didn't write down. Your idea of sending a WM_CHAR isn't bad - but you're sending it to the main window for the application. If I use Spy++ on notepad, there are two child windows - a big edit one, and a status bar window. You could get the child window, and try sending the WM_CHAR to that. But that is implementation dependent. For all I know, notepad.exe under Vista is built completely differently. Maybe it uses a richedit window, rather than an edit one? Or Notepad under windows 2000 didn't have subwindows, it just worked as you expected. I would have a look at WM_PASTE message. It's likely the notepad's parent window would pass it on to the child edit window to handle, and that would paste the contents of the clipboard into notepad. It is harder to set up some text on the clipboard - but there are samples on codeproject - and it would allow you to do more than one letter at a time. I hope that helps, Iain.
Iain Clarke appearing in spite of being begged not to by CPallini.
Iain Clarke wrote:
I hope I'm missing out on something in your question that you didn't write down.
i mean the destroy msg is working and the wm keydown msg was not working. destroy is commented. paste is not working. any other alternative? thanks for the reply.
:rose:
-
Iain Clarke wrote:
Iain Clarke appearing in spite of being begged not to by CPallini.
:-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
[my articles]can u please tell me how to get the handle of notepad's edit window/
:rose:
-
can u please tell me how to get the handle of notepad's edit window/
:rose:
-
i am trying to insert text into notepad.
CWnd *myWnd = FindWindow(_T("Notepad"), _T("Untitled - Notepad"));
if(myWnd)
{
::PostMessage(myWnd->GetSafeHwnd(),WM_CHAR,(BYTE)'a',0x000e0001);
//::PostMessage(myWnd->GetSafeHwnd(),WM_DESTROY,0,0);
}if i enable the second line, notepad is quitting. how to insert a character? it is not working.
:rose:
a plain dump solution, activate the notepad application and generate keyboard event (keybd_event() API)
modified on Thursday, February 07, 2008 6:54:00 AM
-
Iain Clarke wrote:
I hope I'm missing out on something in your question that you didn't write down.
i mean the destroy msg is working and the wm keydown msg was not working. destroy is commented. paste is not working. any other alternative? thanks for the reply.
:rose:
Aljechin wrote:
i mean the destroy msg is working
WM_DESTROY is a notification message from the system. Sending it to a window that actually isn't being destroyed isn't going to do anything except possibly leave the target application in an unstable state. What are you expecting sending that message to do? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java: