你在程序中直接响应 WM_QUERYENDSESSIONLRESULT 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消息,当然也就拦截不倒了~
System Shutdown Messages The following messages are used with system shutdown. WM_ENDSESSION WM_QUERYENDSESSION WM_QUERYENDSESSION: LPARAM lParam,If this parameter includes the ENDSESSION_LOGOFF value, the user if logging off.
WM_QUERYENDSESSIONLRESULT 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消息,当然也就拦截不倒了~
The following messages are used with system shutdown.
WM_ENDSESSION
WM_QUERYENDSESSION
WM_QUERYENDSESSION:
LPARAM lParam,If this parameter includes the ENDSESSION_LOGOFF value, the user if logging off.
根据消息进行操作
如果突然掉电,肯定会再开机的,
强行按Power键,那是自己找死拉。。