我看可以一个QQ轰炸机的代码,于是自己写了一段代码模仿在另外一个windows程序里的一个button的鼠标单击!代码是这样写的!
function GetButtonHandle(hwnd: Integer; lparam: Longint):Boolean; stdcall;
var
buffer: array[0..255] of Char;
buffer1: array[0..255] of Char;
begin
Result := True;
//得到目标窗口的控件
GetClassName(hwnd,buffer,256);
//找到目标窗口的目标控件
if StrPas(Buffer)='Button' then
begin
GetWindowText(hwnd,buffer1,100);
if buffer1 = '确定' then
begin
PInteger(lparam)^ := hwnd; //得到目标控件的Hwnd(句柄)
Result:=False; //终止循环
end;
end;
end;
procedure tform1.button1onclick(sender:tobject);
var
myHandle,temphandle,Fbuttonhandle:Hwnd;
begin
myHandle:=FindWindow(nil,'test'); //就是窗口的Caption
if myHandle<>nil then
begin
tmpHandle := myHandle;
//在这里循环取到想要的句柄为止
//取按钮的FButtonHandle
EnumChildWindows(tmpHandle,@GetButtonHandle,Integer(@tmpHandle));
FButtonHandle := tmpHandle;
end;
SendMessage(FButtonHandle,MOUSEEVENTF_LEFTDOWN,0,0);
SendMessage(FButtonHandle,MOUSEEVENTF_LEFTUP,0,0);
end;
程序编译正常,但我怎么按button,在另外一个叫test的窗体里的名为'确定'的按钮也没有反应!
请教大虾们,我的程序到底出现了什么问题?拜托!
function GetButtonHandle(hwnd: Integer; lparam: Longint):Boolean; stdcall;
var
buffer: array[0..255] of Char;
buffer1: array[0..255] of Char;
begin
Result := True;
//得到目标窗口的控件
GetClassName(hwnd,buffer,256);
//找到目标窗口的目标控件
if StrPas(Buffer)='Button' then
begin
GetWindowText(hwnd,buffer1,100);
if buffer1 = '确定' then
begin
PInteger(lparam)^ := hwnd; //得到目标控件的Hwnd(句柄)
Result:=False; //终止循环
end;
end;
end;
procedure tform1.button1onclick(sender:tobject);
var
myHandle,temphandle,Fbuttonhandle:Hwnd;
begin
myHandle:=FindWindow(nil,'test'); //就是窗口的Caption
if myHandle<>nil then
begin
tmpHandle := myHandle;
//在这里循环取到想要的句柄为止
//取按钮的FButtonHandle
EnumChildWindows(tmpHandle,@GetButtonHandle,Integer(@tmpHandle));
FButtonHandle := tmpHandle;
end;
SendMessage(FButtonHandle,MOUSEEVENTF_LEFTDOWN,0,0);
SendMessage(FButtonHandle,MOUSEEVENTF_LEFTUP,0,0);
end;
程序编译正常,但我怎么按button,在另外一个叫test的窗体里的名为'确定'的按钮也没有反应!
请教大虾们,我的程序到底出现了什么问题?拜托!
-------------------------------------
如果您觉的您对Delpih感兴趣或是很想学的更好些或者是对Delphi有更深的认识,我们可以一起交流;
呵呵
www.nxrs.net/bbs
谢谢,别抛砖