|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
定时器的使用.ASM
=========================================
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.386
.model flat, stdcall
option casemap :none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Include 文件定义
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Equ 等值定义
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
ICO_MAIN equ 1 ;图标
DLG_MAIN equ 2000h ;对话框资源
IDC_INT equ 100
IDT_TESE2 equ 202
IDT_TESE3 equ 203
ICO_TIME1 equ 301
ICO_TIME2 equ 302
ICO_FOR1 equ 401
ICO_FOR2 equ 402
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 数据段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data?
hInstance dd ?
WinMain dd ?
Test1 dd ?
ITime1 dd ?
ITime2 dd ?
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 代码段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.code
TIME_TEST1 proc
pushad
invoke GetDlgItemInt,WinMain,IDC_INT,NULL,FALSE
inc eax
invoke SetDlgItemInt,WinMain,IDC_INT,eax,FALSE
popad
ret
TIME_TEST1 endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_ProcDlgMain proc uses ebx edi esi hWnd,wMsg,wParam,lParam
mov eax,wMsg
.if eax == WM_CLOSE ;关闭对话框窗口所作操作
invoke EndDialog,hWnd,NULL ;结束对话框窗口
invoke KillTimer,hWnd,Test1
invoke KillTimer,hWnd,Test1
invoke KillTimer,hWnd,Test1
.elseif eax == WM_INITDIALOG ;在对话框窗口还没有显现出来就处理的消息
push hWnd
pop WinMain
invoke LoadIcon,hInstance,ICO_MAIN ;载入图标返回句柄
invoke SendMessage,hWnd,WM_SETICON,ICON_BIG,eax ;发送消息到对话框过程来设置菜单图标
invoke LoadIcon,hInstance,ICO_TIME1
mov ITime1,eax
invoke LoadIcon,hInstance,ICO_TIME2
mov ITime2,eax
invoke SetTimer,NULL,NULL,1000,TIME_TEST1
mov Test1,eax
invoke SetTimer,hWnd,IDT_TESE2,500,NULL
invoke SetTimer,hWnd,IDT_TESE3,2000,NULL
;hWnd :发送消息的窗口
;nIDEvent :如果参数hWnd不为NULL,则指定一个非零定时器时间标识符
;uElapse :指定定时器事件之间的时间间隔(以微秒计算)
;lpTimeerFunc :表示定时器事件发生后接收消息的函数的过程实例地址
; :如果参数lpTimerFunc为NULL,则将WM_TIMER消息放入应用程序队列中
; :并把调用函数SetTimer时的参数hWnd放入结构MSG的hWnd
.elseif eax == WM_TIMER
mov eax,wParam ;wParam存储了菜单命令
.if eax == IDT_TESE2
mov eax,ITime1 ; a=x c语言原理,汇编变了下小小的思路
xchg eax,ITime2 ; x=y
mov ITime1,eax ; y=a
invoke SendDlgItemMessage,hWnd,ICO_FOR1,STM_SETIMAGE,IMAGE_ICON,ITime1
invoke SendDlgItemMessage,hWnd,ICO_FOR2,STM_SETIMAGE,IMAGE_ICON,ITime2
.elseif eax == IDT_TESE3
invoke MessageBeep,MB_ICONASTERISK
.endif
.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 ;创建模态对话框
;函数从hInstance模块装载DLG_MAIN的资源
;父窗口就是本身,对话框过程是_ProcDlgMain
;dwInitParam是当做WM_INITDIALOG消息的lParam传给对话框过程,用来自定义消息
invoke ExitProcess,NULL
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
end start
定时器的使用.RC
==============================================
#include <resource.h>
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#define ICO_MAIN 1 //图标
#define DLG_MAIN 0x2000 //对话框
#define IDC_INT 100
#define ICO_TIME1 301
#define ICO_TIME2 302
#define ICO_FOR1 401
#define ICO_FOR2 402
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
ICO_MAIN ICON "Main.ico" //图标文件
ICO_TIME1 ICON "ICO1.ico"
ICO_TIME2 ICON "ICO2.ico"
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
DLG_MAIN DIALOG 250,150,230,59 //对话框资源定义:X坐标,Y坐标,宽度,高度
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU//风格定义
CAPTION "定时器的使用" //定义显示在窗口标题栏上的文字
FONT 8, "微软雅黑" //定义对话框包括子窗口控件使用的字体和大小
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
BEGIN
ICON ICO_TIME1, ICO_FOR1, 162,12,17,17
ICON ICO_TIME2, ICO_FOR2, 195,12,17,17
CTEXT "定时器介绍:\n【1】:数字每秒变动累加1\n 【2】:图标每0.5秒变动一次\n 【3】:提示音每2秒响动一次", -1, 6,9,100,36
GROUPBOX "",-1,4,3,144,51
GROUPBOX "",-1,147,3,80,51
CTEXT "循环次数:",-1,158,34,40,9
CTEXT "0",IDC_INT,195,34,26,8
END
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//WS_POPUP :弹出式窗口
//WS_VISIBLE :初始状态可见
//WS_SYSMENU :创建一个在其标题条中具有系统菜单框的窗口,仅适用于带标题条的窗口
//DS_MODALFRAME :指定带模式对话框边界的对话框,此风格和WS_CAPTION、WS_SYSMENU风格一起,创建带标题条和系统菜单的对话框
//WS_CAPTION :创建一个有标题的窗口,包含了WS_BORDER,不能和WS_DLGFRAME一起使用
//WS_BORDER :创建一个有边框的窗口
//WS_DLGFRAME :创建一个带有双层边框但没有标题的窗口
//CONTROL 文本, ID, 类, 风格, X, Y, 宽度, 高度 [,扩展风格]
//invoke CreateWindow, 类名, 文本, 风格, X, Y, 宽度, 高度, 对话框窗口句柄, ID, hInstance, NULL
//控件名称 [文本,] ID,X,Y,宽度,高度[,风格][,扩展风格]
//类介绍 :按钮(Button)、静态(Static)、编辑(Edit)、滚动条(ScrollBar)、列表框(ListBox)、组合框(ComboBox)
|
|