请问怎样向程序发送模拟鼠标移动消息,如:      WM_RBUTTONDOWN://鼠标右键被按下      WM_LBUTTONDOWN://鼠标左键被按下      WM_LBUTTONUP://释放鼠标左键      WM_RBUTTONUP://释放鼠标右键      WM_LBUTTONDBLCLK://鼠标左键双击      WM_RBUTTONDBLCLK://鼠标右键双击移动呢?!??

解决方案 »

  1.   

    请教以上这些 怎么用??postmessage(Hnd,WM_MOUSEMOVE,0,0);    ??
      

  2.   

    WM_MOUSEMOVE???我用了怎么不行的晕死..我想实现的功能是按住左键或右键后的移动 刚刚上面那些组合起来用就可以了吗???  怎么我不行有人能贴出一小段代码吗?? 谢谢了
      

  3.   

    WM_MOUSEMOVE  
    fwKeys = wParam;        // key flags 
    xPos = LOWORD(lParam);  // horizontal position of cursor 
    yPos = HIWORD(lParam);  // vertical position of cursor 
     
    Parameters
    fwKeys
    Value of wParam. Indicates whether various virtual keys are down. This parameter can be any combination of the following values: Value Description
    MK_CONTROL Set if the CTRL key is down.
    MK_LBUTTON Set if the left mouse button is down.
    MK_MBUTTON Set if the middle mouse button is down.
    MK_RBUTTON Set if the right mouse button is down.
    MK_SHIFT          Set if the SHIFT key is down.看看wParam的描述
      

  4.   

    postmessage(Hnd,WM_MOUSEMOVE,MK_RBUTTON,MakeLong(320,184));
    不是很明白 以上是不是拉住右键移动?!?
      

  5.   

    这是MSDN的解释:WM_LBUTTONDOWN
    The WM_LBUTTONDOWN message is posted when the user presses the left mouse button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse. WM_LBUTTONDOWN 
    fwKeys = wParam;        // key flags 
    xPos = LOWORD(lParam);  // horizontal position of cursor 
    yPos = HIWORD(lParam);  // vertical position of cursor 
     
    Parameters
    fwKeys 
    Value of wParam. Indicates whether various virtual keys are down. This parameter can be any combination of the following values: Value Description 
    MK_CONTROL Set if the ctrl key is down. 
    MK_LBUTTON Set if the left mouse button is down.  
    MK_MBUTTON Set if the middle mouse button is down. 
    MK_RBUTTON Set if the right mouse button is down. 
    MK_SHIFT Set if the shift key is down. 
    xPos 
    Value of the low-order word of lParam. Specifies the x-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area. 
    yPos 
    Value of the high-order word of lParam. Specifies the y-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area. 从上面可以看到 wParam 是鼠标键的按键信息, lParam是鼠标键按下时的坐标。其中lParam的高位是Y,低位是X
      

  6.   

    下面给你写了个例子:unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
        procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    var
    rect:TRect;
    x,y,lPara:Integer;
    begin
    GetWindowRect(Self.Handle,rect);//获得当前窗口的位置
    x:=rect.Left+10;                //当前窗口左上角x坐标加10
    y:=rect.Top+10;                 //当前窗口左上角y坐标加10
    lPara:=x+(y shl 16);            //就算出lParam的值//向当前窗口发送左键按下消息,相当于鼠标在相对窗口(10,10)的位置按下
    PostMessage(Self.Handle,WM_LBUTTONDOWN,MK_LBUTTON,lpara);end;//相应鼠标按下事件
    procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
    showmessage('WM_lbuttondown 在 ' + IntToStr(X) + ','+ IntToStr(y));
    end;end.