The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: hyperon on March 12, 2007, 01:30:06 PM

Title: About WM_DESTROY.
Post by: hyperon on March 12, 2007, 01:30:06 PM
An application usually calls PostQuitMessage in response to the WM_DESTROY message, for simple example:

.if     Msg==WM_DESTROY
    invoke  PostQuitMessage,NULL
    xor eax,eax
    ret
.else
    invoke  DefWindowProc,hWnd,Msg,wParam,lParam
    ret
.endif

Sometimes, I use above codes to goof off, and everything is OK.
On the morning, I did this again and watched that my application was still alive, besides its window was removed from the screen.
Why?
Title: Re: About WM_DESTROY.
Post by: Tedd on March 12, 2007, 01:57:33 PM
What it actually ends up doing is removing the window, and posting WM_QUIT - which should be picked up by your message-loop so it can exit.
Depending how you do your message-loop, you could still keep your application running.

Usually it will look something like this..
invoke ShowWindow, hWnd,SW_SHOWDEFAULT
invoke UpdateWindow, hWnd
.WHILE TRUE
    invoke GetMessage, ADDR msg,NULL,0,0
    .BREAK .IF(!eax)
    invoke TranslateMessage, ADDR msg
    invoke DispatchMessage, ADDR msg
.ENDW
mov eax,[msg].wParam

The 'exit' part is ".BREAK .IF(!eax)" which will jump out of the while-loop when GetMessage returns zero, which it does when WM_QUIT is received.
Title: Re: About WM_DESTROY.
Post by: hyperon on March 13, 2007, 01:07:59 AM
To Tedd:

In my application, the codes of message loop and yours codes are the same.
Why are my application still alive?
Title: Re: About WM_DESTROY.
Post by: hutch-- on March 13, 2007, 03:26:30 AM
hyperon,

You are safer to have a single "DefWindowProc()" at the end of the WndProc rather that buried within a conditional runtime block. You can then leave it as default processing unless the message you are processing requires that you return ZERO without default processing.
Title: Re: About WM_DESTROY.
Post by: hyperon on March 13, 2007, 05:01:11 AM
Thank everyone! I have checked my codes again, and then found a piece of codes which made this error.
In message loop of my application, GetMessage() was called by the following:

invoke  GetMessage,addr stMsg,hWnd,0,0

And hWnd!=NULL, it is retrieved by CreateWindowEx,
so GetMessage() didn't get WM_QUIT(WM_QUIT is a current thread's message).
Title: Re: About WM_DESTROY.
Post by: Tedd on March 13, 2007, 03:56:32 PM
Told you :P