Board index » delphi » how to trigger events in other programs

how to trigger events in other programs

Hi guys,

I need to find a way to copy a string into an editbox in another program,
and consequently trigger a mouseclick on one of its buttons.

Any suggestions?
Olivier Peter

 

Re:how to trigger events in other programs


You can use FindWindow and EnumChildWindows to locate the handle of the edit
box and the button. Next, use Windows messages to set the text and to press
the button.

"Olivier Peter" <pe...@kryptonline.com> schreef in bericht
news:3b3c2b3e$0$20372$ba620e4c@news.skynet.be...

Quote
> Hi guys,

> I need to find a way to copy a string into an editbox in another program,
> and consequently trigger a mouseclick on one of its buttons.

> Any suggestions?
> Olivier Peter

Re:how to trigger events in other programs


Thanks to your hint i found the handle of the desired window, but i've still
got a problem with the
windows messages. Underneath you can find an example of my code.
The strange fact is that PostMessage(WindowHandle, WM_QUIT, 0, 0) works just
fine.

procedure TForm1.Button1Click(Sender: TObject);
var
  i : Integer;
  UserName, Password : String;
  WindowHandle    : THandle;
begin
  UserName := 'John'; Password := 'Smith';
  WindowHandle := FindWindow(nil, 'Ciel Boekhouding voor Windows 6.12');
  if WindowHandle = 0 then begin
    ShowMessage('Error: Window Not Found!')
  end else begin
    for i := 1 to Length(UserName) do
      PostMessage(WindowHandle, WM_CHAR, Ord(UserName[i]), 1);
    PostMessage(WindowHandle, WM_NEXTDLGCTL, 0, 0);
    for i := 1 to Length(Password) do
      PostMessage(WindowHandle, WM_CHAR, Ord(UserName[i]), 1);
    PostMessage(WindowHandle, WM_LBUTTONDOWN, 100, 100);
  end;
end;

Kind Regards,
Olivier Peter

M.H. Avegaart <avega...@NOSPAMmccomm.nl> schreef in berichtnieuws
9hk6vd$1n2...@scavenger.euro.net...

Quote
> You can use FindWindow and EnumChildWindows to locate the handle of the
edit
> box and the button. Next, use Windows messages to set the text and to
press
> the button.

> "Olivier Peter" <pe...@kryptonline.com> schreef in bericht
> news:3b3c2b3e$0$20372$ba620e4c@news.skynet.be...
> > Hi guys,

> > I need to find a way to copy a string into an editbox in another
program,
> > and consequently trigger a mouseclick on one of its buttons.

> > Any suggestions?
> > Olivier Peter

Re:how to trigger events in other programs


Try using the functions from the SndKey32 unit on your Delphi CD instead.

"Olivier Peter" <pe...@kryptonline.com> schreef in bericht
news:3b406374$0$20377$ba620e4c@news.skynet.be...

Quote
> Thanks to your hint i found the handle of the desired window, but i've
still
> got a problem with the
> windows messages. Underneath you can find an example of my code.
> The strange fact is that PostMessage(WindowHandle, WM_QUIT, 0, 0) works
just
> fine.

> procedure TForm1.Button1Click(Sender: TObject);
> var
>   i : Integer;
>   UserName, Password : String;
>   WindowHandle    : THandle;
> begin
>   UserName := 'John'; Password := 'Smith';
>   WindowHandle := FindWindow(nil, 'Ciel Boekhouding voor Windows 6.12');
>   if WindowHandle = 0 then begin
>     ShowMessage('Error: Window Not Found!')
>   end else begin
>     for i := 1 to Length(UserName) do
>       PostMessage(WindowHandle, WM_CHAR, Ord(UserName[i]), 1);
>     PostMessage(WindowHandle, WM_NEXTDLGCTL, 0, 0);
>     for i := 1 to Length(Password) do
>       PostMessage(WindowHandle, WM_CHAR, Ord(UserName[i]), 1);
>     PostMessage(WindowHandle, WM_LBUTTONDOWN, 100, 100);
>   end;
> end;

> Kind Regards,
> Olivier Peter

> M.H. Avegaart <avega...@NOSPAMmccomm.nl> schreef in berichtnieuws
> 9hk6vd$1n2...@scavenger.euro.net...
> > You can use FindWindow and EnumChildWindows to locate the handle of the
> edit
> > box and the button. Next, use Windows messages to set the text and to
> press
> > the button.

> > "Olivier Peter" <pe...@kryptonline.com> schreef in bericht
> > news:3b3c2b3e$0$20372$ba620e4c@news.skynet.be...
> > > Hi guys,

> > > I need to find a way to copy a string into an editbox in another
> program,
> > > and consequently trigger a mouseclick on one of its buttons.

> > > Any suggestions?
> > > Olivier Peter

Re:how to trigger events in other programs


With the use of this unit it works indeed!

Thanks a lot.

M.H. Avegaart <avega...@NOSPAMmccomm.nl> schreef in berichtnieuws
9hposv$g0...@scavenger.euro.net...

Quote
> Try using the functions from the SndKey32 unit on your Delphi CD instead.

> "Olivier Peter" <pe...@kryptonline.com> schreef in bericht
> news:3b406374$0$20377$ba620e4c@news.skynet.be...
> > Thanks to your hint i found the handle of the desired window, but i've
> still
> > got a problem with the
> > windows messages. Underneath you can find an example of my code.
> > The strange fact is that PostMessage(WindowHandle, WM_QUIT, 0, 0) works
> just
> > fine.

> > procedure TForm1.Button1Click(Sender: TObject);
> > var
> >   i : Integer;
> >   UserName, Password : String;
> >   WindowHandle    : THandle;
> > begin
> >   UserName := 'John'; Password := 'Smith';
> >   WindowHandle := FindWindow(nil, 'Ciel Boekhouding voor Windows 6.12');
> >   if WindowHandle = 0 then begin
> >     ShowMessage('Error: Window Not Found!')
> >   end else begin
> >     for i := 1 to Length(UserName) do
> >       PostMessage(WindowHandle, WM_CHAR, Ord(UserName[i]), 1);
> >     PostMessage(WindowHandle, WM_NEXTDLGCTL, 0, 0);
> >     for i := 1 to Length(Password) do
> >       PostMessage(WindowHandle, WM_CHAR, Ord(UserName[i]), 1);
> >     PostMessage(WindowHandle, WM_LBUTTONDOWN, 100, 100);
> >   end;
> > end;

> > Kind Regards,
> > Olivier Peter

> > M.H. Avegaart <avega...@NOSPAMmccomm.nl> schreef in berichtnieuws
> > 9hk6vd$1n2...@scavenger.euro.net...
> > > You can use FindWindow and EnumChildWindows to locate the handle of
the
> > edit
> > > box and the button. Next, use Windows messages to set the text and to
> > press
> > > the button.

> > > "Olivier Peter" <pe...@kryptonline.com> schreef in bericht
> > > news:3b3c2b3e$0$20372$ba620e4c@news.skynet.be...
> > > > Hi guys,

> > > > I need to find a way to copy a string into an editbox in another
> > program,
> > > > and consequently trigger a mouseclick on one of its buttons.

> > > > Any suggestions?
> > > > Olivier Peter

Other Threads