截获系统注销时候的消息

使用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); }

支持原创技术分享,据说打赏我的人,都找到了女朋友!