Skip to main content
GameDev.net gamedev.net
🔒 Locked

Difference between WM_CLOSE, WM_QUIT and WM_DESTROY and what to do with them

Started by Subotron Jan 22, 2003 at 3:30 AM 6 replies 35.4k views
Original Post
Subotron
Subotron
When I see example WindowProc functions most of the time they handle different messages including these: WM_QUIT WM_DESTROY WM_CLOSE I was wondering, what are the differences between these 3, when do they occur and what should I do when they occur? To give an example, say if WM_QUIT means you clicked on the cross that closes an application, you should probably destroy everything and free the allocated memory. But if WM_DESTROY would mean everything is destroyed, you would only do PostQuitMessage(0) right? That brings me to another question, what are the last commands given to close an application? I always see PostQuitMessage(0) but what does it really do, when should I use it and are there other things I need to do? (like if I do this in the end of the WinApi function, should I still return 0 afterwards to lose the function?) Thanks in advance for the feedback!
quasar3d
quasar3d
WM_CLOSE means the user clicked the close button on the title bar (opr Alt+F4), but that doesn't close the window. Most times you call DestroyWindow(hWnd); to destroy the window, but if you don't do anything, the window won't be closed.
afaik the WM_DESTROY message is sent when the window is destroyed, and WM_QUIT when the application is about to quit. after this message, the program leaves the message loop.

My Site

[edited by - Quasar3D on January 22, 2003 5:01:49 AM]
Beer Hunter
Beer Hunter
I''ll elaborate a bit...

WM_CLOSE indicates a request to close a window, such as by clicking on the x. This is a good time to ask the user if they want to save their work, etc. Calling DefWindowProc will destroy the window, while returning zero will leave the window intact.
WM_DESTROY indicates that a window is being destroyed. If it''s the main window that''s being destroyed, this is a popular place to call PostQuitMessage(0) (which just adds a WM_QUIT message to the message queue).
WM_QUIT indicates that the application should quit. If I recall correctly, it can be generated by ctrl-alt-deleting the application (can anyone confirm this?), but most of the time, you''ll receive it because you sent it to yourself in response to WM_DESTROY. Receiving a WM_QUIT is the termination condition in the message pump.
Enselic
Enselic
BeerHunter, are you saying that an app that doesn''t supoport the WM_QUIT message can''t be CADed? I doubt it...

Tac-Tics
Tac-Tics
I''m not all that fluent in Win32 API (I just know enough to get OpenGL to fullscreen render mode), but I know a few times when VC++ errored on me, I''ve seen something peculiar. Every once in a while, VC++ will freeze during compiling and linking (thnx M$ =-) and if I click on the ''x'' to close it, it gives me an error message "cannot exit, build in progress" (also, trying to cancel the build from the build menu didn''t do anything , so don''t say I blame M$ without cause!) However, when I give VC++ the three-fingered salute, it pauses for a while like it normally does, and then pops up a window saying the same thing as when I tried to close the app normally: "cannot exit, build in progress"... and then a second later, the program terminates despite its warning =-|

This is reason to believe that CAD''ing an app does allow for some kind of interface with the program before it pulls the plug on it.

"You TK''ed my chicken!"
Beer Hunter
Beer Hunter
quote:
Original post by Enselic
BeerHunter, are you saying that an app that doesn''t supoport the WM_QUIT message can''t be CADed?
Uh, no. I never said that. Where did that come from?

...

I''ve done a quick test, and, in fact, it didn''t send a WM_QUIT to the application, but a WM_CLOSE to the main window. If the application ignores the message, it can be forcibly terminated, as we all know, but before that, it sends messages.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.