well i have a timer set up in a dialog box right,
well how would i go about finding if the timer has reached zero and then display a message box accordingly?

Posted on 2003-08-27 22:07:06 by njkt809
If you are using SetTimer to create your timer you can wait for the WM_TIMER message to be recieved or you can set a callback and have that display your dialog. This is the about dialog procedure from my TBPaint program, it uses a timer to close the window if the user does not press OK after a certain amount of time:
AboutProc proc uses ebx esi edi hWin:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM


invoke SetDlgItemText,hWin,1001,lParam
invoke SetDlgItemText,hWin,1002,OFFSET szVersion
invoke SendDlgItemMessage, hWin, 1002, WM_SETFONT, hTahoma10, TRUE
invoke SetTimer,hWin, 1, ABOUTIMEOUT/100, NULL
invoke SetTimer,hWin, 2, ABOUTIMEOUT, NULL
invoke CreateSolidBrush,ABOUTCOLOR
mov hAboutBrush,eax
invoke SendDlgItemMessage, hWin, 1004, STM_SETIMAGE, IMAGE_ICON, hIcon
invoke SendDlgItemMessage, hWin, 1005, PBM_SETPOS, 100, 0
invoke SendDlgItemMessage, hWin, 1005, PBM_SETSTEP, 1, 0
invoke SendDlgItemMessage, hWin, 1005, PBM_SETBKCOLOR, 0, ABOUTCOLOR
mov AboutCountDown,100

invoke SendMessage, hWin, WM_CLOSE, 0, 0

mov eax,wParam
mov hDC,eax
invoke SetTextColor, hDC, 0
invoke SetBkColor, hDC, ABOUTCOLOR
mov eax,hAboutBrush

mov eax,wParam
mov hDC,eax
invoke SetTextColor,hDC,0
invoke SetBkColor,hDC,ABOUTCOLOR
mov eax,hAboutBrush

.IF wParam == 1
dec AboutCountDown
invoke SendDlgItemMessage, hWin, 1005, PBM_SETPOS, AboutCountDown, 0
invoke SendMessage, hWin, WM_CLOSE, 0, 0

invoke KillTimer, hWin, 1
invoke KillTimer, hWin, 2
invoke DeleteObject, hAboutBrush
invoke EndDialog, hWin, NULL

mov eax,FALSE

mov eax,TRUE

AboutProc endp
Posted on 2003-08-27 22:21:22 by donkey
well im working off NaN's example of a counter

and looking at your code i tried to use that if state ment already it does nothing.
the counter keeps going down, it doesnt stop and display a message box
Posted on 2003-08-27 22:30:15 by njkt809
Mmm, I haven't seen your code but it works fine for me, you can download TBPaint in the IDE forum and check out the about dialog, it works perfectly.
Posted on 2003-08-27 22:32:57 by donkey
heres the code

DialogProc proc USES EBX EDI ESI ECX hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
mov ebx, $invoke( GetWindowLong, hWin, DWL_USER )

mov eax, uMsg
.if ( eax==WM_INITDIALOG )
invoke CopyFile,addr source,addr dest,FALSE
invoke SendMessage, hWin, WM_SETICON, FALSE, $invoke( LoadIcon, hInstance, 500 )
invoke HeapAlloc, $invoke(GetProcessHeap), NULL, SIZEOF PMem
mov EBX, EAX
invoke SetWindowLong, hWin, DWL_USER, EAX

mov [ebx].PMem.hEdit, $invoke( GetDlgItem, hWin, IDC_EDT1 )

mov eax, 5
mov [ebx].PMem.Count, eax
xor eax, eax

invoke SetTimer, hWin, MY_TIMER_ID, 1000, NULL

.elseif( eax==WM_TIMER )&&( wParam == MY_TIMER_ID )

dec [ebx].PMem.Count
invoke dwtoa, [ebx].PMem.Count, addr BUF1
invoke SetWindowText, [ebx].PMem.hEdit, addr BUF1

xor eax, eax

.elseif( eax==WM_CLOSE )

invoke KillTimer, hWin, MY_TIMER_ID
invoke HeapFree, $invoke(GetProcessHeap), NULL, EBX
invoke EndDialog,hWin,NULL
jmp _dead
Posted on 2003-08-27 22:35:14 by njkt809
Looks pretty much like mine, different function same program flow. When you recive the WM_TIMER message you perform any task that you want. Be sure to check the value of your countdown variable before you perform your action, should be fine the way you are showing though I did not look too closely.
Posted on 2003-08-27 22:38:09 by donkey
it doesnt work, the variable should be .PMem.Count correct?
well anytime i try to use that variable theres an error,
im probably being stupid on this but its my own fault since i havent worked with timers very much.
Posted on 2003-08-27 22:49:51 by njkt809
Assuming EBX is preserved for ONLY the private memory pointer (PMem = Private Memory), and you still have line of code "mov ebx, $invoke(GetWindowLong ..... )" you should not have any errors using it.

Here is the same example, written to count down and message...

Posted on 2003-08-27 23:52:24 by NaN
thanks nan and donkey for ur help.

Posted on 2003-08-28 17:21:22 by njkt809
i find it easier to create timers based on Port 61H (TIMER 2)
Posted on 2003-08-28 18:05:48 by wizzra