Dear all
    first, please see the codes:
-----------------------------------
.while TRUE
    invoke GetMessage, addr @stMsg, NULL, NULL, NULL.
    .break  .if eax == 0
    invoke TranslateMessage, addr @stMsg
    invoke DispatchMessage, addr @stMsg
.endw
........
invoke  ExitProcess, NULL
------------------------------------
    to use these codes, my program can run well and quit normally.
    when i replace the second argument from NULL to hWnd, my program can run normally, but cannot quit.

    My "WinProc" callback procedure code is:
-------------------------------------------
    .........
    .if          eax == WM_PAINT
          ..........
    .elseif    eax == WM_CLOSE
            invoke  DestroyWindow, .....
            invoke  PostQuitMessage, ........
            xor  eax, eax
            ret
    .else
      ............
-------------------------------------------
Now, I want to know, why My program cannot quit?

BTW
if i add a option(eax == -1) to break the loop, My program can quit
---------------
.while TRUE
    invoke GetMessage, addr @stMsg, NULL or hWnd, NULL, NULL.
    .break  .if eax == 0 || eax == -1
    invoke TranslateMessage, addr @stMsg
    invoke DispatchMessage, addr @stMsg
.endw
invoke  ExitProcess, NULL
---------------

thanks and best regards.
billbear
Posted on 2006-10-23 21:36:22 by billbear
Dear all

    Sorry, I forgot to said,
    the hWnd is correct handle

thanks and best regards.
billbear
Posted on 2006-10-23 21:40:24 by billbear
GetMessage returns 0 for WM_QUIT and non-zero for other messages, *BUT* returns -1 if an error occurred, so
check out the error using GetLastError.

Edit: Try removing "DestroyWindow" from the WM_CLOSE processing, since GetLastError returns "invalid hwnd"
Posted on 2006-10-23 22:12:41 by sinsi
I think Raymond Chen addresses this somewhere in his The Old New Thing blog. And yup, indeed he does. Read through the blog entry as well as all the comments :)

(I've been bitten by this myself, thinking I was going to be all-efficient by filtering by hwnd).

I'll post the last comment entry here, in case The Old New Thing ever moves:

while (GetMessage(&msg, hwnd, 0, 0)) - is also wrong for other reason - your applicaion will never exit. WM_QUIT is posted to main thread with NULL for windows handle ( PostQuitMessage ). In this case GetMessage never retrieves WM_QUIT and application hangs. I have learned it in hard way teaching class of people Windows programming. My test application never exited and in Windows 3.1 blocked whole OS. I honestly said that I do not know the problem and found it only for next meeting.
I always knew that teaching brings a lot of new knowledge and this is good example.

Posted on 2006-10-24 01:19:45 by f0dder
Dear Fodder and sinsi,

    thank you very much!

best regards.
billbear
Posted on 2006-10-25 03:53:34 by billbear
Glad to have helped :)
Posted on 2006-10-25 08:48:48 by f0dder