Jump to content

  • Log In with Google      Sign In   
  • Create Account

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


Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
7 replies to this topic

#1   Members   

182
Like
Likes
Like

Posted 21 January 2003 - 09:30 PM

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!

#2   Members   

810
Like
Likes
Like

Posted 21 January 2003 - 10:01 PM

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]

#3   Members   

712
Like
Likes
Like

Posted 21 January 2003 - 10:21 PM

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.

#4 Anonymous Poster_Anonymous Poster_*   Guests   

Likes

Posted 22 January 2003 - 01:41 AM

BeerHunter, no, ctl-alt-del does not generate a WM_QUIT, afaik and iirc. but it''s been a while since i''ve done any testing on all Windows platforms, so maybe some are different. i think the application''s process is forced closed instead by killing the main thread. i''m pretty sure this is the case because most of my apps write their settings after exiting the msg loop and this will not occur if the app is killed. i also just tested this on my XP box and the app receives no WM_QUIT when killed via Task Manager.

#5   Members   

829
Like
Likes
Like

Posted 22 January 2003 - 06:31 AM

BeerHunter, are you saying that an app that doesn''t supoport the WM_QUIT message can''t be CADed? I doubt it...



#6   Members   

197
Like
Likes
Like

Posted 22 January 2003 - 07:56 AM

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!"

#7 Anonymous Poster_Anonymous Poster_*   Guests   

Likes

Posted 22 January 2003 - 09:18 AM

Tac-Tics, what OS version? the VC++ IDE definitely doesn''t work that way for me under XP. that''s why when i start it back up after a kill or system crash it no longer loads up my current project. i''ve also "spy++"''d the msg stream going to killed apps and they never receive any msgs after the kill request.

also, it''s not that hard to use a shell hook and capture the CAD request that way. maybe that''s what VC++ is doing. (just some more useless Win32 API trivia.)

#8   Members   

712
Like
Likes
Like

Posted 22 January 2003 - 10:29 AM

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.




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.