i am studying Win32Asm ,i have read the tutorial about child window controls that icezelion wrote.i have one question about the codes he wrote.
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.IF uMsg==WM_DESTROY
invoke PostQuitMessage,NULL
.ELSEIF uMsg==WM_CREATE
invoke CreateWindowEx,WS_EX_CLIENTEDGE, ADDR EditClassName,NULL,\
WS_CHILD or WS_VISIBLE or WS_BORDER or ES_LEFT or\
ES_AUTOHSCROLL,\
50,35,200,25,hWnd,8,hInstance,NULL
mov hwndEdit,eax
invoke SetFocus, hwndEdit
invoke CreateWindowEx,NULL, ADDR ButtonClassName,ADDR ButtonText,\
WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON,\
75,70,140,25,hWnd,ButtonID,hInstance,NULL
mov hwndButton,eax
.ELSEIF uMsg==WM_COMMAND
mov eax,wParam
.IF lParam==0
.IF ax==IDM_HELLO
invoke SetWindowText,hwndEdit,ADDR TestString
.ELSEIF ax==IDM_CLEAR
invoke SetWindowText,hwndEdit,NULL
.ELSEIF ax==IDM_GETTEXT
invoke GetWindowText,hwndEdit,ADDR buffer,512
invoke MessageBox,NULL,ADDR buffer,ADDR AppName,MB_OK
.ELSE
invoke DestroyWindow,hWnd
.ENDIF
.ELSE
.IF ax==ButtonID
shr eax,16
.IF ax==BN_CLICKED
invoke SendMessage,hWnd,WM_COMMAND,IDM_GETTEXT,0
.ENDIF
.ENDIF
.ENDIF
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
xor eax,eax
ret
WndProc endp
Who can tell me, what does the "mov hwndButton,eax " make sense? i deleted this code,and the program run correctly as i did it before.
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.IF uMsg==WM_DESTROY
invoke PostQuitMessage,NULL
.ELSEIF uMsg==WM_CREATE
invoke CreateWindowEx,WS_EX_CLIENTEDGE, ADDR EditClassName,NULL,\
WS_CHILD or WS_VISIBLE or WS_BORDER or ES_LEFT or\
ES_AUTOHSCROLL,\
50,35,200,25,hWnd,8,hInstance,NULL
mov hwndEdit,eax
invoke SetFocus, hwndEdit
invoke CreateWindowEx,NULL, ADDR ButtonClassName,ADDR ButtonText,\
WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON,\
75,70,140,25,hWnd,ButtonID,hInstance,NULL
mov hwndButton,eax
.ELSEIF uMsg==WM_COMMAND
mov eax,wParam
.IF lParam==0
.IF ax==IDM_HELLO
invoke SetWindowText,hwndEdit,ADDR TestString
.ELSEIF ax==IDM_CLEAR
invoke SetWindowText,hwndEdit,NULL
.ELSEIF ax==IDM_GETTEXT
invoke GetWindowText,hwndEdit,ADDR buffer,512
invoke MessageBox,NULL,ADDR buffer,ADDR AppName,MB_OK
.ELSE
invoke DestroyWindow,hWnd
.ENDIF
.ELSE
.IF ax==ButtonID
shr eax,16
.IF ax==BN_CLICKED
invoke SendMessage,hWnd,WM_COMMAND,IDM_GETTEXT,0
.ENDIF
.ENDIF
.ENDIF
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
xor eax,eax
ret
WndProc endp
Who can tell me, what does the "mov hwndButton,eax " make sense? i deleted this code,and the program run correctly as i did it before.
If you don't use that handle, then it's useless.
Doesn't hurt saving it though :)
It hurts the performance XD :lol:
I'm guessing Abuseyourdna doesn't understand what the hwndButton variable is. So real quick, CreateWindowEx returns
a "handle" when it's called. Return values are, as far as you should be conserned right now, always returned in the EAX
register. That example stores the handle by moving data from EAX and copying it into hwndButton. The reason this is
done is for later reference to the child window (control). Say for example, you wish to hide the button later on in your
program. This can be done by inserting:
invoke ShowWindow,hwndButton,SW_HIDE
This keeps you from having to call GetDlgItem each time you want to reference the control's handle. In that example,
you will notice there is nothing else using hwndButton. So if you remove it, it doesn't hurt the execution of the program,
only decreases the size of the executable by about 4 bytes.
Regards,
Bryant Keller
a "handle" when it's called. Return values are, as far as you should be conserned right now, always returned in the EAX
register. That example stores the handle by moving data from EAX and copying it into hwndButton. The reason this is
done is for later reference to the child window (control). Say for example, you wish to hide the button later on in your
program. This can be done by inserting:
invoke ShowWindow,hwndButton,SW_HIDE
This keeps you from having to call GetDlgItem each time you want to reference the control's handle. In that example,
you will notice there is nothing else using hwndButton. So if you remove it, it doesn't hurt the execution of the program,
only decreases the size of the executable by about 4 bytes.
Regards,
Bryant Keller
only decreases the size of the executable by about 4 bytes.
Actually it decreases the code block's size by 4 bytes, which will decrease executable's size in VERY RARE occassions ;) Something like [100/BLOCK_ALIGNMENT] % chance for that, if I'm not wrong (it's 5:43AM already :P ).
Good Night :)
thx for all your help.