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
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
Dear all
Sorry, I forgot to said,
the hWnd is correct handle
thanks and best regards.
billbear
Sorry, I forgot to said,
the hWnd is correct handle
thanks and best regards.
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"
check out the error using GetLastError.
Edit: Try removing "DestroyWindow" from the WM_CLOSE processing, since GetLastError returns "invalid hwnd"
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.
(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.
Dear Fodder and sinsi,
thank you very much!
best regards.
billbear
thank you very much!
best regards.
billbear
Glad to have helped :)