===========================================
this snippet is from iczelions tut 8-01 pasted from a debugger
===========================================
00401119 CMP DWORD PTR SS:, 111
00401120 JNZ SHORT MENU.00401180
00401122 MOV EAX, DWORD PTR SS:
00401125 CMP AX, 1
00401129 JNZ SHORT MENU.00401140
========================================================
this snippet is from my code tut 8-01 pasted from a debugger
========================================================
00401432 CMP DWORD PTR SS:, 111
00401439 JNZ v2237028.00401517
0040143F MOV EAX, DWORD PTR SS:
00401442 CMP AX, 1
00401446 JNZ SHORT v2237028.0040145B
======================================================

the first icz app does not ever break if i put a break point on
00401125 CMP AX, 1 and keep on hitting enter __| (VK_ENTER OR VK_RETURN)

the second mycode ALWAYS BREAKS if i put a break point on
00401125 CMP AX, 1 and hit enter __| (VK_ENTER OR VK_RETURN)
=======================================================
my code in masm
IDM_EXIT equ 1
.ELSEIF uMsg==WM_COMMAND
mov eax,wParam
.IF ax==IDM_EXIT
invoke SendMessage,hWnd,WM_CLOSE,0,0
.ELSEIF ax==IDM_ABOUT

so my proggie terminates if i hit enter when my proggie is in focus
and also my proggie breaks when i press esc too VK_ESCAPE

iczelions code
IDM_TEST equ 1
.ELSEIF uMsg==WM_COMMAND
mov eax,wParam
.IF ax==IDM_TEST
invoke MessageBox,NULL,ADDR Test

his does not terminate

what can cause this different behaviour for same code
both tested in w2k with ollydbg as the debugger


:(
Posted on 2004-01-01 08:07:19 by bluffer
The compare test is always jumping - PAST - the point where you are placing the breakpoint. The breakpoint is not being encountered, and thus the break is not occuring. The fact that your own code DOES break indicates that the compare test of uMsg is failing, possibly due to corruption of the stack, since thats where uMsg is, as it is a local to the procedure, its kept in the procedure stack frame.

Have a nice day :)
Posted on 2004-01-01 09:12:16 by Homer
i cant find out where iam CORRUPTING THE stack

can some one look into my code and say why this is processing enter and escape

iam also attaching the exe (i dunno if i can attach if i cant i will rename it to txt or jpeg or what ever and attach it rename it to exe and can try it out)

oops it is written there i cant attache exes so i have zipped it and attached


.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

szText MACRO Name, Text:VARARG
LOCAL lbl
jmp lbl
Name db Text,0
lbl:
ENDM

WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD
TopEditBox PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
PushButton PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD

.data
ClassName db "BLAH",0
AppName db "BLAH",0
MenuName db "FirstMenu",0
szBtnText db "BLAH",0


.data?
hInstance HINSTANCE ?
CommandLine LPSTR ?
hMenu HMENU ?
hwndEdit HWND ?

.const
IDM_EXIT equ 1
IDM_ABOUT equ 2

.code
start:
invoke GetModuleHandle, NULL
mov hInstance,eax
invoke GetCommandLine
mov CommandLine,eax
invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
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_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra,NULL
mov wc.cbWndExtra,NULL
push hInstance
pop wc.hInstance
mov wc.hbrBackground,COLOR_BTNFACE+1
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

INVOKE CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\
WS_SYSMENU or WS_MINIMIZEBOX ,360,\
240,80,120,NULL,NULL,\
hInst,NULL
mov hwnd,eax
invoke ShowWindow, hwnd,SW_SHOWNORMAL
invoke UpdateWindow, hwnd
.WHILE TRUE
invoke GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
invoke IsDialogMessage, hwnd, ADDR msg
.IF !eax
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.ENDIF
.ENDW
mov eax,msg.wParam
ret
WinMain endp

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL hEdit :DWORD
.IF uMsg==WM_CREATE

invoke TopEditBox,0,hWnd,16,16,75,21,501
invoke PushButton,ADDR szBtnText,hWnd,16,48,75,21,523

.ELSEIF uMsg==WM_COMMAND
mov eax,wParam
.IF ax==IDM_EXIT
invoke SendMessage,hWnd,WM_CLOSE,0,0
.ELSEIF ax==IDM_ABOUT
jmp @F
szAboutText db "BLAH",0
szAboutCaption db "BLAH",0
@@:
invoke MessageBox,hWnd,ADDR szAboutText,ADDR szAboutCaption,MB_OK or MB_ICONINFORMATION
.ELSEIF ax==523
jmp @F
szMessage db "Hello, world!",0
szCaption db "Hi!",0
@@:
invoke MessageBox,hWnd,ADDR szMessage,ADDR szCaption,MB_OK or MB_ICONEXCLAMATION
.ENDIF
.ELSEIF uMsg==WM_DESTROY
invoke PostQuitMessage,NULL
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF

xor eax,eax
ret
WndProc endp

TopEditBox proc lpText:DWORD,hParent:DWORD,
a:DWORD,b:DWORD,wd:DWORD,ht:DWORD,ID:DWORD
LOCAL hFont :DWORD
LOCAL hEdit :DWORD
szText editClass,"EDIT"

invoke CreateWindowEx,WS_EX_CLIENTEDGE,
ADDR editClass,lpText,
WS_CHILD or WS_VISIBLE or WS_TABSTOP or ES_AUTOHSCROLL,
a,b,wd,ht,hParent,ID,
hInstance,NULL
mov hEdit, eax
invoke GetStockObject,DEFAULT_GUI_FONT ; ANSI_FIXED_FONT
mov hFont, eax
invoke SendMessage,hEdit,WM_SETFONT,hFont, 0
ret

TopEditBox endp



PushButton proc lpText:DWORD,hParent:DWORD,a:DWORD,b:DWORD,wd:DWORD,ht:DWORD,ID:DWORD
LOCAL hFont :DWORD
LOCAL hBtn :DWORD
szText btnClass,"BUTTON"

invoke CreateWindowEx,WS_EX_CLIENTEDGE,
ADDR btnClass,lpText,
WS_CHILD or WS_VISIBLE,
a,b,wd,ht,hParent,ID,
hInstance,NULL

mov hBtn, eax

invoke GetStockObject,DEFAULT_GUI_FONT
mov hFont, eax
invoke SendMessage,hBtn,WM_SETFONT,hFont,0

ret
PushButton endp

end start

Posted on 2004-01-04 05:53:20 by bluffer
bluffer,
You probably won't get too many people looking over your code unless you change the way you present it. You should use the
directives when posting, so the spacing and indentations of your source is preserved. It is difficult to read code that is left justified on the margin. Why don't you package up all the source statements needed for a build, including the resource statements into a ZIP file. Then send it as an attachment along with a concise statement of what is wrong. It will surely make thing a lot easier and faster. Ratch
Posted on 2004-01-04 14:49:17 by Ratch
I can't see anything obviously wrong with it and there appears to be no stack corruption in this case. Please post the complete source in a zip.
For future reference, here is the stackchecking macro I use during debugging - just include the file somewhere near the top of your source, then use the two lines "startstack" and "endstack" around the section of code to be checked. If you get a messagebox popup when you run the exe, it will tell you where the misalignment occured and how large it was (and the direction + or -), if nothing happens then the stack was not corrupted between the statements.

Have a nice day :)
Posted on 2004-01-04 16:47:41 by Homer
ratch i edited my above post as you said with code directives
thanks evil homer i dld yoursafestack.inc will try using it btw i have uploaded a new attachment along with source in my previous post

hope now you or some one can tell why it is processing enter and escape
Posted on 2004-01-06 00:57:21 by bluffer
bluffer,
Good job on presenting the code so I could read and understand it. Looks to me like you are creating a window and then creating two child control windows within it. So far so good. Then I have to ask; why is there a IsDialogMessage API in your message loop? You don't have a dialog box in your program. When I removed the IsDialogMessage, the program did not respond to ENTER and ESCAPE, and appeared to work OK to the limits that it was completed so far.

I can rewrite that program using my methods for a demonstration and send it to you, but I will not do it unless you want me to. It's up to you. Ratch
Posted on 2004-01-06 17:32:14 by Ratch
Yes I too noticed that call in the messagepump.. I wasn't familiar with it so I looked it up and its fine..

Although the IsDialogMessage function is intended for modeless dialog boxes, you can use it with any window that contains controls, enabling the windows to provide the same keyboard selection as is used in a dialog box.

When IsDialogMessage processes a message, it checks for keyboard messages and converts them into selection commands for the corresponding dialog box. For example, the TAB key, when pressed, selects the next control or group of controls, and the DOWN ARROW key, when pressed, selects the next control in a group.
Posted on 2004-01-06 20:32:09 by Homer
bluffer,
EvilHomer2k is correct about using IsDialogMessage in your main window to gain dialog box functionality. If you do, however, you must be aware of the following:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/dialogboxes/dialogboxprogrammingconsiderations.asp

Select Dialog Box Keyboard Interface. As you can see in the table, a ENTER supplies a IDOK code in wParam, which is the same as the IDM_EXIT you have defined in your program. ESCAPE supplies a IDCANCEL code, which is the same a the IDM_ABOUT code defined in your program. What you should do is check the ID parameter in LOWORD(wParam) to make sure the WM_COMMAND is coming from your child windows instead of the keyboard. Ratch
Posted on 2004-01-06 22:16:03 by Ratch
Ratch and EvilHomer2 thanks to both of you for answering to my question

so IsDialogMessage is processing my enter and escape and sending it to my dialog

i know if i change IDM_EXIT and IDM_ABOUT to some other value i can eliminate the problem but that is kind of hack mechanic work

i couldnt understand why if some one elses code worked with 1 and 2
why not mine

What you should do is check the ID parameter in LOWORD(wParam) to make sure the WM_COMMAND is coming from your child windows instead of the keyboard. Ratch


thaks for that info ratch

ill try it and if i face problems ill come back and thanks for your offer to code but let me try and fail first
Posted on 2004-01-07 09:56:23 by bluffer