前面学习了win32汇编定时器,还非常不熟悉,继续熟悉,稍微增加一点功能;
.386.model flat,stdcalloption casemap:noneinclude windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.libID_TIMER1 equ 1
ICO_1 equ 102
DLG_MAIN equ 1
IDC_INFO equ 101.data
count dd 0
szbuf db 100 dup(0).data?
hInstance dd ?
hWinMain dd ?
idTimer dd ?.const
fmt1 db ' %d ',0dh,0ah,0.code
; 定时器过程
_ProcTimer procret
_ProcTimer endp_ProcDlgMain proc uses ebx edi esi,hWnd,uMsg,wParam,lParammov eax,uMsg.if eax == WM_TIMERmov eax,wParam.if eax == ID_TIMER1inc [count]invoke wsprintf,addr szbuf,addr fmt1,count invoke SetDlgItemText,hWinMain,IDC_INFO,addr szbuf.endif.elseif eax == WM_INITDIALOGpush hWndpop hWinMaininvoke SetTimer,hWnd,ID_TIMER1,1000,NULLinvoke SetTimer,NULL,NULL,1000,addr _ProcTimermov idTimer,eax.elseif eax == WM_CLOSEinvoke KillTimer,hWnd,ID_TIMER1invoke EndDialog,hWnd,NULL.elsemov eax,FALSEret.endifmov eax,TRUEret
_ProcDlgMain endpstart:invoke GetModuleHandle,NULLmov hInstance,eaxinvoke DialogBoxParam,hInstance,DLG_MAIN,NULL,offset _ProcDlgMain,NULLinvoke ExitProcess,NULLend start
首先要定义定时器的id, 和句柄hWinMain这些定义在一起;
在主对话框过程中处理WM_TIMER消息,和WM_INITDIALOG消息的处理是在不同的分支;
收到WM_TIMER消息时,eax中是定时器的id;
然后之前学习过,资源文件里像这样的写法,
ICON ICO_1, -1, 00, 10, 25, 25
指定图标的位置和大小,前面加了个-1,这使对话框自己加载图标,不用LoadIcon;
定义一个dd类型变量count,每次定时器间隔到,加1,赋值给静态文本框;
count定义在.data段,count加1写为 inc [count];