News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

What is difference between WM_FINISH WM_DESTROY AND WM_CLOSE

Started by Don57, December 07, 2012, 09:16:28 AM

Previous topic - Next topic

Don57

I have to ReleaseDC and DeleteObject but in what section?



      .ELSEIF uMsg==WM_FINISH
           
          invoke MessageBox, NULL,addr sz_MsgBoxDoneText, addr sz_MsgDoneCaption, MB_OK
          invoke PostMessage,hWnd,WM_SYSCOMMAND,SC_CLOSE,NULL                         
          xor eax,eax                                                                   

      .ELSEIF uMsg==WM_DESTROY

          invoke PostQuitMessage,NULL

      .ELSE

          invoke DefWindowProc,hWnd,uMsg,wParam,lParam      
          ret

      .ENDIF

      xor eax,eax                                                             ; clear message

      ret

   WndProc ENDP

dedndave

WM_FINISH is not a "standard" windows message
you must be looking at Iczelion's tutorial
it is a custom "user defined" message

WM_CLOSE and WM_DESTROY are the ones we usually deal with

if you look at the example code in the other thread, you will see that i clean up the GDI stuff in WM_CLOSE

WM_CLOSE is sent to a window when the user clicks on the X box
if you want to cause a window to close, you can send it a WM_SYSCOMMAND with an SC_CLOSE notification
        INVOKE  SendMessage,hwndWindowToClose,WM_SYSCOMMAND,SC_CLOSE,NULL
you might do that if you have an "Exit" command on a menu, for example
if it is handled by the same window, you would use PostMessage, to prevent an infinite loop

WM_CLOSE may also be used to prevent a program from exiting
so - you might get the message and offer an "are you sure" message box
to keep the program running, you return 0 without calling DestroyWindow

if the message is processed by DefWindowProc, it peforms a DestroyWindow
if you process it, you can do the DestroyWindow
during WM_CLOSE is the best time to do clean-up
some clean-up, you might do before DestroyWindow - some after

WM_DESTROY is sent to tell you that the window is about to be destroyed
normally you use it to tell the message loop to terminate the program with PostQuitMessage
the message loop then sees that and GetMessage exits with a 0 instead of a positive non-zero value


dedndave

i recalled that incorrectly, Don   :redface:

if you want to keep a program from closing, you do not return TRUE for WM_CLOSE
you return 0 - just don't execute the DestroyWindow

i was thinking of WM_CREATE
where, if you return TRUE, the window is not created and an error is returned