老妖网上的:
DWORD g_main_tid = 0;
HHOOK g_kb_hook = 0;
bool CALLBACK con_handler (DWORD)
{
PostThreadMessage (g_main_tid, WM_QUIT, 0, 0);
// 本文转自 C++Builder 研究 - http://www.ccrun.com/article.asp?i=984&d=es23f6
return TRUE;
};
int main (void)
{
g_main_tid = GetCurrentThreadId ();
SetConsoleCtrlHandler ((PHANDLER_ROUTINE)&con_handler, TRUE);
MSG msg;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
};
return 0;
}
DWORD g_main_tid = 0;
HHOOK g_kb_hook = 0;
bool CALLBACK con_handler (DWORD)
{
PostThreadMessage (g_main_tid, WM_QUIT, 0, 0);
// 本文转自 C++Builder 研究 - http://www.ccrun.com/article.asp?i=984&d=es23f6
return TRUE;
};
int main (void)
{
g_main_tid = GetCurrentThreadId ();
SetConsoleCtrlHandler ((PHANDLER_ROUTINE)&con_handler, TRUE);
MSG msg;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
};
return 0;
}
本示例展示了一个使用 C++ 编写的简单控制台应用程序,该程序通过设置控制台处理函数来响应控制台关闭事件。程序还展示了如何获取当前线程ID并发送退出消息。
2848

被折叠的 条评论
为什么被折叠?



