+ Reply to Thread
Results 1 to 2 of 2

Thread: What is the difference between WM_CLOSE and WM_DESTROY

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    1

    What is the difference between WM_CLOSE and WM_DESTROY

    I am writing a Windows application using only the WIN32 API
    in my window procedure where all messages are handled i find two different messages in the MSDN documentation
    WM_CLOSE and WM_DESTROY
    i know they are both sent before the window is closed, but what is the difference between them?

  2. #2
    Junior Member
    Join Date
    Jun 2012
    Posts
    3
    WM_CLOSE is sent to the window as a warning after the user clicks the close button or ALT F4 etc... it is to give you the chance to prompt the user asking him/her are you sure you want close, handle any serialization (saving to file), or any code that needs to be run while the window is still on the screen
    while WM_DESTROY is sent after the window has been gone and disappeared from the screen, no user interatcion now, this is where you do your last minute clean up, delete objects you have created, manage any memory leack, write something to a log file....etc.
    so in WM_CLOSE you still have a chance to abort closing the window, in WM_DESTROY you don't

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts