当前位置:网站首页>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);
}
边栏推荐
- 3、函数指针和指针函数
- Chapter 9: xshell free version installation
- Database connection pool and data source
- String matching problem
- buuctf-pwn write-ups (7)
- Simple verification code generator for 51 single chip microcomputer experiment
- The use of TestNG, the testing framework (II): the use of TestNG XML
- 【NOI模拟赛】刮痧(动态规划)
- qml 弹窗框架,可定制
- ONNX+TensorRT:将预处理操作写入ONNX并完成TRT部署
猜你喜欢

PHP linked list creation and traversal

fatal: unsafe repository is owned by someone else 的解决方法

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

Fabric.js 上划线、中划线(删除线)、下划线

复用和分用

The use of TestNG, the testing framework (II): the use of TestNG XML

为什么只会编程的程序员无法成为优秀的开发者?

Fundamentals of software testing

Fatal: unsafe repository is owned by someone else
[email protected] : The platform “win32“ is incompatible with this module."/>info [email protected] : The platform “win32“ is incompatible with this module.
随机推荐
It's no exaggeration to say that this is the most user-friendly basic tutorial of pytest I've ever seen
buuctf-pwn write-ups (7)
Convolutional neural network (Introduction)
threejs的控制器 立方体空间 基本控制器+惯性控制+飞行控制
Fabric. JS upper dash, middle dash (strikethrough), underline
taobao. trade. memo. Add (add remarks to a transaction) interface, Taobao store flag insertion interface, Taobao order flag insertion API interface, oauth2.0 interface
Large top heap, small top heap and heap sequencing
Yyds dry goods inventory software encryption lock function
Advanced usage of C language -- function pointer: callback function; Conversion table
taobao.trades.sold.get-查询卖家已卖出的交易数据(根据创建时间),淘宝店铺卖出订单查询API接口,淘宝R2接口,淘宝oAuth2.0交易接口代码分享
华为面试题: 没有回文串
Onnx+tensorrt: write preprocessing operations to onnx and complete TRT deployment
jmeter脚本参数化
Fabric.js 自由绘制椭圆
求轮廓最大内接圆
The use of TestNG, the testing framework (II): the use of TestNG XML
uniapp自动化测试学习
Xilinx Vivado set *. svh as SystemVerilog Header
NLA自然语言分析实现数据分析零门槛
Fabric. Keep the original level when JS element is selected