用WM_QUERYENDSESSION.
在你的主框架窗口类中使用.
// in the class header
afx_msg BOOL OnQueryEndSession( WPARAM wReserved, LPARAM lEndReason );
// in the Message Map
ON_MESSAGE( WM_QUERYENDSESSION, OnQueryEndSession )
// in the class body
BOOL CMainFrame::OnQueryEndSession( WPARAM wReserved, LPARAM lEndReason )
{
if( lEndReason =3D=3D ENDSESSION_LOGOFF ) {
// user is logging off
else
// Windows is going down
return( bCanExit );
}