Jump to content
  • Advertisement
Sign in to follow this  
AtsusaKai

How to cancel WM_CLOSE message?

This topic is 3709 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

Hello, I'm a beginner on Win32 programming and I'd like to ask how to cancel the message WM_CLOSE when it's sent to the MessageProc. Thank you in advance.

Share this post


Link to post
Share on other sites
Advertisement
From the docs:
Quote:

If an application processes this message, it should return zero.

In other words, return zero in your message handling callback.

Share this post


Link to post
Share on other sites
Quote:
Original post by eq
From the docs:
Quote:

If an application processes this message, it should return zero.

In other words, return zero in your message handling callback.


Hold a sec, I'm a little confused. Okay, here's the situation.. Say I have created a window, then I click the close button of the window, true enough, the window will send a message which is I think WM_CLOSE..and will pass through a MsgProc... now, what should I do or write to cancel the closing.

Did you mean that I should return zero so it will be cancelled?

[source language=cpp]

LRESULT MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
if ( uMsg == WM_CLOSE )
{
if ( cancelClose )
{
// code to cancel.. how?
}
}

return 0;
}




Thanks for the time.

Share this post


Link to post
Share on other sites
Again, read the docs:

Quote:

An application can prompt the user for confirmation, prior to destroying a window, by processing the WM_CLOSE message and calling the DestroyWindow function only if the user confirms the choice.

By default, the DefWindowProc function calls the DestroyWindow function to destroy the window.

If you don't return 0; in your WM_CLOSE handler and call DefWindowProc instead, it will call DestroyWindow(). So, by returning 0 in your handler, you can bypass the default handler and choose whether or not to destroy the window yourself:


case WM_CLOSE:
// ...
if (!cancelClose)
{
DestroyWindow(hWnd)
}
return 0;




Edit: I noticed that you don't return DefWindowProc. This is how a Message Proc typically looks:


LRESULT CALLBACK MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
switch (uMsg)
{
case WM_CREATE:
break;
// etc...
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

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