-
October 22nd, 2006, 03:43 PM
#1
SendMessage/PostMessage
Hi
This code closes the window with PostMessage.
But if i write SendMesssage instead of Post message it doesn't close the window.I don't understand why it is so.
Code:
HWND h=::FindWindow(NULL,L"Tutorial: A Simple Window - Mozilla Firefox");
PostMessage(h,WM_QUIT,0,0);
What are the differences so postmessage can close the window but postmessage can not.
Thanks
-
October 22nd, 2006, 05:11 PM
#2
Re: SendMessage/PostMessage
Never post/send a WM_QUIT. Always post/send a WM_CLOSE message instead.
The reason it doesn't work is probably answered here.. which is , WM_QUIT message has to be processed by GetMessage, however, SendMessage bypasses this.
Anyways, refrain from send/posting WM_QUIT. WM_CLOSE is the recommended approach to close a window. If not, you might bypass other stuff the application would typically do when closing a window.
-
October 23rd, 2006, 02:29 AM
#3
Re: SendMessage/PostMessage
What are the differences so postmessage can close the window but postmessage can not
Originally Posted by MSDN
The SendMessage function sends the specified message to a window or windows. It calls the window procedure for the specified window and does not return until the window procedure has processed the message.
Originally Posted by MSDN
The PostMessage function places (posts) a message in the message queue associated with the thread that created the specified window and returns without waiting for the thread to process the message.
Now, you should undestand better what Kiran said (as specified in MSDN)
Originally Posted by MSDN
The WM_QUIT message is not associated with a window and therefore will never be received through a window's window procedure. It is retrieved only by the GetMessage or PeekMessage functions.
-
October 23rd, 2006, 03:24 AM
#4
Re: SendMessage/PostMessage
ok.
Thanks friends for help...
-
October 23rd, 2006, 04:29 AM
#5
Re: SendMessage/PostMessage
Hi All
I want to close another programm from my programm:
Code:
SendMessage(hMw,WM_CLOSE,0,0);
And it works ...
But if another programm is Minimized, it's not closed. Only after the second start of my program it's closed.
Why...?
I don't understand.
-
October 23rd, 2006, 10:49 AM
#6
Re: SendMessage/PostMessage
I don't undestand this either:
after the second start of my program it's closed.
-
October 23rd, 2006, 05:31 PM
#7
Re: SendMessage/PostMessage
I think he means... if the program he wants to close is minimized, running his program once will not close it. But, running his program a second time will close it.
-
October 23rd, 2006, 11:47 PM
#8
Re: SendMessage/PostMessage
Yes I meant it.
I badly know English. Sorry...
-
October 24th, 2006, 12:01 AM
#9
Re: SendMessage/PostMessage
Why SendMessage ? Why not PostMessage ? ( SendMessage will tie up the sender if , for some reason, the target process is hung ). Instead, use PostMessage, or SendMessageTimeout.
Also, how are you obtaining the hWnd ? Are you sure you are getting the right hWnd ?
-
October 24th, 2006, 01:30 AM
#10
Re: SendMessage/PostMessage
PostMessage does not work too.
SendMessageTimeout did't try. I do not know parameter - fuFlags.
Yes Window handle is right. First time it's working.
-
October 24th, 2006, 04:03 AM
#11
Re: SendMessage/PostMessage
SendMessageTimeout does not work too.
Maybe i send wrong parameters !?
Code:
hMw = FindWindowEx (NULL,NULL,"WindowsForms10.Window.8.app17",NULL);
SendMessageTimeout(hMw,WM_CLOSE,0,0,0,200,0);
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
|