i made the most simple win32asm file, i just create and register a class, then create a window, then call showwindow and updatewindow, then enter the message loop

for the window procedure i have nothing else besides invoke defwindowproc

but when i close the window, it closes but the program (win32.exe) keeps running...and i can only close it using ctrl+alt+del...this is becoming a realllll pain!

here's the source code

.386
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\gdi32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\gdi32.lib


WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
WndProc proto :DWORD,:DWORD,:DWORD,:DWORD

.data
className db 'My Class',0
winName db 'My Window',0
mystr db 'akjsdfajfajfasjdfkajfiuwmncandsfijacnalsdfjadfjasfjasdfj',0
text db 0

.data?
hInst dd ?


.code
start:

invoke GetModuleHandle,NULL
mov hInst,eax



invoke WinMain,hInst,NULL,NULL,SW_SHOWDEFAULT
invoke ExitProcess,eax


WinMain proc hinst:DWORD,bah:DWORD,blah:DWORD,show:DWORD

LOCAL wd:WNDCLASSEX
LOCAL hWnd:HWND
LOCAL msg:MSG

mov wd.cbSize,SIZEOF(WNDCLASSEX)
mov wd.style,CS_HREDRAW OR CS_VREDRAW
mov wd.lpfnWndProc,offset WndProc
mov wd.cbClsExtra,NULL
mov wd.cbWndExtra,NULL
push hinst
pop wd.hInstance
invoke LoadIcon,NULL,IDI_APPLICATION
mov wd.hIcon,eax
invoke LoadCursor,NULL,IDC_ARROW
mov wd.hCursor,eax
mov wd.hbrBackground,COLOR_BACKGROUND+1
mov wd.lpszMenuName,NULL
mov wd.lpszClassName,offset className
mov wd.hIconSm,NULL

invoke RegisterClassEx,addr wd

invoke CreateWindowEx,WS_EX_OVERLAPPEDWINDOW,addr className,addr winName,
WS_VISIBLE OR WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,NULL,
CW_USEDEFAULT,NULL,NULL,NULL,hinst,NULL

mov hWnd,eax
invoke ShowWindow,eax,SW_MAXIMIZE

invoke UpdateWindow,hWnd




MESS_LOOP:
invoke GetMessage,addr msg,hWnd,0,0
cmp eax,0
jne disp_mess
jmp END_LOOP

disp_mess:
invoke DispatchMessage,addr msg
jmp MESS_LOOP

END_LOOP:
mov eax,msg.wParam
ret

WinMain endp



WndProc proc hnd:DWORD,ms:DWORD,wpar:WPARAM,lpar:LPARAM


def:
invoke DefWindowProc,hnd,ms,wpar,lpar

ret
WndProc endp

end start



thanks
Posted on 2003-04-15 01:16:23 by AnotherWay83
GetMessage returns 0 only if a WM_QUIT message has been posted (by PostQuitMessage). So insert such a call when receiving WM_CLOSE or WM_DESTROY in your wndproc.
Posted on 2003-04-15 01:49:01 by japheth
Edit your wndproc to



WndProc proc hnd:DWORD,ms:DWORD,wpar:WPARAM,lpar:LPARAM
cmp ms, WM_CLOSE; WM_DESTROY would work fine too
je @F
def:
invoke DefWindowProc,hnd,ms,wpar,lpar
ret
@@:
invoke PostQuitMessage,0
xor eax,eax
ret
WndProc endp
Posted on 2003-04-15 03:55:35 by roticv
yeah, i was thinking defwindowproc would make the call to postquitmessage itself upon receiving the wm_destroy message...guess not :D

thanks for the help
Posted on 2003-04-15 13:39:34 by AnotherWay83
DefWindowProc won't quit the application because the window being destroyed isn't required to be the main application window.
Posted on 2003-04-15 14:22:29 by tenkey
You will have to use WndPro in the following way:-


WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.if uMsg==WM_CREATE
invoke SetDlgItemText,hWnd,IDC_EDIT,ADDR AppName
.ELSEIF uMsg==WM_DESTROY
invoke PostQuitMessage,NULL
.ELSEIF uMsg==WM_COMMAND
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
xor eax,eax
ret
WndProc endp

This will make your application exit from the memory ;-)
Posted on 2003-04-16 01:34:05 by telophase