关机的消息是:WM_QUERYENDSESSION
WM_QUERYENDSESSION 
nSource = (UINT) wParam;    // source of end-session request 
fLogOff = lParam            // logoff flag 
 
Parameters
nSource 
Reserved for future use. 
fLogOff 
Value of lParam. Indicates whether the user is logging off or shutting down the system. Supported values include: ENDSESSION_LOGOFF. 
Return Values
If an application can terminate conveniently, it should return TRUE; otherwise, it should return FALSE.