can someone tell me why this code doesn't work? it should prevent windows from shutdown and display a messagebox, but it doesn't work! i tried to return 0 (as you can see below) and i tried to return 1. nothing works. please help. .386 .model flat, stdcall option casemap: none include \masm32\include\windows.inc include \masm32\include\kernel32.inc includelib \masm32\lib\kernel32.lib include \masm32\include\user32.inc includelib \masm32\lib\user32.lib .data msgtext db "blabla",0 msgtitle db "",0 iswaiting db 1 .data? hinstance HINSTANCE ? aMsg MSG > .code reminder: invoke GetModuleHandle, NULL mov hinstance, eax .while iswaiting==1 invoke WaitMessage invoke GetMessage, addr aMsg, NULL, 0, 0 .if aMsg.message==WM_QUERYENDSESSION invoke MessageBox,NULL,addr msgtext,addr msgtitle,MB_OK or MB_ICONEXCLAMATION mov iswaiting, 0 mov eax,0 ret .endif ret .endw invoke ExitProcess, NULL end reminder
WM_QUERYENDMESSAGE must be handled in a window proc, because Windows is using some kind of SendMessage function to send out this message to every window in the system. If a message handler needs to return a value to the sender via EAX, then a window proc is the only way to do it. The various SendMessage functions (which require a window destination) provide the only style of message passing that works like a subroutine call. GetMessage passes such messages directly to the window proc, bypassing all other message processing. A dialog proc can also work because it is called by a window proc. However, you'll need to use the dialog box method of returning values.