/*
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");
}

C++ WIN32控制台异常关闭回调函数的更多相关文章

  1. VS中子对话框的关闭回调函数

    新建了QDialog的子类时,如果需要回调它的关闭函数 1.加入头文件#include <QCloseEvent> 2.重写函数 protected: void closeEvent(QC ...

  2. 从Win32程序中的主函数中获取命令行参数

    在标准C或者Win32控制台程序的main函数中,它们都有两个参数:"argc" 和 "argv",如下所示: int main(int argc, char ...

  3. register_shutdown_function函数详解--脚本退出时执行回调函数

    register_shutdown_function — Register a function for execution on shutdown. ps:Registers a callback  ...

  4. PHP的异常处理、错误的抛出及错误回调函数

    一.错误.异常和等级常量表 error:不能再编译期发现运行期的错误,不如试图echo输出一个未赋值的变量,这类问题往往导致程序或逻辑无法继续下去而需要中断. exception:程序执行过程中出现意 ...

  5. nodejs中处理回调函数的异常

    如果是使用nodejs+express3这个经典的组合,那么有一种很方面的处理回调函数异常的方法: 1. 安装模块:express-domain-middleware 2. 加入如下的代码: app. ...

  6. 微信小程序开发——使用回调函数出现异常:TypeError: Cannot read property 'setData' of undefined

    关键技术点: 作用域问题——回调函数中的作用域已经脱离了调用函数了,因此需要在回调函数外边把this赋给一个新的变量才可以了. 业务需求: 微信小程序开发,业务逻辑需要,需要把获取手机号码的业务逻辑作 ...

  7. win32的回调函数

    [转]http://blog.csdn.net/w419675647/article/details/6599070 众所周知,win32的回调函数WndProc()是操作系统调用的函数,win32用 ...

  8. 【XLL 文档翻译】【第2部分】C API 回调函数 Excel4, Excel12

    Excel4 和 Excel12 函数使得 DLL 可以调用 Excel 工作表函数.宏表函数.命令.XLL特定函数或命令.最近的一些 Excel 版本都支持 Excel12 函数.这两个函数支持下面 ...

  9. Javascript异步编程之二回调函数

    上一节讲异步原理的时候基本上把回掉函数也捎带讲了一些,这节主要举几个例子来具体化一下.在开始之前,首先要明白一件事,在javascript里函数可以作为参数进行传递,这里涉及到高阶函数的概念,大家可以 ...

随机推荐

  1. arcgis desktop按ctrl键后地图乱移的解决办法

    习惯使用快捷键的,经常会按下ctrl. 但在arcmap中,按下ctrl后,地图乱移.分析发现变为鼠标导航状态,也就是鼠标偏离地图中心,地图就会往鼠标所在方向移动. 解决办法:1. 以前按下esc键, ...

  2. SWFTools参数

    CMD: d:\SWFTools>pdf2swf -o c:\2.swf -s flashversion=9 -s languagedir=c:\xpdf\xpdf-cinese-simplif ...

  3. Android文件系统的结构

    Android 4.2.2 版本的文件系统 内核版本为 3.0.31 版本号为JDQ39 factory//估计是存放网络通信协议的登录密钥的|-- bluetooth|-- hdcp.keys|-- ...

  4. PS 制作复印件及盖章效果

    对要处理的部分选定  1.执行 滤镜--杂色--添加杂色 2.执行 滤镜--模糊--高斯模糊 3.ctrl+L 执行 色阶 调整为 满意的效果  4.最后添加想要的颜色 图像--调整--渐变映射 关键 ...

  5. 【软件工程】用map 实现把英语文本文件词和个数打印出来

    #include <iostream> #include <fstream> #include <string> #include <map> usin ...

  6. [Swift]基础

    [Swift]基础 一, 常用变量 var str = "Hello, playground" //变量 let str1="Hello xmj112288" ...

  7. ubuntu 12.04禁用笔记本触摸板

    习惯了在Macbook Pro上使用触摸板,装了个linux 的dualboot,发现,ubuntu下对触摸板的支持实在是太烂了,想禁用触摸板却找不到设置的地方. 终于最后发现了——touchpad- ...

  8. R语言--数据预处理

    一.日期时间.字符串的处理 日期 Date: 日期类,年与日 POSIXct: 日期时间类,精确到秒,用数字表示 POSIXlt: 日期时间类,精确到秒,用列表表示 Sys.date(), date( ...

  9. 缺jstl.jar包导致的代码出现异常

    java.lang.ClassNotFoundException: javax.servlet.jsp.jstl.core.Config 看报错中的红色部分,意思是缺类异常,再看后面蓝色粗体倾斜部分, ...

  10. php 继承

    说多重继承之前首先说下与其相对的单一继承,单一继承指的是一个类只可以继承自一个父类,从现实生活中举例就是说一个儿子只有一个父亲.那么多重继承就好理解了,多重继承指的是一个类可以同时从多于一个父类继承行 ...