porcedure 得到目标窗体的句炳;
var
hCurWindow,hwnds: HWnd; // 窗口句柄
WinText: array [0..255] of char;
begin
// 获取第一个窗口的句柄
hCurWindow := GetWindow(Handle, GW_HWNDFIRST);
while hCurWindow <> 0 do
begin
// 获取窗口的名称
if GetWindowText(hCurWindow, @WinText, 255)>0 then
if strpas(@wintext))='目标窗体的标题' then
begin
hwnds:=hcurwindow;//储存句炳
跳出循环;
end;
listbox1.items.Add(StrPas(@WinText));
// 获取下一个窗口的句柄
hCurWindow:=GetWindow(hCurWindow, GW_HWNDNEXT);
end;
end;
function GetButtonHandle(hwnds: hwnd; 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;
procedure TfrmMain.bbtnStartClick(Sender: TObject);
var
Handle: Integer;
tmpHandle: Integer;
begin
{取句柄}
Handle := FindWindow(nil,'对话模式'); //就是窗口的Caption
if Handle<>0 then
begin
tmpHandle := Handle;
//在这里循环取到想要的句柄为止
//取发送按钮的,FButtonHandle
EnumChildWindows(Handle,@GetButtonHandle,Integer(@Handle));
FButtonHandle := Handle;
end;
end;
procedure 控制按钮;
begin
SendMessage(FButtonHandle,WM_LBUTTONDOWN,0,0);
SendMessage(FButtonHandle,WM_LBUTTONUP,0,0);
end;