停止程序关闭CTRL_CLOSE_EVENT C ++

时间:2013-11-25 16:44:49

标签: c++ visual-studio-2010 visual-studio console-application

我正在尝试使用SetConsoleCtrlHandler函数,但它不能像我想要的那样工作,我想在我按下X时停止程序关闭,但我不知道如何完全覆盖CTRL_CLOSE_EVENT:

#include <myHead.h> //selfmade header

BOOL WINAPI HandlerRoutine(DWORD dwCtrlType){
    switch(dwCtrlType)
    {
    case CTRL_CLOSE_EVENT:
        {
            cout << "Closing...";
            getch();                    //should wait for a character after calling the CLOSE_EVENT
            return true;
        }
    default:
            return false;
    }
}

int main()
{
    SetConsoleCtrlHandler(HandlerRoutine,true);
    getch();
    return 0;
}

0 个答案:

没有答案