明明已经向目标窗口发了鼠标消息,为什么就没有效果呢?unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;type
  TForm1 = class(TForm)
    ComboBox1: TComboBox;
    Button1: TButton;
    Timer1: TTimer;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure ComboBox1Click(Sender: TObject);
  private
    { Private declarations }
     procedure myhotkey(var msg: Twmhotkey);message wm_hotkey;
  public
    { Public declarations }
  end;var
  Form1: TForm1;
  hh:hwnd;
  hhh:integer;
  p:tpoint;
implementation{$R *.dfm}
//列举所有窗口
procedure TForm1.Button1Click(Sender: TObject);
var
h:hwnd;
r:array[0..254]of char;
begin
if combobox1.Items.Count>0 then combobox1.Items.Clear;
h:=getwindow(handle,gw_hwndfirst);
while h<>0 do
begin
if getwindowtext(h,@r,255)>0 then
form1.ComboBox1.Items.Add(strpas(@r)) ;
h:=getwindow(h,gw_hwndnext);
end;
end;procedure TForm1.FormActivate(Sender: TObject);
begin
hhh:=GlobalAddAtom('hotkey');
 RegisterHotKey(handle, hhh, 0, vk_home);
end;
//按‘home’选鼠标将要点击的地方
 procedure Tform1.myhotkey(var msg: Twmhotkey);
 begin
 getcursorpos(p);
 //
 end;
//在下面模拟鼠标,timer为5秒
procedure TForm1.Timer1Timer(Sender: TObject);
begin
sendmessage(hh,$203,p.X,p.Y);
//sendmessage(hh,wm_lbuttondown,p.x,p.y);
sleep(200);
//sendmessage(hh,wm_lbuttonup,p.x,p.y);
end;
//控制模拟开关
procedure TForm1.Button2Click(Sender: TObject);
begin
  if timer1.Enabled=false then
    timer1.Enabled:=true else
    timer1.Enabled:=false;
end;
//选定一个窗口
procedure TForm1.ComboBox1Click(Sender: TObject);
begin
hh:=findwindow(nil,pchar(combobox1.Items[combobox1.itemindex]));
end;end.

解决方案 »

  1.   

    mouse_event能用于没有焦点的窗口吗?
    它的参数好象没有窗口句柄啊!
      

  2.   

    mouse_event 就是单纯的操作鼠标,移动、单击、双击等等。和窗口句柄没关系。
      

  3.   

    mouse_event 就是单纯的操作鼠标,移动、单击、双击等等。和窗口句柄没关系。
    所以和我的目的无关,我不是要在屏幕上按
      

  4.   

    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.
      

  5.   

    也就是说调用sendmessage之前,先要让窗口获得焦点,这有一段vb代码你参考一下:
        Dim Tid1 As Long, Tid2 As Long, pid As Long
        Tid1 = GetWindowThreadProcessId(mhwnd, pid)
        Tid2 = App.ThreadID
        Call AttachThreadInput(Tid1, Tid2, True)
        SetFocusApi mhwnd
        '在按钮相对坐标(1,1)处点击,最后一个参数用0应该也没关系
        SendMessage mhwnd, WM_LBUTTONDOWN, MK_LBUTTON, ByVal &H10001
        SendMessage mhwnd, WM_LBUTTONUP, MK_LBUTTON, ByVal &H10001
    最后说一句:
    sendmessage(hh,wm_lbuttondown,p.x,p.y);
    这一句里,你的wparam和lparam参数都不对
      

  6.   

    WPARAM为空,LPARAM是一个POINTER,结构跟POINTE一样,高位为X,低位为Y.也许LPARAM是一个INTEGER,自己设高低位.反正VB是这样.用INTEGER发送参数试试.