I am probably missing something really basic here..... why is the
window created with this code not resizeable, and why doesn't
the close button (in the top right corner) work? I have cut code
out until i am down to the very bare basics, and it still doesn't
work the way it should.....


[size=9]

WinMain proc hInst:HINSTANCE, hPrevInst:HINSTANCE, CmdLine:LPSTR, CmdShow:DWORD
LOCAL wc :WNDCLASSEX
LOCAL msg :MSG
LOCAL hwnd :HWND
LOCAL dwStyle :DWORD
LOCAL dwExStyle :DWORD
LOCAL windowClassAtom :DWORD


mov wc.cbSize, SIZEOF WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra, NULL
mov wc.cbWndExtra, NULL
push hInst
pop wc.hInstance
mov wc.hbrBackground, COLOR_APPWORKSPACE
mov wc.lpszMenuName, NULL
mov wc.lpszClassName, OFFSET ClassName
invoke LoadIcon, NULL, IDI_APPLICATION
mov wc.hIcon, eax
mov wc.hIconSm, eax
invoke LoadCursor, NULL, IDC_ARROW
mov wc.hCursor, eax
invoke RegisterClassEx, ADDR wc
mov windowClassAtom, eax


mov dwStyle, WS_OVERLAPPEDWINDOW or WS_SIZEBOX
mov dwExStyle, WS_EX_CLIENTEDGE
invoke CreateWindowEx, dwExStyle, windowClassAtom, ADDR AppName, dwStyle, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInst, NULL
mov masterhWnd, eax
invoke ShowWindow, masterhWnd, SW_SHOWNORMAL
invoke UpdateWindow, masterhWnd


.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
ret
WinMain endp


WndProc proc uses edi esi eax ebx ecx edx hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

.if uMsg==WM_DESTROY
invoke PostQuitMessage, NULL

.else
invoke DefWindowProc, hWnd, uMsg, wParam, lParam
ret
.endif


xor eax,eax
ret
WndProc endp
[/size]


P.S. sorry about the formatting.....
Posted on 2002-07-04 19:36:51 by sluggy
ummm doesn't it send WM_CLOSE... not sure... try it...

<edit>
i checked it.. the X button in the right cornere sends the WM_CLOSE message... other than that i dunno what's wrong if anything
</edit>
Posted on 2002-07-04 19:45:51 by NervGaz
I thought it may have been something to do with the message handling, so i took everything out of the WndProc except the call to DefWindowProc, and it still behaved the same, i.e. the close button didn't respond, and i couldn't drag the window around.
Posted on 2002-07-04 20:22:44 by sluggy
Add WS_THICKFRAME and WS_SYSMENU to dwStyle.
Posted on 2002-07-04 21:50:45 by comrade
Add WS_THICKFRAME and WS_SYSMENU to dwStyle.
They made no difference. Also, they are already included as part of the WS_OVERLAPPEDWINDOW style.
Posted on 2002-07-04 22:17:58 by sluggy
I guess: dont code "uses eax" in your WndProc.
Posted on 2002-07-05 02:39:53 by japheth
Set (don't add) dwStlye WS_THICKFRAME and WS_SYSMENU.
Posted on 2002-07-05 02:59:08 by comrade
An ATOM is a WORD. You may need to clear the upper 16 bits:
and windowClassAtom,0FFFFh
Posted on 2002-07-05 04:29:26 by tenkey
sluggy,

ICZ tut #3 should be the example your looking for. You can resize the window, you can close it using the x at the top right ... just like you needed it to.

Also at WndProc your saving the value of EAX in which this is also the returned value. Translating your WndProc would look something like this:
xor eax,eax

ret
WndProc endp

.... -- --------------- ....

xor eax, eax

pop edx
pop ecx
pop ebx
pop eax
pop esi
pop edi
mov esp, ebp
pop ebp
retn 16
The xor eax, eax no longer has an effect since you pop a value from the stack into eax. Of course, unless the popped value is 0. Also, what tenkey said is true, that the upper 16 bits(HiWord) must be 0 ... :)
Posted on 2002-07-05 16:31:42 by stryker
japheth and stryker,
you both nailed it with the "uses eax" :) I also thought of that while i was drifting off to sleep last night, and i tried it out today (before i even logged on to check your answers), and viola!, it worked. How could i have been so stupid? I knew from the beginning that it had to be something simple :rolleyes:


tenkey and stryker,
thanks for the pointer about the ATOM. I think i have gotten away with it so far because it is returned from RegisterClassEx as a DWORD with the top 16 bits cleared. If my code had of been this:
[size=12]

LOCAL classAtom :WORD

...
...
...
RegisterClassEx, ADDR wc
mov classAtom, ax

...
[/size]

then i would have been in trouble, as local variables are not zeroed when you create them, in fact it may well been an intermittent error. That could have kept me guessing for a while :)
Posted on 2002-07-06 07:15:04 by sluggy