定时器示例:
#include <tchar.h>

// The caption of our message box
TCHAR g_szCaption[] = TEXT("Timed Message Box");


// How many seconds we'll display the message box
int g_nSecLeft = 0;


// This is STATIC window control ID for a message box
#define ID_MSGBOX_STATIC_TEXT 0x0000ffff
//控件得值為即xFFFF

VOID WINAPI MsgBoxTimeout(PVOID pvContext, BOOLEAN fTimeout)


{
// NOTE: Due to a thread race condition, it is possible (but very unlikely)
// that the message box will not be created when we get here.
HWND hwnd = FindWindow(NULL, g_szCaption);

if (hwnd != NULL)

{
// The window does exist; update the time remaining.
TCHAR sz[100];
wsprintf(sz, TEXT("You have %d seconds to respond"), g_nSecLeft--);
SetDlgItemText(hwnd, ID_MSGBOX_STATIC_TEXT, sz);

if (g_nSecLeft == 0)

{
// The time is up; force the message box to exit.
EndDialog(hwnd, IDOK);
}
}
else

{
// The window does not exist yet; do nothing this time.
// We'll try again in another second.
}
}

int WINAPI _tWinMain(HINSTANCE hinstExe, HINSTANCE, PTSTR pszCmdLine, int)


{

chWindows9xNotAllowed();

// How many seconds we'll give the user to respond
g_nSecLeft = 10;

// Create a multishot 1 second timer that begins firing after 1 second.
HANDLE hTimerQTimer;
CreateTimerQueueTimer(&hTimerQTimer, NULL, MsgBoxTimeout, NULL, 1000, 1000, 0);

// Display the message box
MessageBox(NULL, TEXT("You have 10 seconds to respond"), g_szCaption, MB_OK);

// Cancel the timer & delete the timer queue
DeleteTimerQueueTimer(NULL, hTimerQTimer, NULL);

// Let us know if the user responded or if we timed-out.
MessageBox(NULL, (g_nSecLeft == 0) ? TEXT("Timeout") : TEXT("User responded"), TEXT("Result"), MB_OK);

return(0);
}


【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· [AI/GPT/综述] AI Agent的设计模式综述
2007-06-09 一个小问题
2007-06-09 整合ActiveMQ和JBoss
2006-06-09 [转]最长递增子序列问题的求解
2006-06-09 TOJ_1003题解