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?
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.
To Tedd:
In my application, the codes of message loop and yours codes are the same.
Why are my application still alive?
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.
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).
Told you :P