News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

About WM_DESTROY.

Started by hyperon, March 12, 2007, 01:30:06 PM

Previous topic - Next topic

hyperon

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?

Tedd

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.
No snowflake in an avalanche feels responsible.

hyperon

To Tedd:

In my application, the codes of message loop and yours codes are the same.
Why are my application still alive?

hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

hyperon

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).

Tedd

No snowflake in an avalanche feels responsible.