MessageBoxでは、いいえを選択した場合シャットダウンを中止させたいのですが...。
#include <stdio.h>
#include <windows.h>
#include <thread>
#include <iostream>
using namespace std;
BOOL WINAPI controlHandler(DWORD type)
{
if (CTRL_C_EVENT == type) {
cout << "Ctrl+C" << endl;
Sleep(30000);
}
if (CTRL_CLOSE_EVENT == type) {
cout << "CLOSE" << endl;
Sleep(30000);
}
if (CTRL_LOGOFF_EVENT == type) {
cout << "LOGOFF" << endl;
Sleep(30000);
}
if (CTRL_SHUTDOWN_EVENT == type) {
cout << "SHUTDOWN" << endl;
HWND hwnd = GetConsoleWindow();
MessageBox(hwnd,"シャットダウンしますか?","",MB_OKCANCEL);
system("shutdown /a");
Sleep(30000);
}
return TRUE;
}
int main()
{
printf("main[%d] start\n", GetCurrentProcessId());
if (!SetConsoleCtrlHandler(controlHandler, TRUE)) {
printf("SetConsoleCtrlHandler");
return -1;
}
for (;;);
printf("main[%d] end\n", GetCurrentProcessId());
return 0;
}