Link to home
Start Free TrialLog in
Avatar of trausti
trausti

asked on

Invisible man that push a button

Hello!!!

I want my Delphi app to run a setup file and when the setup file is finish to load i have to push "next" and may be again "next" , i want my Delphi app to listen if this window is running use FindWindowEx(Findwindow('notepad', nil), 0, 'edit', nil); or something like that. and when this window is upp and running i will let my Delphi program to hit automatically the left mouse button and more, "that's needs to the setup" with API Postmessage - WM_LBUTTONDOWN and UP

Is this Possible?
Avatar of Palamedes
Palamedes
Flag of United States of America image

Just so I understand,  You want your application to sit in the background and automate the setup process of some other application?
Avatar of trausti
trausti

ASKER

Yes , and thank you for understand me
Well, your grammer needs improving, but I think I get the jist - I'll see what I can come up with...
Hmmm This would be subclassing a window I think.  I have no idea how to do this in Delphi.  Going to have to look into it.

-Pal
ASKER CERTIFIED SOLUTION
Avatar of PhrAtoR
PhrAtoR

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
PS: if you don't have winsight, let me know. i wrote my own 'small' version -)
Avatar of trausti

ASKER

I have not the Winsight, what is that, can you send me

question@vis.is
Avatar of trausti

ASKER

This won't work

hwnd:=FindWindowEx(hwnd,0,'TButton','&Next');

What is 0,TButton,&Next ?

I'm trying to install "Getright" and push &next And ?
Avatar of trausti

ASKER

hwnd get 0 in debugging

hwnd:=FindWindowEx(hwnd,0,'TButton','&Next');
Winspy is included in delphi professionell and c/s, so i can't send it (would be illegal).
I'll send you my small prog.

hwnd:=FindWindowEx(hwnd,0,'TButton','&Next');

0  =  handle to a childwindow. 0 because there is no.
'TButton'  = Name of a component (like Tform or TButton, TEdit,...)
'&Next'  = Title of the window or button.

PhrAtoR

Avatar of trausti

ASKER

This won't work, here is the code

var
hwnd : THandle;
h    : THandle;
begin
hwnd := FindWindow(NIL,'Cool Edit 96 Installation');
if hwnd<>0 then begin
//h:=hwnd;
SetForeGroundWindow(hwnd);
Sleep(1000);
h := FindWindowEx(hwnd,0,'Welcome!','&OK');
SetForeGroundWindow(h);
//hwnd:=FindWindowEx(h,0,'Welcome!','Next');
//if hwnd<>0 then begin
SendMessage(hwnd,WM_KEYDOWN,13,0);
SendMessage(hwnd,WM_KEYUP,13,0);
end;
end;
//end;
if there is no window/button with componentname 'TButton' and Title '&Next' FindWindowEX MUST result 0

Avatar of trausti

ASKER

There is a button with name "next" and the window caption is GetRight Installation the same as parent

what can i do?
Thats right. This code won't work.
in your code hwnd is the handle of the window 'Cool Edit 96 Installation'.

you have to send the messages to the button, so you need the handle of the button.
hwnd:=FindWindow('Cool Edit 96 Installation',NIL);
if hwnd<>0 then begin
    h:=hwnd;
    hwnd:=FindWindowEx(hwnd,0,[COMPONENTNAME],'OK');
  if hwnd<>0 then begin
      SendMessage(h,WM_KEYDOWN,13,0);
      SendMessage(h,WM_KEYUP,13,0);
    end;

You have to replace [COMPONENTNAME] by the name of the Button's component. Use my program to get its name.
it's the string in the brackets ().
If one letter in 'OK' is underlined then put a & in front of it.
Thats right. This code won't work.
in your code hwnd is the handle of the window 'Cool Edit 96 Installation'.

you have to send the messages to the button, so you need the handle of the button.
hwnd:=FindWindow('Cool Edit 96 Installation',NIL);
if hwnd<>0 then begin
    h:=hwnd;
    hwnd:=FindWindowEx(hwnd,0,[COMPONENTNAME],'OK');
  if hwnd<>0 then begin
      SendMessage(h,WM_KEYDOWN,13,0);
      SendMessage(h,WM_KEYUP,13,0);
    end;

You have to replace [COMPONENTNAME] by the name of the Button's component. Use my program to get its name.
it's the string in the brackets ().
If one letter in 'OK' is underlined then put a & in front of it.
Thats right. This code won't work.
in your code hwnd is the handle of the window 'Cool Edit 96 Installation'.

you have to send the messages to the button, so you need the handle of the button.
hwnd:=FindWindow('Cool Edit 96 Installation',NIL);
if hwnd<>0 then begin
    h:=hwnd;
    hwnd:=FindWindowEx(hwnd,0,[COMPONENTNAME],'OK');
  if hwnd<>0 then begin
      SendMessage(h,WM_KEYDOWN,13,0);
      SendMessage(h,WM_KEYUP,13,0);
    end;

You have to replace [COMPONENTNAME] by the name of the Button's component. Use my program to get its name.
it's the string in the brackets ().
If one letter in 'OK' is underlined then put a & in front of it.
oops. last comment was posted three times. sorry.
PhrAtoR
Avatar of trausti

ASKER

Where is the program email: emil@vis.is
Avatar of trausti

ASKER

Alright this works,

When i have click one "&next" i have to wait for extract , before i can click the &next button. How can i wait for the next window?
just implemant a loop that looks for the next window like this:

while findwindow('NameOfSecondWindow',Nil)= 0 do;
handleof2ndwindow:=findwindow('NameOfSecondWindow',Nil)

PhrAtoR
don't forget the ; behind the do!
Avatar of trausti

ASKER

What are you meaning?
Avatar of trausti

ASKER

Can you show me some examples with While - DO
Examples? What kind of examples?

do; means do nothing

so
while findwindow('NameOfSecondWindow',Nil)= 0 do;
means: while there is no window with the title 'NameOfSecondWindow' do nothing. When there is a window -> finish the loop and continue with the program.

PhrAtoR
The problem with that is, what if a window NEVER opens with that name.. suddenly you have an application running waiting for something that will never happen..

-Pal
Avatar of trausti

ASKER

Let's say i'm installing Acrobat Reader 4.0, this setup opens tvo windows Main and Child, i just want to control the Childe window and send WM_KEYDOWN - WM_KEYUP thats all. You can test this if you have Acrobat Reader 4.0

Thanks
Trausti
i'll test it.