Hi guys. I have been reading these boards for awhile now and trying to teach myself assembly, but I am having trouble gettiing anything to work correctly.I am trying to write a program wich will display some text on the screen DC and then erase it a few milliseconds later. I have tried using several different timers and several methods to erase the data (Invalidate region and bit blit). I think that my problem is in flow control. But Im really not skilled enough to figure it out.I have rewritten this simple program probably 15 times.I have tried coding in a window I dont need just to get an hWnd for my timers. I have tried several forms of jumps. I just don't get what i'm doing wrong.Please Help!The following is my code as it stands now.

.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



.data
OurText db "Hey!Im on the Top!Yeah!",0
Display db "DISPLAY",0
timefun1 dd
timefun2 dd

.data?
hInstance HINSTANCE ?
CommandLine LPSTR ?
hWnd HWND ?
myhdc dd ?
msg DWORD ?
tid1 DWORD ?
tid2 DWORD ?
memDC dd ?
bitmap DWORD ?
count byte ?

.code
invoke GetModuleHandle, NULL
mov hInstance,eax
invoke GetCommandLine
invoke ExitProcess,eax

start:
;mov timefun1,
;mov timefun2,
invoke CreateDC, addr Display, NULL, NULL, NULL
mov myhdc, eax
invoke CreateCompatibleDC, NULL
mov memDC, eax
invoke CreateCompatibleBitmap, myhdc, 175, 20
mov bitmap, eax
invoke SelectObject, memDC,
invoke SetTimer, NULL, 1, 3000, timefun1
mov tid1, eax



myloop:
invoke GetMessage,ADDR msg,NULL,0,0 ; get each message
cmp eax, 0 ; exit if GetMessage()
je Exit ; returns zero
invoke TranslateMessage, ADDR msg ; translate it
invoke DispatchMessage, ADDR msg ; send it to message proc
jmp myloop


timer1:
invoke BitBlt, memDC, 0, 0, 175, 20, myhdc, 0 ,0, SRCCOPY
invoke SetBkMode, myhdc,TRANSPARENT
invoke ExtTextOut, myhdc, 0, 0, NULL, NULL, ADDR OurText, SIZEOF OurText, NULL
invoke SetTimer, NULL, 1, 300, timefun2
mov tid2, eax
invoke KillTimer, NULL, tid1

jmp myloop

timer2:
invoke BitBlt, myhdc, 0, 0, 175, 20, memDC, 0, 0, SRCCOPY
invoke SetTimer, NULL, 1, 3000, timefun1
mov tid1, eax
invoke KillTimer, NULL, tid2
jmp myloop



Exit:
invoke ExitProcess,0
end start

Thanks in Advance,
Emonk
Posted on 2001-10-24 10:43:53 by emonk
I'm not sure what your saying the problem is. If your saying you can't get the text to output to the screen then i suggest you read iczelions tutorial on "painting with text"

And by the way timer messages are very low priority in windows and i have had problems using them myself.

sorry i cant help you more but if you read the "painting with text tutorial you will probably see whats going wrong

unless of course its the timer thats not working

LOOK AT THIS:

invoke BitBlt, memDC, 0, 0, 175, 20, myhdc, 0 ,0, SRCCOPY

i just noticed the above line in your seems to be wrong.
shouldn't memdDC and myhdc be in opposite places

good luck
:alright:
Posted on 2001-10-24 12:31:02 by titan
Thanks for the fast response. I dont think my problem is the timer, or the painting. The text paints fine (and I did learn for Icz's tut:), and "timer2:" does get triggered. I guess maybe my problem is in the bitblit somewhere?It doesn't want to blit for me for some reason. I tried swapping the bitBlit's in the way suggested, it made no difference to the output.
Posted on 2001-10-24 15:14:55 by emonk
Try to change:
timefun1 dd
timefun2 dd

to:
timefun1 dd offset timer1
timefun2 dd offset timer2

and:
timer1:
invoke BitBlt, memDC, 0, 0, 175, 20, myhdc, 0 ,0, SRCCOPY
invoke SetBkMode, myhdc,TRANSPARENT
invoke ExtTextOut, myhdc, 0, 0, NULL, NULL, ADDR OurText, SIZEOF OurText, NULL
invoke SetTimer, NULL, 1, 300, timefun2
mov tid2, eax
invoke KillTimer, NULL, tid1

to:
timer1 proc hwnd:dword, uMsg:dword, idEvent:dword, dwTime:dword
invoke BitBlt, memDC, 0, 0, 175, 20, myhdc, 0 ,0, SRCCOPY
invoke SetBkMode, myhdc,TRANSPARENT
invoke ExtTextOut, myhdc, 0, 0, NULL, NULL, ADDR OurText, SIZEOF OurText, NULL
invoke SetTimer, NULL, 1, 300, timefun2
mov tid2, eax
invoke KillTimer, NULL, tid1
ret
timer1 endp

Make same changes to timer2
Posted on 2001-10-24 19:11:03 by Aaro
possible problems in your code are:

1. msg is defined as dword, but should be of type MSG
2. your timer procs should not jump to label "myloop" but execute a ret (and they should be defined with some parameters, look in the Win32 docs)

japheth
Posted on 2001-10-25 06:51:41 by japheth
Thanks all, I will give these suggestions a try and let you know!:tongue:
Posted on 2001-10-25 07:51:50 by emonk
Aaro-
I made the changes you suggested, it compiles fine and everything but my bitblits still wont work.

Japeth- How do I define msg as being of the MSG type?I tried putting
msg MSG ?
in my .data? section and it gives me compile error A2008 syntax error: In Structure.

Any other ideas guys?
Posted on 2001-10-25 10:51:56 by emonk
code

msg MSG <>
Posted on 2001-10-25 11:00:04 by japheth
After making the suggested change with msg my program will compile but it just runs for a second and then quits. None of the timer events even fire!Here is my revised code incase anyone can help.
.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



.data
OurText db "Hey!Im on the Top!Yeah!",0
Display db "DISPLAY",0
timefun1 dd offset timer1
timefun2 dd offset timer2

.data?
hInstance HINSTANCE ?
CommandLine LPSTR ?
hWnd HWND ?
myhdc dd ?
tid1 DWORD ?
tid2 DWORD ?
memDC dd ?
bitmap DWORD ?
count byte ?

.code
msg MSG <>
invoke GetModuleHandle, NULL
mov hInstance,eax
invoke GetCommandLine
invoke ExitProcess,eax

start:
invoke CreateDC, addr Display, NULL, NULL, NULL
mov myhdc, eax
invoke CreateCompatibleDC, NULL
mov memDC, eax
invoke CreateCompatibleBitmap, myhdc, 175, 20
mov bitmap, eax
invoke SelectObject, memDC,
invoke SetTimer, NULL, 1, 3000, timefun1
mov tid1, eax



myloop:
invoke GetMessage,ADDR msg,NULL,0,0 ; get each message
cmp eax, 0 ; exit if GetMessage()
je Exit ; returns zero
invoke TranslateMessage, ADDR msg ; translate it
invoke DispatchMessage, ADDR msg ; send it to message proc
jmp myloop


timer1 proc hwnd:dword, uMsg:dword, idEvent:dword, dwTime:dword
invoke BitBlt, memDC, 0, 0, 175, 20, myhdc, 0 ,0, SRCCOPY
invoke SetBkMode, myhdc,TRANSPARENT
invoke ExtTextOut, myhdc, 0, 0, NULL, NULL, ADDR OurText, SIZEOF OurText, NULL
invoke SetTimer, NULL, 1, 300, timefun2
mov tid2, eax
invoke KillTimer, NULL, tid1
invoke MessageBox, NULL, NULL, NULL, MB_OK ; I placed this here to see if my timer fired
ret
timer1 endp

timer2 proc hwnd:dword, uMsg:dword, idEvent:dword, dwTime:dword
invoke BitBlt, myhdc, 0, 0, 175, 20, memDC, 0, 0, SRCCOPY
invoke SetTimer, NULL, 1, 3000, timefun1
mov tid1, eax
invoke KillTimer, NULL, tid2
invoke MessageBox, NULL, NULL, NULL, MB_OK ; I placed this here to see if my timer fired
ret
timer2 endp


Exit:
invoke ExitProcess,0
end start

END

I know this must be annoying to those of you who know what your doing, but im getting so discouraged I might give assembly up.Please Help before I go crazy!
Posted on 2001-10-25 11:58:33 by emonk
MSG <> should be in .data? not .code

cheers
Random
Posted on 2001-10-25 13:07:12 by random
Oops! I Misunderstood Japeth.Now I feel stoopid! But its a good stoopid because now my crappy program works. Yeah! Thanks guys, I really appreciate everyones help!
Posted on 2001-10-25 13:12:21 by emonk
hi


i did few changes in code ( very little )
. well the two timers are working ok .. i dont know about the graphic .didnt check it(yet). but the timers works



bye

eko


p.s

i think becuase you dont have a window you dont see what you draw. .

instead of ;"invoke CreateDC, NULL, NULL, NULL, NULL "
i did
push NULL
call GetDC
then you will c your text in the left corner of the screen .

and be ware not to get flood from the msgbox ;]
Posted on 2001-10-25 13:17:48 by eko