Below is code for a simple window that has a menu. The weird thing is that it once displayed message boxes in front of the main window but now it displays them behind the main window. I had added code for displaying system information in the client are and it worked fine. Then when tried the menu item "Save & Open" the message boxes appeared behind the window. I removed the new code but still MB was behind main window. This happened to me before on another project and it is now pissing me off.

I have attached the executable also.

Any help appreciated if its a syntax error or something.


.386
.model flat,stdcall
OPTION SCOPED
option casemap:none

WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
;ZeroMemory proto :DWORD,:DWORD

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\gdi32.inc
include \masm32\include\comctl32.inc
include \masm32\include\winmm.inc
include \masm32\include\masm32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\comctl32.lib
includelib \masm32\lib\winmm.lib
includelib \masm32\lib\masm32.lib


include d:\masm32\mystuff\exploder\cdchdata.asm
include d:\masm32\mystuff\exploder\cdchdatani.asm
include d:\masm32\mystuff\exploder\cdchconst.asm
include d:\masm32\mystuff\exploder\cdchmacros.asm


.code
OsInfoString db "Computer Name",13,10
db "Major Version",13,10
db "Minor Version",13,10
db "Build Number",13,10
db "Platform ID",13,10
db "CSDVersion",0

start:
invoke GetModuleHandle, NULL
mov hInstance,eax
invoke GetCommandLine
mov CommandLine,eax
invoke WinMain, hInstance,NULL,CommandLine, SW_NORMAL
invoke ExitProcess,eax

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:HWND
mov wc.cbSize,SIZEOF WNDCLASSEX
mov wc.style, CS_BYTEALIGNCLIENT or CS_HREDRAW or CS_VREDRAW or CS_OWNDC
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra,NULL
mov wc.cbWndExtra,NULL
push hInst
pop wc.hInstance
mov wc.hbrBackground,COLOR_WINDOW +1
mov wc.lpszMenuName,OFFSET MenuName
mov wc.lpszClassName,OFFSET ClassName
invoke LoadIcon,NULL,IDI_WINLOGO
mov wc.hIcon,eax
mov wc.hIconSm,eax
invoke LoadCursor,NULL,IDC_ARROW;Null or hInstance
mov wc.hCursor,eax
invoke RegisterClassEx, addr wc

INVOKE CreateWindowEx,WS_EX_APPWINDOW,ADDR ClassName,ADDR AppName,\
WS_OVERLAPPEDWINDOW ,CW_USEDEFAULT,\
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,\
hInst,NULL


mov hwnd,eax
INVOKE ShowWindow, hwnd,SW_SHOWNORMAL
INVOKE UpdateWindow, hwnd

.WHILE TRUE
INVOKE GetMessage, ADDR msg,hwnd,0,0
.BREAK .IF (!eax)
INVOKE TranslateMessage,ADDR msg

INVOKE DispatchMessage, ADDR msg

.ENDW
mov eax,msg.wParam
ret
WinMain endp

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL ps:PAINTSTRUCT
.IF uMsg==WM_DESTROY
invoke PostQuitMessage,NULL
.ELSEIF uMsg==WM_CREATE

invoke GetDC,hWnd
mov hdc,eax
mov osinfo.dwOSVersionInfoSize, sizeof OSVERSIONINFO
invoke GetVersionEx, addr osinfo
invoke GetSystemInfo, addr sysinfo

.ELSEIF uMsg==WM_PAINT

;Invoke Beep,NULL,NULL

.ELSEIF uMsg==WM_COMMAND ;MENU COMMANDS
mov eax,wParam
.IF ax==IDM_GETOSINFO
invoke Beep,NULL,NULL
.ELSEIF ax==IDM_OPEN
invoke MessageBox,hWnd,ADDR Goodbye_string,OFFSET AppName,MB_OK or MB_TOPMOST or MB_APPLMODAL
.ELSEIF ax==IDM_SAVE
invoke MessageBox,hWnd,ADDR Hello_string,OFFSET AppName,MB_OK or MB_TOPMOST or MB_APPLMODAL
.ELSEIF ax==IDM_EXIT
invoke DestroyWindow,hWnd
.ENDIF

.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF


xor eax,eax
ret
WndProc endp

end start


Posted on 2003-01-05 15:32:40 by IwasTitan
I found two problems when runnin ure code...

.WHILE TRUE

INVOKE GetMessage, ADDR msg,hwnd,0,0
.BREAK .IF (!eax)
INVOKE TranslateMessage,ADDR msg

INVOKE DispatchMessage, ADDR msg

.ENDW


dont use "GetMessage, ADDR msg, hwnd, 0, 0" use "GetMessage, ADDR msg, NULL, 0, 0"

.ELSEIF uMsg==WM_PAINT


;Invoke Beep,NULL,NULL


Your if block is handling WM_PAINT, therefore it never calls defwindowproc, therefore window never gets painted
Posted on 2003-01-05 17:14:37 by BubbaFate
On my win2k machine your attachment continiously runs with 100% CPU usage (it doesn't shut down even if you close the window). The GETOSVERSIONINFO menu does nothing, exit closes the window but the process keeps running and both Save and Open make the program hang...

Is the code you posted the same as the application in the attachment? Try removing the WM_PAINT .if case since you don't handle it. I had some trouble before having a WM_PAINT handler (i.e. not calling DefWindowProc for it) but not actually handling it.

Thomas
Posted on 2003-01-05 17:14:53 by Thomas
Thomas and BubbaFate:
The WM_PAINT was causing the problem..thanx.


Bubba...the hWnd or NULL shouldn't make a difference

Thomas...the GETOSVERSIONINFO menu isn't suppose to do anything because i removed the code.


I HATE THE WM_PAINT MESSAGE!!!

thanx again


:alright:
Posted on 2003-01-05 17:47:20 by IwasTitan
the NULL is why the app locks up on thomas's machine
Posted on 2003-01-05 17:54:02 by BubbaFate

the NULL is why the app locks up on thomas's machine


I don't get yah. Are you saying to use NULL in the case of win2k...or just the opposite?

I put Null back in mine ...98se

The original prog was running in my task list after i closed the prog also...got it fixed now though.
Posted on 2003-01-05 19:38:14 by IwasTitan
ya, the reason why the program never exited was because you were using

INVOKE GetMessage, ADDR msg,hwnd,0,0

and not
INVOKE GetMessage, ADDR msg,NULL,0,0


The reason it acts this way? Im not completely sure but I believe the answer to be this...

The WM_QUIT message is not associated with a window and therefore will never be received through a window's window procedure. It is retrieved only by the GetMessage or PeekMessage functions. -Microsoft Platform SDK

So if thats true then supplying a window handle to GetMessage will cause it to never retrieve the WM_QUIT message.

Another theory...

If there is an error, the return value is -1. For example, the function fails if hWnd is an invalid window handle or lpMsg is an invalid pointer. To get extended error information, call GetLastError. -Microsoft Platform SDK

That quote is from the remarks section of the GetMessage description. By the time your message loop retireves the WM_QUIT message, the main winodw is already destroyed, therefore 'hwnd' is an invalid handle, therefore GetMessage returns -1, therefore your message loop never exits and it eats up your resources.
Posted on 2003-01-05 19:56:14 by BubbaFate
Well it will certainly be :

INVOKE GetMessage, ADDR msg,NULL,0,0

from now on


The message system for windows can be very confusing.
Posted on 2003-01-05 21:11:30 by IwasTitan
Alot of things in Windows is very confusing... especially with the M$ monopoly machine making revision every other year... ;)
Posted on 2003-01-05 23:35:36 by NaN

Alot of things in Windows is very confusing... especially with the M$ monopoly machine making revision every other year... ;)


Which makes the learning curve substantial...even for the not so seriose hobbyist.

The revisions are obviously not what gives M$ a monopoly but they make things difficult for programmers as far as cross platform issues go....especially those wanting to impliment external hardware such as robotics applications.


:alright:
Posted on 2003-01-06 20:16:10 by IwasTitan