here is my code and i have attached the source rsrc and exes
i am using win2k
this code assembles and shows up the dialogbox but when i click in the second edit box there appears a slew of message boxes approximately 25 of them
before it stops i dont understand why this happens (if you are bored clicking the ok
keep the enter button pressed till it stops)
i tried the ws_disabled style for the second edit box it does not pop up the message boxes
i have attached both in a zip the zip has two zips inside it one is original
other has ws_disabled style and i have also enclosed a diff text between them
but why should wm_command be processed and why should the message boxes appear is a mystery to me
can some one explain it to me
thanks and regards
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
DialogProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
.data
name_buffer db 20h dup (?)
const_string db "-BiW-",0
.data?
hInstance dd ?
.code
start:
main :
invoke GetModuleHandle,NULL
mov hInstance ,eax
invoke DialogBoxParamA,hInstance,64,NULL,ADDR DialogProc,NULL
invoke ExitProcess,NULL
DialogProc Proc handle:DWORD,message:DWORD,wParam:DWORD,lParam:DWORD
.if(message==WM_COMMAND)
mov eax,wParam
.if(ax==102)
invoke GetDlgItemTextA,handle,101,offset name_buffer,10h
invoke lstrcat,offset name_buffer,offset const_string
.elseif(ax==103)
invoke MessageBox,NULL,NULL,NULL,NULL
.endif
.elseif(message==WM_CLOSE)
invoke EndDialog,handle,NULL
jmp ending
.endif
ending:
mov eax, FALSE
ret
DialogProc endp
end main
i am using win2k
this code assembles and shows up the dialogbox but when i click in the second edit box there appears a slew of message boxes approximately 25 of them
before it stops i dont understand why this happens (if you are bored clicking the ok
keep the enter button pressed till it stops)
i tried the ws_disabled style for the second edit box it does not pop up the message boxes
i have attached both in a zip the zip has two zips inside it one is original
other has ws_disabled style and i have also enclosed a diff text between them
but why should wm_command be processed and why should the message boxes appear is a mystery to me
can some one explain it to me
thanks and regards
mov eax,wParam
.if(ax==102)
try it as .if(eax==102)
as ax might well be 102 sometimes, especially during init stages
clicking the edit box will probably give a 02000102 value for eax, followed
by a 01000102 when it loses focus
.if(ax==102)
try it as .if(eax==102)
as ax might well be 102 sometimes, especially during init stages
clicking the edit box will probably give a 02000102 value for eax, followed
by a 01000102 when it loses focus
bluffer,
but why should wm_command be processed and why should the message boxes appear is a mystery to me
Well, the WM_COMMAND message gets processed because it is SUPPOSED to get processed. You defined a Dialog Box with controls in the Resource file, so don't be surprised to find that they send WM_COMMAND messages to their designated Dialog Box when they are activated. The MessageBox shows up because you have a MessageBox API call where the edit box gets processed. You get multiple occurrences of MessageBox because you do not have the Handle of the Dialog Box coded in the call. Read the documentation of MessageBox.
And speaking of the Dialog Box Procedure. The documentation for Dialog Box Procedure says you are to return a TRUE if you process a message and a FALSE if you do not. You are returning a FALSE in all cases.
One more thing. When you specify the styles in the template, why not make it easy on someone else reading your code by specifying the styles mnemonically like ES_LEFT|WS_BORDER|WS_TABSTOP instead of a bit blasted word like 0x50A00004? Ratch
but why should wm_command be processed and why should the message boxes appear is a mystery to me
Well, the WM_COMMAND message gets processed because it is SUPPOSED to get processed. You defined a Dialog Box with controls in the Resource file, so don't be surprised to find that they send WM_COMMAND messages to their designated Dialog Box when they are activated. The MessageBox shows up because you have a MessageBox API call where the edit box gets processed. You get multiple occurrences of MessageBox because you do not have the Handle of the Dialog Box coded in the call. Read the documentation of MessageBox.
From the MessageBox Documentation
If you create a message box while a dialog box is present, use the handle of the dialog box as the hWnd parameter. The hWnd parameter should not identify a child window, such as a control in a dialog box.
If you create a message box while a dialog box is present, use the handle of the dialog box as the hWnd parameter. The hWnd parameter should not identify a child window, such as a control in a dialog box.
And speaking of the Dialog Box Procedure. The documentation for Dialog Box Procedure says you are to return a TRUE if you process a message and a FALSE if you do not. You are returning a FALSE in all cases.
One more thing. When you specify the styles in the template, why not make it easy on someone else reading your code by specifying the styles mnemonically like ES_LEFT|WS_BORDER|WS_TABSTOP instead of a bit blasted word like 0x50A00004? Ratch
You defined a Dialog Box with controls in the Resource file, so don't be surprised to find that they send WM_COMMAND messages to their designated Dialog Box when they are activated
so the system itself may send WM_COMMAND during initialization
If you create a message box while a dialog box is present, use the handle of the dialog box as the hWnd parameter. The hWnd parameter should not identify a child window, such as a control in a dialog box.
i tried giving the msg box the handle but it was popping up two message boxes so i made it null and it started giving 25 msg boxes
you may change this line like this and try
invoke MessageBox,handle,NULL,NULL,NULL
it will still pop up two mesage boxes one for 10000067 in eax and 0ther for 20000067 in eax
The documentation for Dialog Box Procedure says you are to return a TRUE if you process a message and a FALSE if you do not. You are returning a FALSE in all cases.
i changed my code to below it still pops up ;)
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
DialogProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
.data
name_buffer db 20h dup (?)
const_string db "-BiW-",0
.data?
hInstance dd ?
.code
start:
main :
invoke GetModuleHandle,NULL
mov hInstance ,eax
invoke DialogBoxParamA,hInstance,64,NULL,ADDR DialogProc,NULL
invoke ExitProcess,NULL
DialogProc Proc handle:DWORD,message:DWORD,wParam:DWORD,lParam:DWORD
.if(message==WM_COMMAND)
mov eax,wParam
.if(ax==102)
invoke GetDlgItemTextA,handle,101,offset name_buffer,10h
invoke lstrcat,offset name_buffer,offset const_string
mov eax,TRUE
ret
.elseif(ax==103)
invoke MessageBox,NULL,NULL,NULL,NULL
mov eax,TRUE
ret
.endif
.elseif(message==WM_CLOSE)
invoke EndDialog,handle,NULL
mov eax,TRUE
ret
.endif
mov eax, FALSE
ret
DialogProc endp
end main
hehe i used the bit blasted word because i avoided uploading another resource.h file with the packeage i used reshack to extract the dword and cut pasted it there
when brw made it it was like you mentioned WS_BLAH
thank you very much for replying
mov eax,wParam
.if(ax==102)
again, use EAX not just ax.
ie:
mov eax,wParam
.if(eax==102)
.if(ax==102)
again, use EAX not just ax.
ie:
mov eax,wParam
.if(eax==102)
This is what happens. When you click the editbox a message SETFOCUS is sent by WM_COMMAND to dialog process. The Edit ID catches the message and open the messagebox. When that happens the editbox loses focus and a message KILLFOCUS is sent to dialog process, before messagebox appears. Closing the messagebox alows processing of the already sent KILLFOCUS message causing a new message box. But closing the messagebox also sets the editbox in focus so a message SETFOCUS is sent ... and so on.
Regards
Regards
hi minor thanks for taking time to reply
but why it stops then after displaying about 25 msg boxes it should go on
as you say so on isnt it ;)
evilcrn
its not that i cannot avoid that message box by making it eax
but if you see many tuts its coded like that only
cmp ax,IDC_PUSHBUTTON1 etc
but why it stops then after displaying about 25 msg boxes it should go on
as you say so on isnt it ;)
evilcrn
its not that i cannot avoid that message box by making it eax
but if you see many tuts its coded like that only
cmp ax,IDC_PUSHBUTTON1 etc
debugged it, messagebox is kicking in when eax = 01000067h and 02000067h
so changing it to cmp eax will work, however the messagebox will never appear because the edit box isnt a button and wont return 00000067h ever (67h=103)
so changing it to cmp eax will work, however the messagebox will never appear because the edit box isnt a button and wont return 00000067h ever (67h=103)
you may change this line like this and try
invoke MessageBox,handle,NULL,NULL,NULL
it will still pop up two mesage boxes one for 10000067 in eax and 0ther for 20000067 in eax
hey evilcrn8 i posted this in my earlier post and i know making it to eax will work
and my question is why should i
as many of the icz tuts i seen have
cmp(ax==****)
not cmp(eax==***)
any way i think its better to forget this and make it eax and continue coding rather than asking some theoratical why why questions
tx for reply
perhaps you read some bad tuts ;)
This is how the WM_COMMAND looks.
You copy wParam to eax i.e. hiword is the notification code 0100 or 0200 as evlncrn8 said. These are notifications for EN_SETFOCUS and EN_KILLFOCUS. Loword is the id of control i.e. 67h or 103 equal to the value you gave the editbox. What happens is as I described it earlier. As a test exchange the messagebox call with "invoke MessageBeep,0FFFFFFFFh and the problem set and kill focus will end.
Regards
WM_COMMAND
wNotifyCode = HIWORD(wParam); // notification code
wID = LOWORD(wParam); // item, control, or accelerator identifier
hwndCtl = (HWND) lParam; // handle of control
You copy wParam to eax i.e. hiword is the notification code 0100 or 0200 as evlncrn8 said. These are notifications for EN_SETFOCUS and EN_KILLFOCUS. Loword is the id of control i.e. 67h or 103 equal to the value you gave the editbox. What happens is as I described it earlier. As a test exchange the messagebox call with "invoke MessageBeep,0FFFFFFFFh and the problem set and kill focus will end.
Regards
This is a solution:
Regards
.if(message==WM_COMMAND)
mov eax,wParam
mov edx,eax
shr edx,16
and eax,0FFFFh
.if(ax==102)
invoke GetDlgItemTextA,handle,101,offset name_buffer,10h
invoke lstrcat,offset name_buffer,offset const_string
.elseif(ax==103)
.if edx==EN_SETFOCUS
invoke GetDlgItem,handle,102
invoke SetFocus,eax
invoke MessageBox,NULL,NULL,NULL,NULL
.endif
.endif
.elseif(message==WM_CLOSE)
Regards
bluffer,
i tried giving the msg box the handle but it was popping up two message boxes so i made it null and it started giving 25 msg boxes
minor28 is correct. You can expect to get two messages from your EDITTEXT control. One is 01000000=EN_SETFOCUS and the other is 0200000=EN_KILLFOCUS. It is working just like it is supposed to. How you process those messages is up to you. Ratchevlncrn8,
What are you thinking of anyway?? AX==102 works because 102 is in the lower 16 bits of EAX. EAX==102 will never work because the upper 16 bits contain notification codes. So if EAX=01000102, then EAX=102 will ALWAYS fail to match. Ratch
mov eax,wParam
.if(ax==102)
again, use EAX not just ax.
ie:
mov eax,wParam
.if(eax==102)
What are you thinking of anyway?? AX==102 works because 102 is in the lower 16 bits of EAX. EAX==102 will never work because the upper 16 bits contain notification codes. So if EAX=01000102, then EAX=102 will ALWAYS fail to match. Ratch
evlncrn8,
mov eax,wParam
.if(ax==102)
again, use EAX not just ax.
ie:
mov eax,wParam
.if(eax==102)
What are you thinking of anyway?? AX==102 works because 102 is in the lower 16 bits of EAX. EAX==102 will never work because the upper 16 bits contain notification codes. So if EAX=01000102, then EAX=102 will ALWAYS fail to match. Ratch
exactly, so the messagebox wont appear, which i think i said earlier because eax will never be 0102 simply because it isnt a button, i still cant figure out why he wanted to put a msgbox in the program either heh
mov eax,wParam
mov edx,eax
shr edx,16 <------ stripping the lo word
and eax,0FFFFh <----- stripping the hi word
thanks a lot minor28 that explains it pretty well
.if edx==EN_SETFOCUS
invoke GetDlgItem,handle,102
invoke SetFocus,eax
is this necessary or can i skip it
and
if i skip it will i still have focus to the edit
Why don't you try and see what happens.
If you skip these three lines your code will catch all messages sent from the editbox and the messagebox will popup for each message.
If you skip the two later lines the focus on editbox is lost when the messagebox appears and set when messagebox hides thus the EN_SETFOCUS will call the messagebox again.
You have to handle all editbox messages. Fling open the editcontrol messages from API reference and compete the code with
.if edx==EN_SETFOCUS
.elseif edx==EN_....
.endif
and see what happens.
Regards
If you skip these three lines your code will catch all messages sent from the editbox and the messagebox will popup for each message.
If you skip the two later lines the focus on editbox is lost when the messagebox appears and set when messagebox hides thus the EN_SETFOCUS will call the messagebox again.
You have to handle all editbox messages. Fling open the editcontrol messages from API reference and compete the code with
.if edx==EN_SETFOCUS
.elseif edx==EN_....
.endif
and see what happens.
Regards
evlncrn8,
exactly, so the messagebox wont appear, which i think i said earlier because eax will never be 0102 simply because it isnt a button, i still cant figure out why he wanted to put a msgbox in the program either heh
I believe he did not want the MB to appear multiple times. With your suggestion, he might just as well not have any code at all. That would certainly keep the MB from appearing. I would not attempt to second guess why he wants the MB, only that he wants it to appear on his terms. Ratchbluffer,
May I suggest the following code.
The MOVZX EAX,DX takes 3 bytes vs. 6 bytes for AND EAX,0777H. Ratch
mov eax,wParam
mov edx,eax
shr edx,16 <------ stripping the lo word
and eax,0FFFFh <----- stripping the hi word
May I suggest the following code.
MOV EDX,[wParam]
MOVZX EAX,DX
SHR EDX,16
The MOVZX EAX,DX takes 3 bytes vs. 6 bytes for AND EAX,0777H. Ratch
only that he wants it to appear on his terms. Ratch
ya i like that statement i really wanted to know why this happens and not how to eliminate it
if i had wanted to remove it from appearing i could have removed the msg box
i could have removed the .if(ax==103) or any other way that seems fit
any way now EN_SETFOCUS
The EN_SETFOCUS notification message is sent when an edit control receives the keyboard focus. The parent window of the edit control receives this notification message through the WM_COMMAND message.
EN_SETFOCUS
idEditCtrl = (int) LOWORD(wParam); // identifier of edit control
wNotifyCode = HIWORD(wParam); // notification code
hwndEditCtrl = (HWND) lParam; // handle of edit control
since the parent recieves it throug WM_COMMAND and i handle it it means i have to handle this also and take appropriate action else it will do what it deems fit
thanks very much for the shorter code ratch and minor28 for clarifying it