473,396 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

PostQuitMessage

Apparently, PostQuitMessage 'posts a quit message to the calling thread's message queue'. How does it know which window this relates to? What if the calling thread's message pump is sending messages to more than one window, or what if there is more than one window in the calling thread but each with their own message pump

How would the function know which window to send the quit message to in both of the above cases?
Nov 17 '05 #1
2 3428
Bonj,

the PostQuitMessage does not relate to a window - it is aimed at the
GetMessage API call and the thread message queue that it is servicing.

See the remarks section in the following link

http://msdn.microsoft.com/library/de...es/WM_QUIT.asp

Think of the WM_QUIT in the same terms as you would the WM_PAINT and
WM_TIMER messages - in fact it is better if you think of these as flags or
states, and not a actual messages that are fetched from the queue and
processed in sequence as are other "real" messages.

Get a copy of Richter's book Advanced Windows for a good coverage of this
topic.

regards
roy fine
"Bonj" <an*******@discussions.microsoft.com> wrote in message
news:C6**********************************@microsof t.com...
Apparently, PostQuitMessage 'posts a quit message to the calling thread's message queue'. How does it know which window this relates to? What if the
calling thread's message pump is sending messages to more than one window,
or what if there is more than one window in the calling thread but each with
their own message pump?
How would the function know which window to send the quit message to in

both of the above cases?
Nov 17 '05 #2
"Bonj" <an*******@discussions.microsoft.com> wrote in message
news:C6**********************************@microsof t.com
Apparently, PostQuitMessage 'posts a quit message to the calling
thread's message queue'. How does it know which window this relates
to? What if the calling thread's message pump is sending messages to
more than one window, or what if there is more than one window in the
calling thread but each with their own message pump?

How would the function know which window to send the quit message to
in both of the above cases?


If you look at almost any other message in these groups, you will see that
it is posted to just a single newsgroup. You, by contrast, seem to post your
every message to at least three groups. Such cross-posting is considered a
breach of newsgroup etiquette since it undermines the principle of having
separate newsgroups for separate topics.

The answer to your question is that the quit message does not relate to a
window at all. It relates to a thread. To quote from the WM_QUIT
documentation:

"The WM_QUIT message is not associated with a window and therefore will
never be received through a window's window procedure."

Instead, WM_QUIT causes GetMessage to return 0, which causes a message loop
of the following (or similar) form

while(GetMessage(...))

to terminate. In the case of PeekMessage, the message is retrieved in the
normal way and the application code should check whether the message is
WM_QUIT and respond appropriately.

Typically a thread has a single message loop regardless of how many windows
it has. The same message loop dispatches messages to all of its windows,
based on the HWND parameter of the message. In the case of WM_QUIT, the
message is never dispatched to a window, the application (or at least the
message pump) simply terminates. The only thing to make sure of is that only
one window calls PostQuitMessage, and it must be the last one destroyed.
Otherwise, the message pump will cease to function prematurely, before all
windows have been properly closed down. This means that only top level
windows should call PostQuitMessage. If there is more than one of them, then
a count should be kept and PostQuitMessage should only be called when there
is only one left.

If it so happens that a thread has more than one message loop (perhaps
because some function doing a lot of processing calls PeekMessage), then
whichever message loop calls GetMessage/PeekMessage first once WM_QUIT
reaches the head of the message queue will be the one to retrieve the
WM_QUIT message. That is how it works with any message. It will then deal
with it in accordance with the code that has been written for that message
loop.
--
John Carson
1. To reply to email address, remove donald
2. Don't reply to email address (post here instead)

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Lee | last post by:
Hi, I'm developing a socket program to connect to Informix database through the ODBC. In here i called my socket program as "tap" . My tap will listen for data from unix through port 1070. After...
3
by: Glen | last post by:
Hello. Can some one explain me why below example work LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; RECT rect;
4
by: Bonj | last post by:
Hi I am having an issue with a window I am creating - in its wndproc, if I call PostMessage(hWnd, WM_QUIT, 0, 0) in response to WM_DESTROY, then GetMessage returns a non-zero value and the loop...
17
by: Bonj | last post by:
Is PostQuitMessage(?) different to PostMessage(hWnd, WM_QUIT, ... ) ? I've got a window in a DLL (the same one experiencing the issue below, "return value of WM_QUIT") in which PostMessage(hWnd,...
11
by: Tom Shelton | last post by:
Last night I was feeling a little bored and I happend to come across a bit of code I wrote way back in the VB5 days. This code, was a simple little windows application - but was created strictly...
4
by: Dragon | last post by:
Hello, I wonder if there's a way to use OpenGL directly from VB .NET, without any C++ code, or CsGL library. I've tried to convert NeHe's first tutorial...
3
by: Rsrany | last post by:
I've been working on a few gtk applications and need to tie a hot key catcher into a thread. I am currently finding threaded user32.GetMessageA do not work. I have included two programs: 1) a...
5
by: sverdloff | last post by:
Hey guys, I've just started in a programming company, and meet some difficulties, as I start from scratch..... I have a command line program I've wrote, and want to transfer it to GUI. It...
3
by: Register456 | last post by:
int f1(){ CreateWindow("edit"...) } int STDCALL WinMain(){etc...} why this gives errorr..: CreateWindowA is undefined? its still defined i dont understand why. can anyone point out some...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.