你不是已经做了吗??
你postmessage(x,y.....);//to hookmouse//怎样发送这个点击的坐标到上面的test form?
你发个自定义消息给 窗体
XY,作为参数,
然后在 窗体的消息里处理就行了,    

解决方案 »

  1.   

    to:byrybye(阿水) 
    但是这个自定义的消息怎么做呢?能不能说个例子!
      

  2.   

    比如了
    sendmessage(you_form.handle,wm_youmessage,x,y)
      

  3.   

    总算搞定了。多谢各位的关心,但是又碰到一个很烦人的问题,我在主程序里自定义了一个这样的消息: 
    procedure WM_MouseMovE(VAR mmouse:TWMMOUSE); message WM_MOUSE1;然后在dll文件中写入这样!   
     if (Msg = WM_RBUTTONDOWN )OR (MSG = WM_RBUTTONUP) then
        begin
          x:=pmousehookstruct(mousehook)^.pt.x;
          y:=pmousehookstruct(mousehook)^.pt.y;
          postmessage(GoData^.TargetWnd ,WM_MOUSE1,x,y);
          result:=0;
    结果,mmouse.keys的值是x,   mmouse.xpos的值是y,而mmouse.ypos的值为0;
    那如果把x,y的值合并为一个integer,高位为x的值,低位为y的值,然后再
    postmessage(GoData^.TargetWnd ,WM_MOUSE1,WM_RIGHDOWN,integer);
    那不就可以得到mmouse.xpos=x,mmouse.ypos=y了吗?
    这样可以吗?
    但是怎样合并x,y呢??
      

  4.   

    下面这段很著名的程序希望对你有用
    {                                                                         }
    { This is the core of the system and task hook.  Some notes:              }
    {                                                                         }
    {  1)  You will definitely want to give the file a more descriptive name  }
    {      to avoid possible collisions with other DLL names.                 }
    {  2)  Edit the MouseHookCallBack function to do what you need when a     }
    {      mouse message is received.  If you are hooking something other     }
    {      mouse messages, see the SetWindowsHookEx topic in the help for the }
    {      proper WH_xxxx constant, and any notes about the particular type   }
    {      of hook.                                                           }
    {  3)  If an application that uses the DLL crashes while the hook is      }
    {      installed, all manner of wierd things can happen, depending on the }
    {      sort of thing you are doing in the callback.  The best suggestion  }
    {      is to use a utility that displays loaded DLLs and forcibly unload  }
    {      the DLL.  You could also write a simple app that checks to see if  }
    {      the DLL is loaded, and if so, call FreeModule until it returns 0.  }
    {  4)  If you make changes to the DLL but the changes don't seem to be    }
    {      working, you may have the DLL already loaded in memory.  Remember, }
    {      loading a DLL that is already in memory just increments a usage    }
    {      count in Windows and uses the already loaded copy.                 }
    {  5)  Remember when you are hooking in at the *system* level, your       }
    {      callback function is being called for everything in the OS.  Try   }
    {      to keep the processing in the callback as tight and fast as you    }
    {      possibly can.                                                      }
    {  6)  Be careful of the uses clause.  If you include stuff like Dialogs, }
    {      you will end up linking in a lot of the VCL, and have a DLL that   }
    {      comes out compiled to around 250k.  You would probably be better   }
    {      served using WM_USER messages to communicate with the application. }
    {  7)  I have successfully hooked mouse messages without the use of a     }
    {      DLL, but many of the hooks say they require the callback to be in  }
    {      a DLL, so I am hesitant to include this method.  It certainly      }
    {      makes the build/test cycle *much* easier, but since it is not      }
    {      "sanctioned" by MS, I would stay away from it and discourage it.   }
    {  8)  Remember that 32-bit processes can only load 32-bit DLLs, and      }
    {      16-bit processes can only load 16-bit DLLs.  That means that if    }
    {      you set a system hook and your DLL is compiled under Delphi 1,     }
    {      only 16-bit processes are going to fire the system hook.  So, if   }
    {      it were running on a Windows 98 machine, not much of anything      }
    {      is going to fire your "system" hook.                               }
    {                                                                         }library HookDLL;uses WinTypes, WinProcs, Messages;
    { Global variables }
    {$IFDEF WIN32}{ For a system-wide hook, global variables must be Memory Mapped to be
      accessible by all processes because the data segment of 32-bit DLL is private
      to each process using it. }
    type
      PSharedData = ^TSharedData;
      TSharedData = record
        { In this record, mirror the global variables of the 16-bit version }
        HookCount: integer;
        HookHandle: HHook;
        MonitorWnd: HWND;
        WM_MONITORMOUSEMOVE: UINT;
      end;var
      { global data for the DLL for a single process }
      hMapObject: THandle;
      SharedData: PSharedData;{$ELSE}{ 16 bit Windows }
    type
      UINT = Longint;var
      HookCount: integer;
      HookHandle: HHook;
      MonitorWnd: HWND;
      WM_MONITORMOUSEMOVE: UINT;
    {$ENDIF}const
      MESSAGE_MONITOR_MOUSE_MOVE = 'DFSHookDLLMonitorMouseMoveMessage';
    function GetMonitorMouseMoveMsg: UINT; export;
    begin
      {$IFDEF WIN32}
      if SharedData = NIL then
        Result := 0
      else
        Result := SharedData^.WM_MONITORMOUSEMOVE;
      {$ELSE}
      Result := WM_MONITORMOUSEMOVE;
      {$ENDIF}
    end;{ This is where you do your special processing. }
    {$IFDEF WIN32}
    function MouseHookCallBack(Code: integer; Msg: WPARAM; MouseHook: LPARAM): LRESULT; stdcall;
    {$ELSE}
    function MouseHookCallBack(Code: integer; Msg: word; MouseHook: longint): longint; export;
    {$ENDIF}
    var
      {$IFDEF WIN32}
      HookHandle: HHOOK;
      MonitorWnd: HWND;
      WM_MONITORMOUSEMOVE: UINT;
      {$ENDIF}
      MouseHookStruct: PMouseHookStruct absolute MouseHook;
    begin
      {$IFDEF WIN32}
      { Access the shared data. Do check if SharedData is assigned, because under
        some circumstances the hook filter can be called after all processes have
        detached }
      if SharedData <> NIL then
      begin
        MonitorWnd := SharedData^.MonitorWnd;
        HookHandle := SharedData^.HookHandle;
        WM_MONITORMOUSEMOVE := SharedData^.WM_MONITORMOUSEMOVE;
      end
      else
      begin
        WM_MONITORMOUSEMOVE := 0;
        MonitorWnd := ;
        HookHandle := 0; { It seems that this handle is not used in the CallNextHookEx
                           function anyway. Several sources on the microsoft web site
                           indicate this. }
      end;
      {$ENDIF}  { If the value of Code is less than 0, we are not allowed to do anything }
      { except pass it on to the next hook procedure immediately.              }
      if (Code >= 0) and (MonitorWnd <> 0) then
      begin
        { This example sends the coordinates of all mouse move messages to the
          monitoring app (the one that installed the hook). }
        if (Msg = WM_MOUSEMOVE) and (MouseHookStruct <> NIL) then
          PostMessage(MonitorWnd, WM_MONITORMOUSEMOVE, MouseHookStruct^.pt.x,
            MouseHookStruct^.pt.y);    { You could do any number of things here based on the different mouse
          messages...
        case Msg of:
          WM_LBUTTONDOWN:
            begin
            end;
          WM_LBUTTONUP:
            begin
            end;
          WM_LBUTTONDBLCLK:
            begin
            end;
          WM_RBUTTONDOWN:
            begin
            end;
          WM_RBUTTONUP:
            begin
            end;
          WM_RBUTTONDBLCLK:
            begin
            end;
          WM_MBUTTONDOWN:
            begin
            end;
          WM_MBUTTONUP:
            begin
            end;
          WM_MBUTTONDBLCLK:
            begin
            end;
          WM_MOUSEMOVE:
            begin
            end;
        end;}    { If you handled the situation, and don't want Windows to process the }
        { message, do *NOT* execute the next line.  Be very sure this is what }
        { want, though.  If you don't pass on stuff like WM_MOUSEMOVE, you    }
        { will NOT like the results you get.                                  }
        Result := CallNextHookEx(HookHandle, Code, Msg, MouseHook);
      end
      else
        Result := CallNextHookEx(HookHandle, Code, Msg, MouseHook);
    end;{ Call InstallHook to set the hook. }
    function InstallHook(SystemHook: boolean; TaskHandle: THandle;
      AMonitorWnd: HWND) : boolean; export;
      { This is really silly, but that's the way it goes.  The only way to get the  }
      { module handle, *not* instance, is from the filename.  The Microsoft example }
      { just hard-codes the DLL filename.  I think this is a little bit better.     }
      function GetModuleHandleFromInstance: THandle;
      var
        s: array[0..512] of char;
      begin
        { Find the DLL filename from the instance value. }
        GetModuleFileName(hInstance, s, sizeof(s)-1);
        { Find the handle from the filename. }
        Result := GetModuleHandle(s);
      end;
    begin
      { Technically, this procedure could do nothing but call SetWindowsHookEx(),  }
      { but it is probably better to be sure about things, and not set the hook    }
      { more than once.  You definitely don't want your callback being called more }
      { than once per message, do you?                                             }
      {$IFDEF WIN32}
      Result := FALSE;
      if SharedData = NIL then
        exit
      else
        with SharedData^ do
        begin
      {$ENDIF}
          Result := TRUE;
          if HookCount = 0 then
          begin
            MonitorWnd := AMonitorWnd;
            if SystemHook then
              HookHandle := SetWindowsHookEx(WH_MOUSE, MouseHookCallBack, HInstance, 0)
            else
              { See the Microsoft KnowledgeBase, PSS ID Number: Q92659, for a
                discussion of the Windows bug that requires GetModuleHandle() to be
                used.                 }
              HookHandle := SetWindowsHookEx(WH_MOUSE, MouseHookCallBack,
                                             GetModuleHandleFromInstance, TaskHandle);
            if HookHandle <> 0 then
              inc(HookCount)
            else
              Result := FALSE;
          end
          else
            inc(HookCount);
      {$IFDEF WIN32}
        end;
      {$ENDIF}
    end;{ Call RemoveHook to remove the system hook. }
    function RemoveHook: boolean; export;
    begin
      { See if our reference count is down to 0, and if so then unhook. }
      Result := FALSE;
      {$IFDEF WIN32}
      if SharedData = NIL then
        exit
      else
        with SharedData^ do
        begin
      {$ENDIF}
          if HookCount < 1 then exit;
          Result := TRUE;
          dec(HookCount);
          if HookCount = 0 then
            Result := UnhookWindowsHookEx(HookHandle);
      {$IFDEF WIN32}
        end;
      {$ENDIF}
    end;{ Have we hooked into the system? }
    function IsHookSet: boolean; export;
    begin
      {$IFDEF WIN32}
      if SharedData = NIL then
        Result := FALSE
      else
        with SharedData^ do
      {$ENDIF}
          Result := (HookCount > 0) and (HookHandle <> 0);
    end;{$IFDEF WIN32}
    { Shared data management }
    procedure AllocSharedData;
    var
      Init: boolean;
    begin
      if hMapObject = 0 then
      begin
        // Create a named file mapping object.
        hMapObject := CreateFileMapping(
          THandle($FFFFFFFF),  // use paging file
          NIL,                 // no security attributes
          PAGE_READWRITE,      // read/write access
          0,                   // size: high 32-bits
          SizeOf(TSharedData), // size: low 32-bits
          'DFSHookDLLSharedDataBlock'); // name of map object, THIS MUST BE UNIQUE!
        // The first process to attach initializes memory.
        Init := GetLastError <> ERROR_ALREADY_EXISTS;
        if hMapObject = 0 then exit;
        // Get a pointer to the file-mapped shared memory.
        SharedData := MapViewOfFile(
          hMapObject,     // object to map view of
          FILE_MAP_WRITE, // read/write access
          0,              // high offset:  map from
          0,              // low offset:   beginning
          0);             // default: map entire file
        if SharedData = NIL then exit;
        // Initialize memory if this is the first process.
        if Init then
          FillChar(SharedData^, SizeOf(TSharedData), 0);
        SharedData^.WM_MONITORMOUSEMOVE := RegisterWindowMessage(
          MESSAGE_MONITOR_MOUSE_MOVE);
      end;
    end;procedure FreeSharedData;
    begin
      if hMapObject <> 0 then
        try
          try
            UnMapViewOfFile(SharedData);
            CloseHandle(hMapObject);
          except
          end;
        finally
          SharedData := NIL;
          hMapObject := 0;
        end;
    end;procedure EntryPointProc(Reason: Integer);
    begin
      case Reason of
        DLL_PROCESS_DETACH: FreeSharedData;
        DLL_PROCESS_ATTACH: AllocSharedData;
        DLL_THREAD_ATTACH: {} ;
        DLL_THREAD_DETACH: {} ;
      end;
    end;
    {$ENDIF}
    exports
      GetMonitorMouseMoveMsg,
      InstallHook,
      RemoveHook,
      IsHookSet,
      MouseHookCallBack;
    { Initialize DLL data. }
    begin
      {$IFDEF WIN32}
      SharedData := NIL;
      hMapObject := 0;
      DllProc := @EntryPointProc;
      EntryPointProc(DLL_PROCESS_ATTACH); // Must call manually in the Delphi world
      {$ELSE}
      HookCount := 0;
      HookHandle := 0;
      WM_MONITORMOUSEMOVE := RegisterWindowMessage(MESSAGE_MONITOR_MOUSE_MOVE);
      {$ENDIF}
    end.