HHOOK SetWindowsHookEx(
  int idHook,        // hook type
  HOOKPROC lpfn,     // hook procedure
  HINSTANCE hMod,    // handle to application instance
  DWORD dwThreadId   // thread identifier
);
lpfn 
[in] Pointer to the hook procedure. If the dwThreadId parameter is zero or specifies the identifier of a thread created by a different process, the lpfn parameter must point to a hook procedure in a dynamic-link library (DLL). Otherwise, lpfn can point to a hook procedure in the code associated with the current process. 
hMod [in] Handle to the DLL containing the hook procedure pointed to by the lpfn parameter. The hMod parameter must be set to NULL if the dwThreadId parameter specifies a thread created by the current process and if the hook procedure is within the code associated with the current process. dwThreadId 
[in] Specifies the identifier of the thread with which the hook procedure is to be associated. If this parameter is zero, the hook procedure is associated with all existing threads running in the same desktop as the calling thread. For a specified hook type, thread hooks are called first, then global hooks. The global hooks are a shared resource, and installing one affects all applications in the same desktop as the calling thread. All global hook functions must be in libraries. Global hooks should be restricted to special-purpose applications or to use as a development aid during application debugging. Libraries that no longer need a hook should remove its hook procedure. 

解决方案 »

  1.   

    没这样子用过把键盘钩子安装在MainFrame是好像无效你SetWindowsHookEx最后一个参数是什么?
      

  2.   

    LRESULT   CALLBACK KeyboardProc(int nCode,WPARAM wParam,LPARAM lParam)
    { if(((DWORD)lParam&0x40000000) && (HC_ACTION==nCode))
    {
    ::PostMessage(g_hWndLCDView,WM_DEBUG,wParam,lParam);
    }

    LRESULT RetVal = CallNextHookEx( hkb, nCode, wParam, lParam );
    return  RetVal;
    }
    BOOL __stdcall installhook()
    {
    //hins = AfxGetInstanceHandle();
    hkb=SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)KeyboardProc,0,GetCurrentThreadId());
    return TRUE;
    }
    BOOL __stdcall  UnHook()
    {   
    BOOL unhooked = UnhookWindowsHookEx(hkb);
    return unhooked;

    这是我的键盘钩子
    用postmessage(----)发送信息;