当前位置:网站首页>MFC timer usage
MFC timer usage
2022-07-02 14:56:00 【sam-zy】
1. Add... In the dialog box base class through the class wizard OnTimer Subclass
2.1. Bind event response
BEGIN_MESSAGE_MAP(TcpClientDlg, CDialogEx)
// Other binding event responses
ON_WM_TIMER()
END_MESSAGE_MAP()
2.2…h file
afx_msg void OnTimer(UINT_PTR nIDEvent);
3. Dialog initialization function
// CRzhChatClientDlg Message handler
BOOL TcpClientDlg::OnInitDialog()
{
SetTimer(1, 1000, NULL); // Timer ID, Time interval between ( In milliseconds )
SetTimer(2, 5000, NULL);
return TRUE; // Unless you set the focus to the control , Otherwise return to TRUE
}
4. Event response
void TcpClientDlg::OnTimer(UINT_PTR nIDEvent)
{
// TODO: Add message handler code and / Or call the default value
switch (nIDEvent)
{
case 1: //1 What timer No. 1 should deal with
AppendLog(TEXT("Timer1"));
break;
case 2: //2 What timer No. 1 should deal with
AppendLog(TEXT("Timer2"));
break;
default:
break;
}
__super::OnTimer(nIDEvent);
}
5. Running results
6. Destroy timer
KillTimer(1);// Destroy timer 1
6.1. Destroy timer example
int i = 0;
void TcpClientDlg::OnTimer(UINT_PTR nIDEvent)
{
switch (nIDEvent)
{
case 1: //1 What timer No. 1 should deal with
AppendLog(TEXT("Timer1"));
i++;
break;
case 2: //2 What timer No. 1 should deal with
AppendLog(TEXT("Timer2"));
break;
default:
break;
}
if (i == 5)
{
KillTimer(1);// Destroy timer 1
}
__super::OnTimer(nIDEvent);
}
边栏推荐
- A white hole formed by antineutrons produced by particle accelerators
- info [email protected] : The platform “win32“ is incompatible with this module.
- 检查密码
- Contrôleur pour threejs cube Space Basic Controller + Inertial Control + Flight Control
- socket(套接字)与socket地址
- Ad20 cannot select the solution of component packaging in PCB editor
- 用户隐私协议有些汉字编码不规范导致网页显示乱码,需要统一找出来处理一下
- 【NOI模拟赛】伊莉斯elis(贪心,模拟)
- 2、const 型指针
- 871. 最低加油次数 : 简单优先队列(堆)贪心题
猜你喜欢
Advanced C language (learn malloc & calloc & realloc & free in simple dynamic memory management)
[untitled] leetcode 2321 Maximum score of concatenated array
About text selection in web pages and counting the length of selected text
MQ教程 | Exchange(交换机)
fatal: unsafe repository is owned by someone else 的解决方法
复用和分用
Makefile separates file names and suffixes
JMeter script parameterization
Makefile 分隔文件名与后缀
实现一个多进程并发的服务器
随机推荐
Thoroughly master prototype__ proto__、 Relationship before constructor (JS prototype, prototype chain)
LeetCode 2310. 个位数字为 K 的整数之和
C# richTextBox控制显示最大行数
socket(套接字)与socket地址
LeetCode 209. 长度最小的子数组
Makefile separates file names and suffixes
Fabric.js 元素被选中时保持原有层级
Ad20 cannot select the solution of component packaging in PCB editor
Error: NPM warn config global ` --global`, `--local` are deprecated Use `--location=global` instead.
Fabric.js 自由绘制椭圆
buuctf-pwn write-ups (7)
C语言习题---(数组)
Advanced C language (realize simple address book)
C#代码审计实战+前置知识
obsidian安装第三方插件——无法加载插件
Delete element (with transition animation)
Xilinx Vivado set *. svh as SystemVerilog Header
geoserver离线地图服务搭建和图层发布
PTA题库 ===>复数四则运算,一帮一,考试座位号(7-73)
OpenCV调用USB摄像头的点滴