Procedure ClickButton(WindowName, WindowCaption,
ControlName, ControlCaption: String);
Var
hParent, hControl : HWND;
Begin
hParent := 0;
hControl := 0;
hParent := FindWindow(pChar(WindowName), pChar(WindowCaption));
Try
BringWindowToTop(hParent);
Application.ProcessMessages;
hControl := FindWindowEx(hParent, 0, pChar(ControlName),
pChar(ControlCaption));
Try
SendMessage(hControl, BM_CLICK, 0,0);
Finally
hControl := 0;
End;
Finally
hParent := 0;
End;
End;
// WindowName: The name of the form (eg: TForm1)
// WindowCaption: The caption of the form (eg: Form1)
// ControlName: The name of the control (eg: TButton)
// ControlCaption: The text/caption of the control (eg: Ok)
Procedure Button2Click(Sender: TObject);
Begin
ClickButton('TForm1', 'Form1', 'TSpeedbutton', '');
End;
|