关闭

控制台屏蔽键盘消息事件

81人阅读 评论(0) 收藏 举报

BOOL __stdcall ConsoleHandler(DWORD dwEvent)
{
switch(dwEvent)
{
case CTRL_C_EVENT:
printf("CTRL+C received!");
break;
case CTRL_BREAK_EVENT:
printf("CTRL+BREAK received!");
break;
case CTRL_CLOSE_EVENT:
printf("Program being closed!");
break;
case CTRL_LOGOFF_EVENT:
printf("User is logging off!");
break;
case CTRL_SHUTDOWN_EVENT:
printf("User is logging off!");
break;
default:
break;
}
return TRUE;

}

int main(int argc, char* argv[])
{
if(SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleHandler, TRUE) == FALSE)
{
printf("设置控制台回调事件失败 \n");
::system("pause");
return 0;
}

while(true)

{

Sleep(100);

}

return 0;

}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场