Howdy all.  I'm a recent convert from TASM.  Wow, if only i had known. 

A question on lesson six, the keyboard tut.

What i'm trying to do is have the program read a keystroke, put it on the screen, advance the "paint point" one space and then wait for another keystroke, so in essense you could type a word rather than just one letter.  Here's where i screwed the proverbial pooch


.data?
xpos db ?


.....

WinMain endp
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL hdc:HDC
LOCAL ps:PAINTSTRUCT
        LOCAL hfont:HFONT
       
        push eax
        xor eax,eax                          ;;ZEROING OUT EAX
        mov add xpos,eax       ;;TRYING TO MOV 0 to xpos
      pop eax                                 
       
        .IF uMsg==WM_DESTROY
invoke PostQuitMessage,NULL
.ELSEIF uMsg==WM_CHAR
push wParam
pop  char
invoke InvalidateRect, hWnd,NULL,TRUE
.ELSEIF uMsg==WM_PAINT
invoke BeginPaint,hWnd, ADDR ps
mov    hdc,eax
invoke CreateFont,50,50,0,0,400,0,0,0,OEM_CHARSET,OUT_DEVICE_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,NULL
                mov hfont,eax
                invoke SelectObject,hdc,hfont
                invoke TextOut,hdc,300,addr xpos,ADDR char,1  ;trying to use the variable xpos to move the "cursor" one step ahead per letter typed
                push eax                      ;Store eax on the stack
                mov eax, addr xpos
                add eax,1                    ;add 1 to eax (xpos value)
                mov addr xpos, eax      ;store new value in xpos
                pop eax                    ;restore eax from the stack

invoke EndPaint,hWnd, ADDR ps
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
xor    eax,eax
ret
WndProc endp
end start


My problem is that it won't assemble.  Apparently eax can't be moved into xpos .  I've tried mov , eax and many variants and am coming up with bupkis.


Anyone have any suggestions?

LHE
Posted on 2005-09-24 17:06:48 by LordHighExecutioner
.data?
xpos dd ?
; TextOut requires a 32-bit variable, NOT an 8-bit one

.....

WinMain endp
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL hdc:HDC
LOCAL ps:PAINTSTRUCT
        LOCAL hfont:HFONT

       ; you should zero this variable in your winmain proc.
       
        .IF uMsg==WM_DESTROY
invoke PostQuitMessage,NULL
.ELSEIF uMsg==WM_CHAR
push wParam
pop  char
invoke InvalidateRect, hWnd,NULL,TRUE
.ELSEIF uMsg==WM_PAINT
invoke BeginPaint,hWnd, ADDR ps
mov    hdc,eax
invoke CreateFont,50,50,0,0,400,0,0,0,OEM_CHARSET,OUT_DEVICE_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,NULL
                mov hfont,eax
                invoke SelectObject,hdc,hfont
                invoke TextOut,hdc,300, xpos,ADDR char,1

                inc  xpos   ; this increases the argument (in this case: the 'xpos' variable)

invoke EndPaint,hWnd, ADDR ps
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
xor    eax,eax
ret
WndProc endp
end start


I would also like to note that this program is very 'unclean'. You should always free all resources you create/allocate.
Posted on 2005-09-24 18:39:33 by ti_mo_n
Thanks man.  I need  a little work.  But its definiatly moving the characters ahead (erasing the one behind, but i'll figure that out.  I think its the invalidate rec call.)

By unallocate, are you referring to the CreateFont, resource?  Should i release it before i exit?
Posted on 2005-09-24 19:26:22 by LordHighExecutioner
Yup. Call DeleteObject to free your font handle.
Posted on 2005-09-24 23:40:41 by roticv