Learning with GoAsm -> Iczelion tutorial problem

Started by Citric, January 17, 2005, 10:23:19 AM

Previous topic - Next topic

Citric

Hi
i am running through Icezelion's tutorials and buidling them on top of each other but now something weird is happening and i can't firgure it out.
The 'char' printed out is removed if i click on the screen and only the y setting of the mouse click, seems to be set.

Please have a look a the code below, and help me with my problem.

The include file

#IFDEF UNICODE
   #include "D:\GoAsm\IncludeW\WINDOWS.inc"
   #include "D:\GoAsm\IncludeW\all_api.inc"
#ELSE
   #include "D:\GoAsm\IncludeA\WINDOWS.inc"
   #include "D:\GoAsm\IncludeA\all_api.inc"
#ENDIF

#define RGB(%red,%green,%blue) = xor eax,eax \
mov ah,%blue \
shl eax,8 \
mov ah,%green \
mov al,%red


The Main program.

#include "tutorial.inc"

DATA SECTION
ALIGN 4
ClassName db "SimpleWinClass",0
AppName  db "Our First Window",0
OurText  db "Big Message",0
FontName db "script",0
mouseClickMessage db "I was here",0
mouseClick db FALSE ; No mouse click yet.
char WPARAM 20h                         ; the character the program receives from keyboard

hInstance dd ?
CommandLine dd ?
hitPoint POINT <>

CODE SECTION
start:
invoke GetModuleHandle, NULL
mov    [hInstance],eax
invoke GetCommandLine
mov    [CommandLine],eax
invoke WinMain, [hInstance], NULL, [CommandLine], SW_SHOWDEFAULT
invoke ExitProcess, eax

WinMain FRAME hInst, hPrevInst, CmdLine, CmdShow
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd

mov   D[wc.cbSize], SIZEOF WNDCLASSEX
mov   D[wc.style], CS_HREDRAW or CS_VREDRAW
mov   D[wc.lpfnWndProc], OFFSET WndProc
mov   D[wc.cbClsExtra], NULL
mov   D[wc.cbWndExtra], NULL
push  [hInstance]
pop   [wc.hInstance]
mov   D[wc.hbrBackground], COLOR_WINDOW+1
mov   D[wc.lpszMenuName], NULL
mov   D[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_OVERLAPPEDWINDOW,CW_USEDEFAULT,\
           CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,\
           [hInst],NULL
mov   [hwnd], eax
invoke ShowWindow, [hwnd], SW_SHOWNORMAL
invoke UpdateWindow, [hwnd]
.msg_loop
invoke GetMessage, ADDR msg, NULL, 0, 0
cmp eax,0
je >.exit
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
jmp <.msg_loop
.exit
mov     eax,[msg.wParam]
ret
WinMain ENDF

WndProc FRAME hWnd, uMsg, wParam, lParam
    USES EBP,EBX,EDI,ESI
    LOCAL hdc
    LOCAL ps:PAINTSTRUCT
    LOCAL rect:RECT
    LOCAL hfont
   
.wmPaint ; Paint
    cmp D[uMsg],WM_PAINT
    jnz LONG >.wmChar
   
        invoke BeginPaint,[hWnd],ADDR ps
        mov [hdc],eax

        invoke GetClientRect,[hWnd],ADDR rect
        invoke DrawText, [hdc],ADDR OurText,-1, ADDR rect,\
                DT_SINGLELINE or DT_CENTER or DT_VCENTER

        invoke CreateFont,24,16,0,0,400,0,0,0,OEM_CHARSET,\
                                       OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,\
                                       DEFAULT_QUALITY,DEFAULT_PITCH or FF_SCRIPT,\
                                       ADDR FontName

invoke SelectObject,[hdc],eax
        mov [hfont],eax
        RGB(255,0,0)
        invoke SetTextColor,[hdc],eax
        RGB(0,0,255)
        invoke SetBkColor,[hdc],eax
        invoke TextOut,[hdc],0,0,ADDR OurText,SIZEOF OurText ; output "Big Message"
        invoke SelectObject,[hdc],[hfont]


        RGB(0,0,0)
        invoke SetTextColor,[hdc],eax
        RGB(255,255,255)
        invoke SetBkColor,[hdc],eax
invoke TextOut,[hdc],0,150,ADDR char,1 ; Output the 'char' set by WM_CHAR

cmp D[mouseClick],TRUE
jnz >.notClicked
invoke lstrlen,ADDR mouseClickMessage
invoke TextOut,[hdc],[hitPoint.x],[hitPoint.y],ADDR mouseClickMessage,eax ; " Output 'I was here' at the
  ;position the mouse was clicked
.notClicked

        invoke EndPaint,[hWnd],ADDR ps
        jmp LONG >.exit

.wmChar ; If we get the WM_CHAR message, set the character hit to 'char'
cmp D[uMsg],WM_CHAR
jnz >.wmLButtonDown

push [wParam]
pop [char]
invoke InvalidateRect,[hWnd],NULL,TRUE
jmp >.exit

.wmLButtonDown ; If we get a LBUTTON_DOWN, set the hitpoint to the position clicked.
cmp D[uMsg],WM_LBUTTONDOWN
jnz >.wmDestroy

mov eax,[lParam]
and eax,0FFFFh
mov D[hitPoint.x],eax
mov eax,[lParam]
shr eax,16
mov D[hitPoint.y],eax
mov D[mouseClick],TRUE
invoke InvalidateRect,[hWnd],NULL,TRUE
jmp >.exit

.wmDestroy ; Destroy the Window and go home.
cmp D[uMsg],WM_DESTROY
jnz >.DefWindowProc
invoke PostQuitMessage, NULL
jmp >.exit
.DefWindowProc
invoke DefWindowProc, [hWnd], [uMsg], [wParam], [lParam]
ret
.exit
xor eax,eax
ret
WndProc ENDF


And the Bat file to compile it.

GoAsm %1.asm
GoLink %1.obj kernel32.dll user32.dll gdi32.dll


Any help will be appreciated.

Thanks Adam

donkey

Hi,

You have defined mouseClick as a BYTE sized buffer (db FALSE) while you are moving a DWORD sized number into it in wmLButtonDown...

mov D[mouseClick],TRUE

This is overwriting the hitPoint.x buffer and setting it to 0. Just define the mouseClick flag as a DD and it should be fine.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Citric