rt
谢谢!

解决方案 »

  1.   

    我也想知道呀,包括自己的MessageBox利用钩子怎么拦截呀
    /****************************************************************************
    *                                 setMyHook
    * Inputs:
    *       HWND hWnd: Window to notify
    * Result: BOOL
    *       TRUE if successful
    * FALSE if error
    * Effect: 
    *       Sets the hook
    ****************************************************************************/__declspec(dllexport) BOOL setMyHook(HWND hWnd)
    {
        if(hWndServer != NULL)
    return FALSE; // already hooked!
        hook = SetWindowsHookEx(WH_CBT,
        (HOOKPROC)msghook,
        hInst,
        0);
    ::MessageBox(NULL,NULL,"SET",MB_OK);
        if(hook != NULL)
    { /* success */
    hWndServer = hWnd;
    return TRUE;
    } /* success */
    return FALSE; // failed to set hook
    } // setMyHook/****************************************************************************
    *                                 clearMyHook
    * Inputs:
    *       HWND hWnd: Window hook
    * Result: BOOL
    *       TRUE if successful
    * FALSE if error
    * Effect: 
    *       Removes the hook that has been set
    ****************************************************************************/__declspec(dllexport) BOOL clearMyHook(HWND hWnd)
    {
    ::MessageBox(NULL,NULL,"Clear",MB_OK);
        if(hWnd != hWndServer || hWnd == NULL)
    return FALSE;
    BOOL unhooked = UnhookWindowsHookEx(hook);
        if(unhooked)
    hWndServer = NULL;
        return unhooked;
    } // clearMyHook/****************************************************************************
    *                                   msghook
    * Inputs:
    *       int nCode: Code value
    * WPARAM wParam:
    * LPARAM lParam:
    * Result: LRESULT
    *       Either 0 or the result of CallNextHookEx
    * Effect: 
    *       Hook processing function. If the message is a mouse-move message,
    * posts the coordinates to the parent window
    ****************************************************************************/static LRESULT CALLBACK msghook(UINT nCode, WPARAM wParam, LPARAM lParam)
    {
    if(nCode < 0)
    { /* pass it on */
    CallNextHookEx(hook, nCode, wParam, lParam);
    return 0;
    } /* pass it on */
        PCWPSTRUCT msg = (PCWPSTRUCT)lParam;
    //::MessageBox(NULL,NULL,"MSG",MB_OK);
        if(msg->message ==  HCBT_CREATEWND )
    {
    ::MessageBox(NULL,NULL,"OK",MB_OK);
    PostMessage(hWndServer, WM_CLOSE, 0, 0);
    }
        return CallNextHookEx(hook, nCode, wParam, lParam);
    } // msghook
    我的钩子怎么没起作用呀,在我的应用程序里面,我想拦截MessageBox的消息,对嘛?
      

  2.   

    代码是我copy过来然后改的,楼主别生气哦