当前位置:网站首页>MFC 定时器使用
MFC 定时器使用
2022-07-02 11:41:00 【sam-zy】
1.通过类向导在对话框基类中添加 OnTimer子类

2.1.绑定事件响应
BEGIN_MESSAGE_MAP(TcpClientDlg, CDialogEx)
//其它绑定事件响应
ON_WM_TIMER()
END_MESSAGE_MAP()
2.2…h文件
afx_msg void OnTimer(UINT_PTR nIDEvent);
3.对话框初始化函数
// CRzhChatClientDlg 消息处理程序
BOOL TcpClientDlg::OnInitDialog()
{
SetTimer(1, 1000, NULL); //定时器的ID,间隔时间(毫秒为单位的)
SetTimer(2, 5000, NULL);
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
}
4.事件响应
void TcpClientDlg::OnTimer(UINT_PTR nIDEvent)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
switch (nIDEvent)
{
case 1: //1号定时器应该处理的事情
AppendLog(TEXT("Timer1"));
break;
case 2: //2号定时器应该处理的事情
AppendLog(TEXT("Timer2"));
break;
default:
break;
}
__super::OnTimer(nIDEvent);
}
5.运行结果

6.销毁定时器
KillTimer(1);//销毁定时器1
6.1.销毁定时器示例
int i = 0;
void TcpClientDlg::OnTimer(UINT_PTR nIDEvent)
{
switch (nIDEvent)
{
case 1: //1号定时器应该处理的事情
AppendLog(TEXT("Timer1"));
i++;
break;
case 2: //2号定时器应该处理的事情
AppendLog(TEXT("Timer2"));
break;
default:
break;
}
if (i == 5)
{
KillTimer(1);//销毁定时器1
}
__super::OnTimer(nIDEvent);
}
边栏推荐
- MQ教程 | Exchange(交换机)
- threejs的控制器 立方體空間 基本控制器+慣性控制+飛行控制
- 复用和分用
- PTA题库 ===>复数四则运算,一帮一,考试座位号(7-73)
- 使用mathtype编辑公式,复制粘贴时设置成仅包含mathjax语法的公式
- Fabric. JS free draw circle
- qml 弹窗框架,可定制
- fatal: unsafe repository is owned by someone else 的解决方法
- LeetCode_滑动窗口_中等_395.至少有 K 个重复字符的最长子串
- Tmall product details interface (APP, H5 end)
猜你喜欢

Fabric.js 橡皮擦的用法(包含恢复功能)

mathjax 入门(web显示数学公式,矢量的)

There is no solution to the decryption error of the remote user 'sa' and the service master password mapped from the remote server 'to the local user' (null) /sa '

YoloV6训练:训练自己数据集遇到的各种问题

Chinese science and technology from the Winter Olympics (III): the awakening and evolution of digital people

【空间&单细胞组学】第1期:单细胞结合空间转录组研究PDAC肿瘤微环境

Actual combat sharing of shutter screen acquisition

Obsidian installs third-party plug-ins - unable to load plug-ins

Makefile separates file names and suffixes

buuctf-pwn write-ups (7)
随机推荐
【空间&单细胞组学】第1期:单细胞结合空间转录组研究PDAC肿瘤微环境
Large top heap, small top heap and heap sequencing
Full of knowledge points, how to use JMeter to generate encrypted data and write it to the database? Don't collect it quickly
Socket and socket address
为什么只会编程的程序员无法成为优秀的开发者?
Wechat applet uses towxml to display formula
[Space & single cellomics] phase 1: single cell binding space transcriptome research PDAC tumor microenvironment
Quick analysis: easy to share the Internet
STM32标准固件库函数名(一)
NLA natural language analysis makes data analysis more intelligent
MQ教程 | Exchange(交换机)
NLA natural language analysis realizes zero threshold of data analysis
threejs的控制器 立方體空間 基本控制器+慣性控制+飛行控制
富文本编辑器添加矢量公式(MathType for TinyMCE ,可视化添加)
mathML转latex
Fabric.js 自由绘制圆形
2、const 型指针
LeetCode 2310. 个位数字为 K 的整数之和
There is no solution to the decryption error of the remote user 'sa' and the service master password mapped from the remote server 'to the local user' (null) /sa '
socket(套接字)与socket地址