Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

red_sodium

Windows message for closing application

This topic is 5293 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, Does anyone know what the windows message is sent when the "x" in the top right of a windowed application is clicked? For some reason, when I click this, my applicaton still runs, although the window itself is closed.

Share this post


Link to post
Share on other sites
Advertisement
Possibly

WM_QUIT



--
What are you nutz?

I have nothing to say to your unevolved little brain. The more I say gives you more weapons to ask stupid questions.

Share this post


Link to post
Share on other sites
I suspect it''s WM_DESTROY that you want to look at. You indicated that the application still runs although the window is closed. The WM_DESTROY message is sent to the window procedure of the window being destroyed after the window is removed from the screen.

The WM_QUIT message indicates a request to terminate an application and is generated when the application calls the PostQuitMessage function.

The WM_CLOSE message is sent as a signal that a window or an application should terminate.

An application (or window) receives all of these messages through its WindowProc function.

I would try intercepting the WM_DESTORY message and making sure you clean up all your resources so that the application can quit. Or... you might just FORCE the application to quit.

Hope this helps!

Share this post


Link to post
Share on other sites
Also make sure that you don''t have a thread left running somewhere. If your app is multi-threaded, you might have a thread hung somewhere that keeps it going as a process even if the window is destroyed...

Rattlehead

Share this post


Link to post
Share on other sites
Clicking the "X" generates the WM_CLOSE message. The default message handling for WM_CLOSE is to call DestroyWindow(), which posts the WM_DESTROY message.

If you want the app to exit when the "X" is clicked add a message handler for WM_DESTROY and call PostQuitMessage() from within it. This will then generate the WM_QUIT message and cause GetMessage() to return.

[corrected spelling]

[edited by - Solo on March 26, 2004 4:04:29 PM]

Share this post


Link to post
Share on other sites
I''m pretty sure the X in the corner of a window generates a WM_SYSCOMMAND message with a wParam of SC_CLOSE. It''s very possible that, whether or not the WM_SYSCOMMAND was handled, other messages such as WM_CLOSE or WM_DESTROY are also sent.

Share this post


Link to post
Share on other sites
Well, when I close using "x", SC_CLOSE of WM_SYSCOMMAND or WM_CLOSE or WM_DESTROY are not called. As far as I know, I only have one thread running. When I use the ESC key, it closes fine, as ESC is set up in my WindowProc message handling function to PostQuitMessage( 0 ); I set up SC_CLOSE, WM_DESTROY and WM_CLOSE messages to do the same, but they did not when I used the "x".

Anyone have any suggestions?

Here is my main loop:


while( true ) {
Sleep( 20 );
PeekMessage( &msg, hWnd, NULL, NULL, PM_REMOVE );

if( msg.message == WM_QUIT ){
break;
}
else if( msg.message == WM_SYSCOMMAND ) {
switch( msg.wParam ) {
case SC_MINIMIZE:
engineManager->Pause( true );
break;
case SC_MAXIMIZE:
engineManager->Pause( false );
break;
case SC_CLOSE:
engineManager->Log( "Window closed" );
PostQuitMessage( 0 );
break;
}
}
else if( msg.message == WM_CLOSE ) {
engineManager->Log( "Close application" );
PostQuitMessage( 0 );
}
else {
engineManager->MainLoop();

TranslateMessage( &msg );
DispatchMessage( &msg );
}
}

engineManager->Log( "Main loop ended, destroying EngineManager" );
delete engineManager;

UnregisterClass( "2DGAMEPROJ", hInstance );
return( msg.wParam );


[edited by - red_sodium on March 26, 2004 7:50:24 PM]

Share this post


Link to post
Share on other sites
You should put your test into the window procedure. As far as I can remeber there is more than one way a message is sent to a window.

Share this post


Link to post
Share on other sites
I also have a windows procedure, but this is what a lot of tutorials do, so I stuck with it. I don''t think this is the cause of my problem though, neither place produces the messages.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!