Thread: Doubt on WM_CLOSE

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    22

    Doubt on WM_CLOSE

    Hi, a while ago I started learning Windows Programming from a tutorial on the Microsoft website, and I learnt that you can call a message box from WM_CLOSE asking whether you want to close it or not.

    I also found out that you can ignore it based on which button on the message box the user clicks and that returning 0 will make the OS ignore the message and not close the window.

    So, my question is this: If I was to directly return 0 without checking for a response from Message box, would the program run forever?

    For obvious reasons, I am not trying this out. Any help would be appreciated. Thank you!

    PS: This is the link to the tutrial: Closing the Window (Windows)
    It's a miracle that curiosity survives formal education - Albert Einstein

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> For obvious reasons, I am not trying this out.
    You can always kill the process using task manager. I prefer process explorer: Process Explorer

    gg

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    22
    Hm.
    Never struck me. Thanks!
    It's a miracle that curiosity survives formal education - Albert Einstein

  4. #4
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Quote Originally Posted by Dakshin View Post
    I also found out that you can ignore it based on which button on the message box the user clicks and that returning 0 will make the OS ignore the message and not close the window.

    So, my question is this: If I was to directly return 0 without checking for a response from Message box, would the program run forever?
    Returning 0 from your WM_CLOSE handler has nothing to do with whether or not the program stops.

    What causes the program to stop is calling DestroyWindow, which sends a WM_DESTROY message that you respond to with PostQuitMessage, which sends a WM_QUIT message that GetMessage responds to by returning 0 to the while loop in WinMain, causing that loop to terminate, causing the program to terminate.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Handling WM_CLOSE and WM_DESTROY
    By megafiddle in forum Windows Programming
    Replies: 9
    Last Post: 10-01-2011, 12:59 AM
  2. Wm_close Wm_destroy Wm_quit
    By h_howee in forum Windows Programming
    Replies: 2
    Last Post: 09-24-2006, 02:11 PM
  3. Wm_close
    By franks in forum Windows Programming
    Replies: 1
    Last Post: 03-24-2003, 04:30 PM
  4. Wm_close & Wm_destroy
    By Kelvin in forum C++ Programming
    Replies: 1
    Last Post: 07-06-2002, 03:12 AM
  5. Disabling WM_Close
    By Unregistered in forum Windows Programming
    Replies: 5
    Last Post: 04-26-2002, 06:30 AM