1. /*
  2. This is an example of the SetConsoleCtrlHandler function that is used to install a control handler.
  3.  
  4. 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.
  5.  
  6. 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.
  7.  
  8. 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.
  9.  
  10. Note that MyErrorExit is a placeholder for an application-defined function to display and handle error conditions.*/
  11.  
  12. BOOL CtrlHandler(DWORD fdwCtrlType)
  13. {
  14. switch (fdwCtrlType)
  15. {
  16. // Handle the CTRL+C signal.
  17.  
  18. case CTRL_C_EVENT:
  19.  
  20. Beep(, );
  21. return TRUE;
  22.  
  23. // CTRL+CLOSE: confirm that the user wants to exit.
  24.  
  25. case CTRL_CLOSE_EVENT:
  26.  
  27. return TRUE;
  28.  
  29. // Pass other signals to the next handler.
  30.  
  31. case CTRL_BREAK_EVENT:
  32.  
  33. case CTRL_LOGOFF_EVENT:
  34.  
  35. case CTRL_SHUTDOWN_EVENT:
  36.  
  37. default:
  38.  
  39. return FALSE;
  40. }
  41. }
  42.  
  43. void main(void)
  44. {
  45. BOOL fSuccess;
  46.  
  47. fSuccess = SetConsoleCtrlHandler(
  48. (PHANDLER_ROUTINE) CtrlHandler, // handler function
  49. TRUE); // add to list
  50. if (! fSuccess)
  51. MyErrorExit("Could not set control handler");
  52. }

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. 各种音视频编解码学习详解 h264 ,mpeg4 ,aac 等所有音视频格式

    编解码学习笔记(一):基本概念 媒体业务是网络的主要业务之间.尤其移动互联网业务的兴起,在运营商和应用开发商中,媒体业务份量极重,其中媒体的编解码服务涉及需求分析.应用开发.释放 license收费等 ...

  2. [转载] Android逃逸技术汇编

    本文转载自: http://blogs.360.cn/360mobile/2016/10/24/android_escape/ 摘    要 传统逃逸技术涉及网络攻防和病毒分析两大领域,网络攻防领域涉 ...

  3. NLPP-02-Exercises

    <PYTHON自然语言处理>第2章 内容简介:各种文本语料库. 古腾堡项目 www.gutenberg.org OLAC元数据格式档 http://www.language-archive ...

  4. java1.7集合源码阅读:LinkedList

    先看看类定义: public class LinkedList<E> extends AbstractSequentialList<E> implements List< ...

  5. jQuery Mobile 过渡效果

    jQuery Mobile 包含了允许您选择页面打开方式的 CSS 效果. jQuery Mobile 过渡效果 jQuery Mobile 拥有一系列关于如何从一页过渡到下一页的效果. 注释:如需实 ...

  6. 评估Divide and Conquer算法时间复杂度的几种策略

    算法导论的第四章对于divide-conquer进行了阐述, 感觉这本书特别在,实际给出的例子并不多,更多其实是一些偏向数学性质的分析, 最重要的是告诉你该类算法分析的一般性策略. 估计 首先是估计算 ...

  7. Android编译环境搭建(0818-0819)

    1 在虚拟机VMware上安装64位Ubuntu14.04LTS 首先需要安装虚拟机并激活.然后新建虚拟机,选择使用下载好的Ubuntu镜像.注意需要将光驱改为自己下载的,而不是autoinst.is ...

  8. jquery星级评论打分组件

    <!DOCTYPE HTML><html> <head> <meta charset="utf-8"><title>jq ...

  9. 团队项目作业:利用NABCD模型进行竞争性需求分析

    NABC正是这样的一套框架,当你试图提出一项崭新的提案之际,它能够提供四个思维基点,令你的商业策划具备天马行空的基础. 具体来说,NABC是四个关键词的首字母缩写- Need(需求)-现在市场上未被满 ...

  10. Odoo10尝鲜:出勤登记

    非常的cool,使用一个 联网的PAD 就能使用超级潮的 出勤登记功能     扫描 工牌条码,或者 从员工目录选择 员工, 例如 输入 PIN 密码, 防止"代打卡"       ...