帮忙看看这段代码 为什么进不去钩子回调函数??
程序代码:
#include <windows.h> #include <stdio.h> #pragma comment <lib, "User32.lib"> #include <winuser.h> WNDPROC g_orgProc; LRESULT CALLBACK NewWndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam) { switch(uMsg) { case WM_COMMAND: if ((wParam == 0x06) && (HIWORD(wParam) == BN_CLICKED) ) { /*Add your own procedure*/ return 0; } break; default: break; } return CallWindowProc(g_orgProc, hWnd, uMsg, wParam, lParam); } LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam) { WCHAR szText[256]; WCHAR szWindowText[32]; HWND hWnd, g_hWnd; bool bSetWindowLong; memset(szWindowText, NULL, sizeof(szWindowText)); wcscpy(szWindowText, L"任务管理器警告"); switch(nCode) { case HCBT_ACTIVATE: hWnd = (HWND)wParam; GetWindowText(hWnd,szText,256); if(wcscmp (szText, szWindowText) == 0) { if(!bSetWindowLong) { g_hWnd = hWnd; g_orgProc=(WNDPROC)SetWindowLong(hWnd,GWL_WNDPROC,(LONG)NewWndProc); bSetWindowLong = TRUE; } } break; case HCBT_DESTROYWND: hWnd = (HWND)wParam; GetWindowText(hWnd,szText,256); if(wcscmp (szText, szWindowText) == 0) { SetWindowLong(g_hWnd,GWL_WNDPROC,(LONG)g_orgProc); g_hWnd = NULL; bSetWindowLong = false; } break; } return CallNextHookEx(NULL, nCode, wParam, lParam); }//End of the hook procedure int main() { HWND g_hInstance = ::FindWindow(NULL, L"Windows 任务管理器"); HHOOK g_cbtHook = SetWindowsHookEx(WH_CBT, (HOOKPROC)CBTProc, NULL, NULL); }