弄了半天SetWindowsHookEx还是没头绪,麻烦哪位高人能指点一二
程序的句柄我已经拿到了,接下来该如何写……procedure TForm1.Button2Click(Sender: TObject);
begin
hHook := SetWindowsHookEx(WH_MOUSE, HookProc, Hwnd, 0);
end;function HookProc(iCode: integer; wParam: wParam; lParam: lParam): LResult; stdcall;
begin
if iCode=WM_MOUSEMOVE then //我只要拦截MOUSE MOVE消息就可以
 begin
 //设想是只要拦截,不把MOUSE MOVE这个消息传递给这个程序
 //不知该写什么了
 end
end;
end;

解决方案 »

  1.   

    //设想是只要拦截,不把MOUSE MOVE这个消息传递给这个程序
    Result := 1;
     //不知该写什么了
      

  2.   

    是不想把mousemove这个消息传给程序,还是不想让程序对这个消息作出响应?
    你想实现一个什么样的效果?
      

  3.   

    To enable the system to process the message, the return value must be zero. To discard the message, the return value must be a nonzero value. 
    如果想让系统处理这个消息,返回值必须为0;
    要丢弃这个消息,返回值必须为非0;
    但是if iCode=WM_MOUSEMOVE 不对啊,iCode只可能有3种取值:HC_ACTION,HC_NOREMOVE,<0.应该是if wParam=WM_MOUSEMOVE then
      lParam指向鼠标消息的结构,包含接收消息的窗口句柄,位置等。Result := 1;就OK了。
      

  4.   

    mouse HoOk 必须采用dll方式......keyHook可以采用第一位仁兄的方法...
      

  5.   

    谢谢大家的建议,根据lijinjie(风云乐神)的意见我写了DLL
    DLL代码部分
    //---------hoot.dpr----------
    library hoot;
    uses
      hoot1 in 'hoot1.pas';
    {$R *.res}
    exports
     EnableMouseHook,
     DisableMouseHook;
    begin
    end.
    //---------hoot.dpr----------//---------hoot1.pas----------
    unit hoot1;
    interface
    uses
    Windows,Messages;
    var
    hHk: HHOOK;//钩子的句柄值。
    hHandle:THandle;//需要拦截的窗口句柄
    function MouseHookProc(nCode: Integer;WParam: WPARAM;LParam: LPARAM): LRESULT;stdcall;
    function EnableMouseHook(Hwnd:THandle):Boolean; stdcall; export;
    function DisableMouseHook:Boolean; stdcall; export;implementationfunction MouseHookProc(nCode: Integer;WParam: WPARAM;LParam: LPARAM): LRESULT;stdcall;
    var
    MouseHookStruct: ^TMOUSEHOOKSTRUCT;
    begin
    Result := 0;
    if wParam = WM_MOUSEMOVE then //判断是不是鼠标移动事件
    begin
     MouseHookStruct := Pointer(LParam);//转换指针并付值给MouseHookStruct变量。
     if MouseHookStruct.hwnd=hHandle then Result :=1 
       //如果当前窗口句柄等于我需要拦截的窗口句柄则丢弃这个消息
     Result:=1
    end;
    end;function EnableMouseHook(Hwnd:THandle):Boolean; stdcall; export;
    begin
    if hHk = 0 then //为了安全,必须判断一下再设置钩子。
    Begin
    hHk := SetWindowsHookEx(WH_MOUSE,@MouseHookProc,Hinstance,0);
    hHandle:=Hwnd; //从主程序传递过来的需要拦截的窗口句柄
    Result := True;
    end
    else
    Result := False;
    end;function DisableMouseHook:Boolean; stdcall; export;
    begin
    if hHk <> 0 then //如果有钩子就卸掉他。
    begin
    UnHookWindowsHookEx(hHk);
    hHk := 0;
    Result := True;
    end
    else
    Result := False;
    end;
    end.
    //---------hoot1.pas----------
    主程序部分代码
    var
      function EnableMouseHook(Hwnd:THandle):Boolean; stdcall;external 'hoot.DLL';
      function DisableMouseHook:Boolean; stdcall;external 'hoot.DLL';implementation
    procedure TForm1.Button2Click(Sender: TObject);
    begin
    if EnableMouseHook(Hwnd) then ShowMessage('HotKey Testing...');
    //Hwnd为我想拦截的窗口句柄
    end;系统没有提示任何错误,也始终没看到效果
      

  6.   

    var
    hHk: HHOOK;//钩子的句柄值。
    hHandle:THandle;//需要拦截的窗口句柄
    你跟踪一下hHandle的值-----不是你想要的吧?
      

  7.   

    呵呵,我看了一下,hHandle的值是你想要的。

    var
    MouseHookStruct: ^TMOUSEHOOKSTRUCT;
    begin
    Result := 0;
    if wParam = WM_MOUSEMOVE then //判断是不是鼠标移动事件
    begin
     MouseHookStruct := Pointer(LParam);//转换指针并付值给MouseHookStruct变量。
     if MouseHookStruct.hwnd=hHandle then Result :=1 
       //如果当前窗口句柄等于我需要拦截的窗口句柄则丢弃这个消息
     Result:=1
    end;
    改为:
    Result := 0;
      if wParam = WM_MOUSEMOVE then //判断是不是鼠标移动事件
      begin
        if pMOUSEHOOKSTRUCT( LParam )^.hwnd = hHandle then
        begin
           Result :=1; //如果当前窗口句柄等于我需要拦截的窗口句柄则丢弃这个消息
          // MessageBox( 0,PChar(IntToStr(hHandle)),'OK',MB_OK);
        end;
      end;
    就可以了。我试了试,很好!
      

  8.   

    flyinwuhan(★★★★★)(冒牌高手) 大哥的是正确的...o ye ...哈哈.