当前位置:网站首页>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);
}
边栏推荐
- Method of creating linked server for cross server data access
- [apipost] tutorial
- 微信小程序使用towxml显示公式
- LeetCode_字符串_简单_412.Fizz Buzz
- taobao.trades.sold.get-查询卖家已卖出的交易数据(根据创建时间),淘宝店铺卖出订单查询API接口,淘宝R2接口,淘宝oAuth2.0交易接口代码分享
- NLA natural language analysis realizes zero threshold of data analysis
- Socket and socket address
- 大顶堆、小顶堆与堆排序
- 由粒子加速器产生的反中子形成的白洞
- 1、编辑利器vim
猜你喜欢

一张图彻底掌握prototype、__proto__、constructor之前的关系(JS原型、原型链)

STM32-DAC实验&高频DAC输出测试

Edit the formula with MathType, and set it to include only mathjax syntax when copying and pasting

什么是 eRDMA?丨科普漫画图解

< schéma de développement de la machine d'exercice oral > machine d'exercice oral / trésor d'exercice oral / trésor de mathématiques pour enfants / lecteur LCD de calculatrice pour enfants IC - vk1621

Yolov6 training: various problems encountered in training your dataset

Makefile separates file names and suffixes

提示:SQL Server 阻止了对组件‘Ad Hoc Distributed Queries ‘的STATEMENT ‘OpenRowset/OpenDatasource“”

Li Chuang EDA learning notes 15: draw border or import border (DXF file)

Fabric.js 上划线、中划线(删除线)、下划线
随机推荐
Find the maximum inscribed circle of the contour
PHP linked list creation and traversal
Fabric. JS free draw circle
实现一个多进程并发的服务器
mathjax 入门(web显示数学公式,矢量的)
【无标题】LeetCode 2321. 拼接数组的最大分数
【空间&单细胞组学】第1期:单细胞结合空间转录组研究PDAC肿瘤微环境
Stm32-dac Experiment & high frequency DAC output test
Design and implementation of car query system based on php+mysql
fatal: unsafe repository is owned by someone else 的解决方法
天猫商品详情接口(APP,H5端)
taobao.trades.sold.get-查询卖家已卖出的交易数据(根据创建时间),淘宝店铺卖出订单查询API接口,淘宝R2接口,淘宝oAuth2.0交易接口代码分享
Use of freemaker
篇9:XShell免费版安装
OpenCV调用USB摄像头的点滴
Large top heap, small top heap and heap sequencing
【NOI模拟赛】刮痧(动态规划)
复用和分用
tmall. product. schema. Get (product information acquisition schema acquisition), Taobao store upload commodity API interface, Taobao commodity publishing interface, Taobao commodity upload API interf
taobao. trades. sold. Get query the transaction data that the seller has sold (according to the creation time), Taobao store sales order query API interface, Taobao R2 interface, Taobao oauth2.0 trans