I am running a Delphi application multiple times and I need to bring each one to top and simulate a mouse click somewhere on its form.
我正在多次运行Delphi应用程序,我需要将每个应用程序放在顶部并在其表单上的某个位置模拟鼠标单击。
In my app I have a TWebBrowser component and I want to click somewhere in that browser. The thing is that I need to click on flash object inside that browser. I tried to get the ClassName and Handle to click on flash, but is not working with all websites. So the only thing that works is to simulate a mouse click.
在我的应用程序中,我有一个TWebBrowser组件,我想在该浏览器中的某个位置单击。问题是我需要点击浏览器中的flash对象。我试图让ClassName和Handle单击flash,但不能与所有网站一起使用。所以唯一有效的方法是模拟鼠标点击。
For example I load this link into the browser http://bit.ly/XWaelU and I am trying to simulate click on the big "play" button from the flash player inside.
例如,我将此链接加载到浏览器http://bit.ly/XWaelU,我试图模拟点击内部Flash播放器的大“播放”按钮。
Can someone help me with an example code on how this can be done? I think the application must be launched with fixed position so the coordinates of the click remain the same, right?
有人可以帮我提供一个关于如何做到这一点的示例代码吗?我认为应用程序必须以固定位置启动,因此点击的坐标保持不变,对吧?
Thanks.
1 个解决方案
#1
0
Assuming you want to click a control on the window, with known position relative to the window, from which you have (can get) the handle, you could use this. Demo only on the current form. Maybe adapted to your conditions.
假设您要单击窗口上的控件,并且具有相对于窗口的已知位置,您可以从中获取(可以获得)句柄,您可以使用此控件。仅在当前表单上进行演示。也许适合你的条件。
Procedure SetWindowTopAndClickOnRelPos(wnd:HWND;Pos:TPoint);
var
ChildControlHandle:HWND;
begin
SetForegroundWindow(wnd);
ChildControlHandle:= ChildWindowFromPoint(WND,pos);
SendMessage(ChildControlHandle,WM_LButtonDown,0,5*$FFFF + 5);
SendMessage(ChildControlHandle,WM_LButtonUp,0,5*$FFFF + 5);
Form4.Memo1.Lines.Add(Format('ChildControlHandle: %d',[ChildControlHandle]));
end;
procedure TForm4.Button1Click(Sender: TObject);
begin
Memo1.Lines.Add(Format('Window: %d',[Handle]));
Memo1.Lines.Add(Format('Button: %d',[button2.Handle]));
SetWindowTopAndClickOnRelPos(handle,Point(Button2.Left + 2,Button2.Top + 2));
end;
procedure TForm4.Button2Click(Sender: TObject);
begin
Showmessage('Hallo');
end;
#1
0
Assuming you want to click a control on the window, with known position relative to the window, from which you have (can get) the handle, you could use this. Demo only on the current form. Maybe adapted to your conditions.
假设您要单击窗口上的控件,并且具有相对于窗口的已知位置,您可以从中获取(可以获得)句柄,您可以使用此控件。仅在当前表单上进行演示。也许适合你的条件。
Procedure SetWindowTopAndClickOnRelPos(wnd:HWND;Pos:TPoint);
var
ChildControlHandle:HWND;
begin
SetForegroundWindow(wnd);
ChildControlHandle:= ChildWindowFromPoint(WND,pos);
SendMessage(ChildControlHandle,WM_LButtonDown,0,5*$FFFF + 5);
SendMessage(ChildControlHandle,WM_LButtonUp,0,5*$FFFF + 5);
Form4.Memo1.Lines.Add(Format('ChildControlHandle: %d',[ChildControlHandle]));
end;
procedure TForm4.Button1Click(Sender: TObject);
begin
Memo1.Lines.Add(Format('Window: %d',[Handle]));
Memo1.Lines.Add(Format('Button: %d',[button2.Handle]));
SetWindowTopAndClickOnRelPos(handle,Point(Button2.Left + 2,Button2.Top + 2));
end;
procedure TForm4.Button2Click(Sender: TObject);
begin
Showmessage('Hallo');
end;