timer.asm
.386
.model flat,stdcall
option casemap:none
include windows.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
;equ 等值定义
IDD_DLG1 equ 1000
IDC_COUNT equ 1000
ID_TIMER1 equ 10001
ID_TIMER2 equ 10002
.data?
hInstance dd ?
hWinMain dd ?
idTimer dd ?
.code
ProTimer proc _hWnd,uMsg,_idEvent,_dwTime
pushad
invoke GetDlgItemInt,hWinMain,IDC_COUNT,NULL,FALSE
inc eax
invoke SetDlgItemInt,hWinMain,IDC_COUNT,eax,FALSE
popad
ret
ProTimer endp
ProDialogMain proc uses ebx esi edi,hWnd,uMsg,wParam,lParam
mov eax,uMsg
.if eax == WM_CLOSE
invoke KillTimer,hWnd,ID_TIMER1
invoke KillTimer,hWnd,ID_TIMER2
invoke EndDialog,hWnd,NULL
.elseif eax == WM_INITDIALOG
push hWnd
pop hWinMain
invoke SetTimer,hWnd,ID_TIMER1,1000,offset ProTimer
mov idTimer,eax
invoke SetTimer,hWnd,ID_TIMER2,2000,NULL
.elseif eax == WM_TIMER
mov eax,wParam
.if eax == ID_TIMER2
invoke MessageBeep,-1
.endif
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
ProDialogMain endp
start:
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke DialogBoxParam,hInstance,IDD_DLG1,NULL,offset ProDialogMain,NULL
invoke ExitProcess,NULL
end start
timer.rc
#define IDD_DLG1 1000
#define IDC_COUNT 1000
#include <resource.h>
IDD_DLG1 DIALOGEX 10,10,135,45
CAPTION "计时器"
FONT 8,"MS Sans Serif",0,0,0
STYLE 0x10CF0000
BEGIN
CONTROL "计数:",-1,"Static",0x50020000,35,16,25,10
CONTROL "",IDC_COUNT,"Static",0x50020000,62,16,37,11
END
编译命令:
ml /c /coff timer.asm
rc timer.rc
link /subsystem:windows timer.obj timer.res
环境:
masm32开发包 /windows系统