前面学习了win32汇编定时器,还非常不熟悉,继续熟悉,稍微增加一点功能;
.386
.model flat,stdcall
option casemap:none
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
ID_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 proc
ret
_ProcTimer endp
_ProcDlgMain proc uses ebx edi esi,hWnd,uMsg,wParam,lParam
mov eax,uMsg
.if eax == WM_TIMER
mov eax,wParam
.if eax == ID_TIMER1
inc [count]
invoke wsprintf,addr szbuf,addr fmt1,count
invoke SetDlgItemText,hWinMain,IDC_INFO,addr szbuf
.endif
.elseif eax == WM_INITDIALOG
push hWnd
pop hWinMain
invoke SetTimer,hWnd,ID_TIMER1,1000,NULL
invoke SetTimer,NULL,NULL,1000,addr _ProcTimer
mov idTimer,eax
.elseif eax == WM_CLOSE
invoke KillTimer,hWnd,ID_TIMER1
invoke EndDialog,hWnd,NULL
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
_ProcDlgMain endp
start:
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke DialogBoxParam,hInstance,DLG_MAIN,NULL,offset _ProcDlgMain,NULL
invoke ExitProcess,NULL
end 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];