你在程序中直接响应
WM_QUERYENDSESSION
LRESULT CturnOffDetectorDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
if (WM_QUERYENDSESSION == message) // 关机,注销;怎样区分查看msdn WM_QUERYENDSESSION
{
AfxMessageBox(_T("...."));
return FALSE; //阻止
}
return CDialog::WindowProc(message, wParam, lParam);
}
但是如果某个程序通过 ExitWindowsEx(EWX_POWEROFF|EWX_FORCE,0);的方式强制关机,系统就不会发出WM_QUERYENDSESSION消息,当然也就拦截不倒了~