feup
asked on
simulate a click on component
Hi!
I want to simulate a leftmousedown and a leftmouseup event on some coordinates I specify.
P.E. : Make a mousedown on a tmemo on position 1,1 and the mouseup on 100, 1), so that it's made the selection.
Also must work with TIEWebBrowser, in a page with frames (click on option 1 or 2 in frame 1).
It must use *only* winAPI instructions and not other controls. I think it uses the processmessage or sendmessage instruction, but I can't find the way of using it.
Thanks
I want to simulate a leftmousedown and a leftmouseup event on some coordinates I specify.
P.E. : Make a mousedown on a tmemo on position 1,1 and the mouseup on 100, 1), so that it's made the selection.
Also must work with TIEWebBrowser, in a page with frames (click on option 1 or 2 in frame 1).
It must use *only* winAPI instructions and not other controls. I think it uses the processmessage or sendmessage instruction, but I can't find the way of using it.
Thanks
ASKER
I can know the handle of the window, but isn't more important the handle of the component?
the component has to be a window if you want to send it messages. This doesn't mean that it has to be a form, for any component that can get focus is a kind of window. You just have to know it's handle, before sending it messages.
GL
Mike
GL
Mike
I tried the follwing that worked with the tmemo, but not with the tiewebbrowser. Why?
var lp : tmessage;
wnd : hwnd;
begin
Lp.lparamHi := 1;
Lp.LparamLo := 1;
wnd := webbrowser1.Handle;
//wnd := memo1.Handle;
Sendmessage(wnd,WM_RBUTTON DOWN,0,LP. Lparam);
sleep (200);
Sendmessage(wnd,WM_RBUTTON UP,0,LP.Lp aram);
end;
Note that I tried the rightbutton because of the coordinates, but it didn't show the menu.
var lp : tmessage;
wnd : hwnd;
begin
Lp.lparamHi := 1;
Lp.LparamLo := 1;
wnd := webbrowser1.Handle;
//wnd := memo1.Handle;
Sendmessage(wnd,WM_RBUTTON
sleep (200);
Sendmessage(wnd,WM_RBUTTON
end;
Note that I tried the rightbutton because of the coordinates, but it didn't show the menu.
a Twebbrowser needs a message handler as well else it wont handle many messages.here is an unit i have that shows an example message handler ,just take out the relevent lines about vk_back etc..:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, OleCtrls, SHDocVw_TLB,ActiveX;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
WebBrowser1: TWebBrowser;
procedure Button1Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormDeactivate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
procedure MyMessageHandler(var Msg: TMsg; var Handled: Boolean);
{ Public declarations }
end;
var
Form1: TForm1;
FOleInPlaceActiveObject: IOleInPlaceActiveObject;
SaveMessageHandler: TMessageEvent;
implementation
{$R *.DFM}
procedure TForm1.MyMessageHandler(va r Msg: TMsg; var Handled: Boolean);
var
iOIPAO: IOleInPlaceActiveObject;
Dispatch: IDispatch;
begin
{ exit if we don't get back a webbrowser object }
if WebBrowser1 = nil then
begin
Handled := False;
Exit;
end;
Handled:=(IsDialogMessage( WebBrowser 1.Handle, Msg) = True);
if (Handled) and (not WebBrowser1.Busy) then
begin
if FOleInPlaceActiveObject = nil then
begin
Dispatch := WebBrowser1.Application_;
if Dispatch <> nil then
begin
Dispatch.QueryInterface(IO leInPlaceA ctiveObjec t, iOIPAO);
if iOIPAO <> nil then
FOleInPlaceActiveObject := iOIPAO;
end;
end;
if FOleInPlaceActiveObject <> nil then
if ((Msg.message = WM_KEYDOWN) or (Msg.message = WM_KEYUP)) and
((Msg.wParam = VK_BACK) or (Msg.wParam = VK_LEFT) or (Msg.wParam = VK_RIGHT)) then
//nothing - do not pass on Backspace, Left or Right arrows
else
FOleInPlaceActiveObject.Tr anslateAcc elerator(M sg);
end;
end;
procedure TForm1.FormActivate(Sender : TObject);
begin
SaveMessageHandler := Application.OnMessage;
Application.OnMessage := MyMessageHandler;
end;
procedure TForm1.FormDeactivate(Send er: TObject);
begin
Application.OnMessage := SaveMessageHandler;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Application.OnMessage := SaveMessageHandler;
FOleInPlaceActiveObject := nil;
end;
procedure TForm1.Button1Click(Sender : TObject);
var a,b,c,d:OleVariant;
begin
WebBrowser1.Navigate(Edit1 .Text,a,b, c,d);
end;
initialization
OleInitialize(nil);
finalization
OleUninitialize;
end.
Regards Barry
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, OleCtrls, SHDocVw_TLB,ActiveX;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
WebBrowser1: TWebBrowser;
procedure Button1Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormDeactivate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
procedure MyMessageHandler(var Msg: TMsg; var Handled: Boolean);
{ Public declarations }
end;
var
Form1: TForm1;
FOleInPlaceActiveObject: IOleInPlaceActiveObject;
SaveMessageHandler: TMessageEvent;
implementation
{$R *.DFM}
procedure TForm1.MyMessageHandler(va
var
iOIPAO: IOleInPlaceActiveObject;
Dispatch: IDispatch;
begin
{ exit if we don't get back a webbrowser object }
if WebBrowser1 = nil then
begin
Handled := False;
Exit;
end;
Handled:=(IsDialogMessage(
if (Handled) and (not WebBrowser1.Busy) then
begin
if FOleInPlaceActiveObject = nil then
begin
Dispatch := WebBrowser1.Application_;
if Dispatch <> nil then
begin
Dispatch.QueryInterface(IO
if iOIPAO <> nil then
FOleInPlaceActiveObject := iOIPAO;
end;
end;
if FOleInPlaceActiveObject <> nil then
if ((Msg.message = WM_KEYDOWN) or (Msg.message = WM_KEYUP)) and
((Msg.wParam = VK_BACK) or (Msg.wParam = VK_LEFT) or (Msg.wParam = VK_RIGHT)) then
//nothing - do not pass on Backspace, Left or Right arrows
else
FOleInPlaceActiveObject.Tr
end;
end;
procedure TForm1.FormActivate(Sender
begin
SaveMessageHandler := Application.OnMessage;
Application.OnMessage := MyMessageHandler;
end;
procedure TForm1.FormDeactivate(Send
begin
Application.OnMessage := SaveMessageHandler;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Application.OnMessage := SaveMessageHandler;
FOleInPlaceActiveObject := nil;
end;
procedure TForm1.Button1Click(Sender
var a,b,c,d:OleVariant;
begin
WebBrowser1.Navigate(Edit1
end;
initialization
OleInitialize(nil);
finalization
OleUninitialize;
end.
Regards Barry
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
U can use this way too.
var LTP:tpoint;
begin
LTP:=Form1.ClientToScreen( Point(Memo 1.Left,Mem o1.Top));
SetCursorPos(LTP.x+2,LTP.y +2);
mouse_event(MOUSEEVENTF_LE FTDOWN,0,0 ,0,0);
mouse_event(MOUSEEVENTF_MO VE,40,40,0 ,0);
mouse_event(MOUSEEVENTF_LE FTUP,0,0,0 ,0);
end;
the mouse cursor can select text.
var LTP:tpoint;
begin
LTP:=Form1.ClientToScreen(
SetCursorPos(LTP.x+2,LTP.y
mouse_event(MOUSEEVENTF_LE
mouse_event(MOUSEEVENTF_MO
mouse_event(MOUSEEVENTF_LE
end;
the mouse cursor can select text.
ASKER
hi!
Just one question... is there any way to do this WITHOUT moving the mouse cursor ober the component?
thanks
Just one question... is there any way to do this WITHOUT moving the mouse cursor ober the component?
thanks
i would like to know the answer to this also? how to do this without have the pointer moved so its a background click
sendMessage(WM_LBUTTONDOWN
sendMessage(WM_LBUTTONUP,1
GL
Mike