Hi! I'm writting a simple notepad clone in ASM but I'm having problem with main window and editbox. The main window:- invoke CreateWindowExA, WS_EX_ACCEPTFILES or WS_EX_APPWINDOW, \ ADDR ClassName, ADDR AppName,\ WS_OVERLAPPEDWINDOW or WS_VISIBLE, \ CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, \ NULL, NULL, hInstance, NULL mov hwnd,eax . . . . WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM LOCAL rect:RECT The editbox:- .IF uMsg==WM_DESTROY ; if the user closes our window invoke PostQuitMessage,NULL ; quit our application .ELSEIF uMsg==WM_CREATE INVOKE GetClientRect, hWnd, addr rect INVOKE CreateWindowExA, WS_EX_ACCEPTFILES or WS_EX_CLIENTEDGE, \ ADDR EditClassName, NULL, \ WS_CHILD or WS_VISIBLE or WS_HSCROLL or WS_VSCROLL or \ ES_MULTILINE or ES_AUTOHSCROLL or ES_AUTOVSCROLL, \ rect.left, rect.top, rect.right, rect.bottom, \ hWnd, NULL, hInstance, NULL MOV hwndEdit,eax INVOKE SetFocus, hwndEdit When I miximize the main window, the edit box remains much as same when the main window was in the normal form. How do I make edit box to take the size of the main window? i.e the edit box must occupy all the main window's client area. Thanks, e-nigma
When the main window is resized, Windows sends WM_SIZE to its window proc. You must process this message in order to resize the edit control properly. .elseif uMsg==WM_SIZE mov eax,lParam ; the low word of lParam contains mov edx,eax ; the width of the client area and and eax,0FFFFh ; the high word the height shr edx,16 invoke MoveWindow,hwndEdit,0,0,eax,edx,TRUE
COuld you break this code down for newbies please? .elseif uMsg==WM_SIZE mov eax,lParam ; the low word of lParam contains mov edx,eax ; the width of the client area and and eax,0FFFFh ; the high word the height shr edx,16 invoke MoveWindow,hwndEdit,0,0,eax,edx,TRUE What does the and eax, 0FFFFh and shr edx,16 lines do exactly? Sorry for this complete idiotic question but I am not sure what is going on in these lines. thank you
Hi, if I am not completely wrong (sorry, I am still learning the "old" assembler stuff) this is needed to split the values retrieved into the low word and the high word. This is because the coordinates are submitted in one buffer and you have to get them seperately. I met this "problem" some time before when I had to handle the mouse cursor position to get the x and the y value. I know this is not the best help but as I said, I try ;) Stefan
Oops... I forgot to check for WM_SIZE msg. Thanks. e-nigma
Hi Frank! look here, this might help you. http://www7.brinkster.com/hiroshimator/ShowMsg.asp?ThreadID=573&ForumID=2&PDays=45
Frank, the data in lParam is in fact two words rather than 1 dword (2x16bit rather than 1x32bit). So in order to separate the words Icz does the following: mov edx, eax ;Make edx a copy of eax, so eax = edx = lParam and eax, 0FFFFh ;Mask out the top 16bits of eax ;I assume you know binary logic :P shr edx, 16 ;Bit shift edx down by 16 bits ;shifts pack with 0s, so the top 16 bits are now shifted to ;the low word, and the top 16 are now 0 shifts work as follows: say al = 3 (0000 0011 binary) shl al, 2 ;Shift the register al 2 places left ;al now = 12 (0000 1100 binary) ; -- the two added 00s ;remember: ;When shifting the last bit to fall off is placed in carry ;so say al = 3 (0000 0011) shr al, 1 ;Shift RIGHT 1 place ;al = 1 (0000 0001), and CARRY flag is now set ;because a 1 fell off! Mirno
True, Iczelion did it that way, moving, shifting, whatever to get the word into memory but.... Think for a sec. There is a word value in memory. Can't assembly just move just that word? Sure it can. I thrashed this over with hutch (and a stream of messageboard comments with a VB-aphobe), we each have methods we each like. His is to define: ; --------------------------------------------------------- ; These 4 equates demonstrate a simple way of splitting ; the wParam and lParam passed to a WndProc into their ; WORD size components. They take the WORD value directly ; off the stack without any conversions. ; --------------------------------------------------------- wpLow equ
Then use them like so:
movsx edx, lpLow ; convert WORD to DWORD
movsx eax, lpHigh ; convert WORD to DWORD
While I prefer structures to do much the same. Define:
value DWORD ?
loword WORD ?
hiword WORD ?
Use this either or two ways.
1) define wParam and lParam in your WinProc as packedDW types
movsx eax, lParam.loword ; get the low word
movsx ebx, lParam.hiword ; get the high word
mov cbx, hParam.value ; get the whole word
Or define l & wParam as usual, and just cast them:
movsx eax, (packedDW PTR lParam).loword ; get the low word
movsx ebx, (packedDW PTR lParam).hiword ; get the high word
mov cbx, hParam ; get the whole word
Thanks guys for your great explanations. I am getting there. I am now taking the time to read through all of Icz's tuts. I am also reading Art of Assembly. Thanks for all your help!