#include "stdafx.h"
#include <Windows.h>

static BOOL WINAPI Handler(DWORD cntrlEvent);
static BOOL exitFlag = FALSE;

int _tmain(int argc, LPTSTR argv[])

/* Beep periodically until signaled to stop. */
{
        /* Add an event handler. */
    if (SetConsoleCtrlHandler(Handler, TRUE)==FALSE)
        printf("Unable to install handler!\n");
    
    while (!exitFlag) { /* This flag is detected right after a beep, before a handler exits */
        Sleep(4750); /* Beep every 5 seconds; allowing 250 ms of beep time. */
        Beep(1000 /* Frequency */, 250 /* Duration */);
    }
    _tprintf(_T("Stopping the main program as requested.\n"));
    return 0;
}

BOOL WINAPI Handler(DWORD cntrlEvent)
{
    switch (cntrlEvent) {
        /* The signal timing will determine if you see the second handler message */
        case CTRL_C_EVENT:
            _tprintf(_T("Ctrl-C received by handler. Leaving in 5 seconds or less.\n"));
            exitFlag = TRUE;
            Sleep(4000); /* Decrease this time to get a different effect */
            _tprintf(_T("Leaving handler in 1 second or less.\n"));
            return TRUE; /* TRUE indicates that the signal was handled. */
        case CTRL_CLOSE_EVENT:
            _tprintf(_T("Close event received by handler. Leaving the handler in 5 seconds or less.\n"));
            exitFlag = TRUE;
            Sleep(4000); /* Decrease this time to get a different effect */
            _tprintf(_T("Leaving handler in 1 second or less.\n"));
            return TRUE; /* Try returning FALSE. Any difference? */
        default:
            _tprintf(_T("Event: %d received by handler. Leaving in 5 seconds or less.\n"), cntrlEvent);
            exitFlag = TRUE;
            Sleep(4000); /* Decrease this time to get a different effect */
            _tprintf(_T("Leaving handler in 1 seconds or less.\n"));
            return TRUE; /* TRUE indicates that the signal was handled. */
    }
}

最新文章

  1. python中获取今天昨天和明天的日期
  2. CK-Editor content.replace
  3. jQuery Mobile学习之grid、等待显示的ajax效果、页面跳转、页面跳转传递参数等(二)
  4. Codeforces 617E XOR and Favorite Number(莫队算法)
  5. AOP 之 6.1 AOP基础(拾陆)
  6. 如何在linux中配置PHP环境
  7. 使用NPOI导出DataTable到Excel
  8. linux中的常用命令
  9. Break、continue、return用法(C++)
  10. OpenNebula openldap集成
  11. OutputDebugString输出调试信息到debugtrack
  12. 【Java】0X001.配置开发环境,JDK、classpath等
  13. centos 桌面没有有线设置,不能上网
  14. 通过类创建子线程&amp;同步锁
  15. Hibernate常用API以及使用说明
  16. 在notepad++中使用正则匹配功能(一-龥!-~) 中文[利刃篇]
  17. php苹果内购订单验证
  18. IE DIV背景透明,点击事件不响应解决方案
  19. android studio(AS) Duplicate files copied in APK META-INF/NOTICE.txt
  20. [luogu3942] 将军令

热门文章

  1. MapReduce-计数器
  2. Python之异常总结
  3. JMeter 3.0 POST Body Data 中文乱码问题
  4. Quartz实现定时任务实例
  5. 阿里云 linux 找回mysql root密码
  6. Windows环境下CGAL的安装
  7. docker安装---CentOS_7
  8. DOM的的概述
  9. 如何关闭 window10 自带的杀毒软件
  10. Windows7 如何关闭系统更新