;The problem is that the value of a variable is not passed to the bitblt api and the
;bitmap is not printed in the window!!!

--- BEGIN CODE ---

.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\gdi32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\gdi32.lib

WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
Mov_Man proto :DWORD

.data
ClassName db "SimpleWinClass",0
AppName db "Our First Window",0
Bmp0 db "Man0",0
char WPARAM 20h

LEFT equ 0
RIGHT equ 1
UP equ 2
DOWN equ 3

.data?
hInstance HINSTANCE ?
CommandLine LPSTR ?
DevCon HDC ?
MemDc HDC ?
Hbmp HDC ?
PlayerPosX dw ? ; <---- This are the variables that causes the problem
PlayerPosY dw ? ; <---- (read below)


.code
start:
invoke GetModuleHandle, NULL
mov hInstance,eax
invoke GetCommandLine
mov CommandLine,eax
invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
invoke ExitProcess,eax

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:HWND
mov wc.cbSize,SIZEOF WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra,NULL
mov wc.cbWndExtra,NULL
push hInstance
pop wc.hInstance
mov wc.hbrBackground,COLOR_WINDOW+1
mov wc.lpszMenuName,NULL
mov 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

invoke GetDC,hwnd
mov DevCon, eax

invoke LoadBitmap,hInstance,addr Bmp0
mov Hbmp, eax
invoke CreateCompatibleDC,DevCon
mov MemDc,eax
invoke SelectObject,MemDc,Hbmp

.WHILE TRUE
invoke GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.ENDW
mov eax,msg.wParam
ret
WinMain endp

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

.IF uMsg==WM_DESTROY
invoke PostQuitMessage,NULL
.ELSEIF uMsg==WM_KEYDOWN
push wParam
pop char

.IF char == 025h
invoke Mov_Man, LEFT
.elseif char == 026h
invoke Mov_Man, UP
.elseif char == 027h
invoke Mov_Man, RIGHT
.elseif char == 028h
invoke Mov_Man, DOWN
.endif

.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
xor eax,eax
ret
WndProc endp

Mov_Man proc Dir:DWORD

.if Dir == LEFT
sub PlayerPosX, 3
.elseif Dir == RIGHT
add PlayerPosX, 3
.elseif Dir == UP
sub PlayerPosY, 3
.elseif Dir == DOWN
add PlayerPosY, 3
.endif

.if PlayerPosX < 0
mov PlayerPosX, 0
.endif

.if PlayerPosY < 0
mov PlayerPosY, 0
.endif

;Here is the problem: the value of PlayerPosX and PlayerPosY is not passed to the
;api and the bitmap is not printed to the window

invoke BitBlt,DevCon,PlayerPosX,PlayerPosY,900,900,MemDc,0,0,SRCCOPY

;but when i pass a direct value to the api (like 10) it print well to the screen.Like this:

invoke BitBlt,DevCon,10,10,900,900,MemDc,0,0,SRCCOPY

;why is this?

ret
Mov_Man endp

end start

--- END CODE ---:
Posted on 2002-08-12 11:24:56 by IrOn
just a thought,

try to initialize the playerposx and playerposy

PlayerPosX dw 0

maybe when you call bitblt the values are out of range
Posted on 2002-08-12 12:16:08 by Terab

PlayerPosX dw ? ; <---- This are the variables that causes the problem
PlayerPosY dw ? ; <---- (read below)


IrOn, API calls usually expect DWORD parameters. What you have declared here are however WORDs. I guess that changing "dw" to "dd" will solve the problem (not tested).
Posted on 2002-08-12 12:22:19 by Frank



IrOn, API calls usually expect DWORD parameters. What you have declared here are however WORDs. I guess that changing "dw" to "dd" will solve the problem (not tested).



i would assume that the high word is undefined, hence it not showing in screen area

actually the invoke pushes onto the stack, the function pops off what it needs, but you've pushed 2 words too few
so problems
Posted on 2002-08-12 13:27:59 by Terab
Thanks for the help, i will test "dd".

IrOn:alright:
Posted on 2002-08-12 21:52:32 by IrOn