使用WH_CALLWNDPROC类型钩子,回调函数如下:
LRESULT CALLBACK MyProc(int code, WPARAM wParam, LPARAM lParam) { switch (((CWPSTRUCT)lParam)->message) { case WM_QUERYENDSESSION: { switch( ((CWPSTRUCT)lParam)->lParam ) { case ENDSESSION_LOGOFF: { FILE pFile = NULL; ((CWPSTRUCT)lParam)->message = 0; AfxMessageBox(TEXT(“log off”)); return 0; } break; } } } return ::CallNextHookEx(g_hMessage, code, wParam, lParam); }