Hmm yeah as the guys suggested, change the window handle parameter in PeekMessage to NULL.
That doesn''t make sense though. According to the documentation it should work both ways; specifying NULL or specifying a window handle. In fact after some testing it quits properly using either way under Windows 2000 but only quits properly using NULL under Windows XP. However if you specify a window handle, under XP it seems to quit if you move the window around (similar to what you said in your first post Syrillix).
Does anyone have any ideas as to what''s going on? The docs are somewhat confusing, in typical Microsoft fashion.
sam
PostQuitMessage() not actually posting a quit message?
I had a similar problem under WinXP where calling PostQuitMessage wouldn''t actually cause the program to close until I moved the window and tried again
Turned out that since the function that called PostQuitMessage was being called through Python it was in a seperate thread''s context.
I''m not 100% sure since this was some time ago, but I believe I was passing my main hWnd into PeekMessage rather than passing NULL. This caused it not to register the WM_QUIT message that was called by the Python thread (or any messages from any threads . All I know for sure is that it works fine now and PeekMessage is passing NULL for the hWnd parameter.
So if there''s a chance that you''re calling PostQuitMessage outside of the main thread (and this can be pretty well hidden), changing the hWnd to NULL would work.
Turned out that since the function that called PostQuitMessage was being called through Python it was in a seperate thread''s context.
I''m not 100% sure since this was some time ago, but I believe I was passing my main hWnd into PeekMessage rather than passing NULL. This caused it not to register the WM_QUIT message that was called by the Python thread (or any messages from any threads . All I know for sure is that it works fine now and PeekMessage is passing NULL for the hWnd parameter.
So if there''s a chance that you''re calling PostQuitMessage outside of the main thread (and this can be pretty well hidden), changing the hWnd to NULL would work.
if it works, it works... i suppose.
but i dont get it. of course, i was under the assumption that windows would keep a message queue for each window handle, so passing NULL instead of the window handle would mean you were requesting messages from the desktop? as was stated above, it doesnt make sense to pass a NULL HWND to PeekMessage().
at any rate, i''d still like to know why this is the case.
but i dont get it. of course, i was under the assumption that windows would keep a message queue for each window handle, so passing NULL instead of the window handle would mean you were requesting messages from the desktop? as was stated above, it doesnt make sense to pass a NULL HWND to PeekMessage().
at any rate, i''d still like to know why this is the case.
WM_QUIT is a message that is not associated with a window, so when you only ask for messages for a certain window you should never get WM_QUIT.
[edited by - extrarius on January 5, 2004 9:34:15 PM]
[edited by - extrarius on January 5, 2004 9:34:15 PM]
Hail to the manual:
Try checking if PeekMessage returns zero instead of checking for WM_QUIT.
quote:
If hWnd is NULL, PeekMessage retrieves messages for any window that belongs to the current thread.
quote:
The WM_QUIT message indicates a request to terminate an application and is generated when the application calls the PostQuitMessage function. It causes the GetMessage function to return zero.
[...]
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.
Try checking if PeekMessage returns zero instead of checking for WM_QUIT.
That makes sense to me.
Syrillix, I want to apologize for my tone of voice. I didn''t realized that you were probably writing your post when I posted mine. Take care.
Syrillix, I want to apologize for my tone of voice. I didn''t realized that you were probably writing your post when I posted mine. Take care.
Extrarius, I guess that makes sense but the documentation is definately still vague, despite the section that Duke posted (it doesn''t really say that explicitely, rather it says something that could mean a couple of things).
Thanks for the help!
sam
Thanks for the help!
sam
This is my normal message loop...
... which ensures _all_ waiting messages are processed before shutdown.
Some Microsoft examples are actually _wrong_ I think, if I remember rightly.
R
[edited by - reaction on January 7, 2004 7:16:24 AM]
MSG msg; bool bQuit = false; do { WaitMessage(); while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); if (msg.message == WM_QUIT) bQuit = true; } if (bQuit) break; } while (1);
... which ensures _all_ waiting messages are processed before shutdown.
Some Microsoft examples are actually _wrong_ I think, if I remember rightly.
R
[edited by - reaction on January 7, 2004 7:16:24 AM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement