C++ WIN32控制台异常关闭回调函数
2024-10-04 01:08:41
/*
This is an example of the SetConsoleCtrlHandler function that is used to install a control handler. When a CTRL+C signal is received, the control handler returns TRUE, indicating that it has handled the signal. Doing this prevents other control handlers from being called. When a CTRL_CLOSE_EVENT signal is received, the control handler returns TRUE, causing the system to display a dialog box that gives the user the choice of terminating the process and closing the console or allowing the process to continue execution. If the user chooses not to terminate the process, the system closes the console when the process finally terminates. When a CTRL+BREAK, CTRL_LOGOFF_EVENT, or CTRL_SHUTDOWN_EVENT signal is received, the control handler returns FALSE. Doing this causes the signal to be passed to the next control handler function. If no other control handlers have been registered or none of the registered handlers returns TRUE, the default handler will be used, resulting in the process being terminated. Note that MyErrorExit is a placeholder for an application-defined function to display and handle error conditions.*/ BOOL CtrlHandler(DWORD fdwCtrlType)
{
switch (fdwCtrlType)
{
// Handle the CTRL+C signal. case CTRL_C_EVENT: Beep(, );
return TRUE; // CTRL+CLOSE: confirm that the user wants to exit. case CTRL_CLOSE_EVENT: return TRUE; // Pass other signals to the next handler. case CTRL_BREAK_EVENT: case CTRL_LOGOFF_EVENT: case CTRL_SHUTDOWN_EVENT: default: return FALSE;
}
} void main(void)
{
BOOL fSuccess; fSuccess = SetConsoleCtrlHandler(
(PHANDLER_ROUTINE) CtrlHandler, // handler function
TRUE); // add to list
if (! fSuccess)
MyErrorExit("Could not set control handler");
}
最新文章
- centos网卡eth1变成eth0修改方法
- android 读中文文本文件
- Android 查看内存
- C# RAS 非对称加密类 支持长字符串
- Fragment与Activity交互(使用接口)
- SQL设置时间格式
- ROS 小乌龟测试
- [Vuex] Create a Vuex Store using TypeScript
- Asp.net core 学习笔记 2.1 升级到 2.2
- ABAP 在被访问的程序中获取访问程序的全局变量
- Codeforces 977F - Consecutive Subsequence - [map优化DP]
- 每日linux命令学习-grep模式检索
- Code Signal_练习题_Knapsack Light
- HTTPS-HTTPS原理
- [控件] ChangeColorLabel
- 理解JavaScript私有作用域
- oninput事件(解决onkeyup无法监听到复制黏贴)
- 37.ROUND() 函数
- 2019.03.19 ZJOI2019模拟赛 解题报告
- circusctl命令在ubuntu 上执行,卡住的现象处理。