我正在尝试使用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;
}