PDA

View Full Version : Delphi help required, please


MattO
16th July 2002, 11:37
Hello all,

I am using the widely available WinExecAndWait32() & SendKeys procedures to run programs from within my Delphi app, SendKeys to them and then have my App wait until they have finished.
But I am having a problem running CCE, sending keystrokes to CCE then waiting for CCE to finish.
I have tried all the variations of ExecAndWait & SendKeys but CCE never appears 'on top' so SendKeys never works with CCE.
Has anyone done this successfully?
Can anyone help me?

Is it possible to launch an external program 'always on top' from within Delphi?

thanks

MattO

[Toff]
16th July 2002, 20:10
What about searching the CCE windows with the FindWindow win32 function.
Then sending message to it.

DaveEL
17th July 2002, 18:15
Originally posted by MattO
Hello all,

I am using the widely available WinExecAndWait32() & SendKeys procedures to run programs from within my Delphi app, SendKeys to them and then have my App wait until they have finished.
But I am having a problem running CCE, sending keystrokes to CCE then waiting for CCE to finish.
I have tried all the variations of ExecAndWait & SendKeys but CCE never appears 'on top' so SendKeys never works with CCE.
Has anyone done this successfully?
Can anyone help me?

Is it possible to launch an external program 'always on top' from within Delphi?

thanks

MattO


i dont have my code here atm but

launch cce with a CreateProcess call
use findWindow / windowEnum to find the window handle
Use ChildWindowFromPoint to get the handle for the control your sending characters to

use sendMessage with a parameter of WM_Char to send a character to that control

then when finished with sending messages use the waitforsingleobject with the process handle and the wait param infinite which will halt the running thread till the program closes

DaveEL
(ill try to get some code to show this better later (my oggmux control code does this))

MattO
17th July 2002, 19:29
I am looking into FindWindow at the moment. As stated in a preivous post I am a Delphi novice (but trying to learn ;).

DaveEL, if you could post some code examples, that would be great.

Thanks

MattO

DaveEL
17th July 2002, 21:50
Originally posted by MattO
I am looking into FindWindow at the moment. As stated in a preivous post I am a Delphi novice (but trying to learn ;).

DaveEL, if you could post some code examples, that would be great.

Thanks

MattO

ok its a mess and rather out of date in terms of the oggmux version it works with but this is the thread i use to control oggmux.


Type TOggMux = class(TThread)
private
InputFile : String;
OutputFile : String;
AudioFile : String;
public
Constructor Create(suspended : boolean); overload; // horrid mess to start my thread suspended
Constructor Create(InFile,OutFile,Audio : String); overload; // the real constructor
protected
procedure Execute; override; // does everything
end;



constructor TOggMux.Create(suspended : boolean); // ignore this its horrible
begin
inherited;
end;


Constructor TOggMux.Create(InFile,OutFile,Audio : String); // just store the values you are going to use in executing the thread.
begin
Create(true);
InputFile := InFile;
OutputFile := OutFile;
AudioFile := Audio;
end;

procedure TOggMux.Execute; //
var
hwin,ch,i : Integer; // hwin : handle of the window ch: child window handle (control handle) i : loop variable
StartInfo : TStartupInfo; // info from create process
ProcInfo : TProcessInformation; // info from create process
oggmux : String; // oggmux executable

begin
Oggmux := SettingsForm.OggmuxEdit.Text; // load oggmux exe location from other form
FillChar(StartInfo,SizeOf(TStartupInfo),#0); // fill with 0
FillChar(ProcInfo,SizeOf(TProcessInformation),#0); // fill with 0
StartInfo.cb := SizeOf(TStartupInfo); // set the size
CreateProcess(nil, PChar(oggmux), nil, nil,False,
CREATE_NEW_PROCESS_GROUP+IDLE_PRIORITY_CLASS,
nil, nil, StartInfo, ProcInfo); // startup the process on idle priority
sleep(1000); // required to let the gui load properly before i do findwindow
hwin := FindWindow(nil,'Koepi''s OggMux 0.8.1'); // find handle of the window
ch := ChildWindowfrompoint(hwin,point(80,35)); // find the handle of the control at 80,35
For i := 1 to length(InputFile) do // loop for each char in the input filename
begin
sendmessage(ch,WM_char,ORD(InputFile[i]),0); // send that char to the control
end;
ch := ChildWindowfrompoint(hwin,point(80,85)); // same again for audio file
if AudioFile <> '' then
begin
For i := 1 to length(AudioFile) do
begin
sendmessage(ch,WM_char,ORD(AudioFile[i]),0);
end;
ch := ChildWindowfrompoint(hwin,point(575,85)); // find the add button at 575,85
sendmessage(ch,WM_LButtonDown,0,0); // button down
sendmessage(ch,WM_LButtonUp,0,0); // button up
end;



ch := ChildWindowfrompoint(hwin,point(80,296)); // output file same as before
For i := 1 to length(OutputFile) do
begin
sendmessage(ch,WM_char,ORD(OutputFile[i]),0);
end;
ch := ChildWindowfrompoint(hwin,point(400,280)); // ok button
sendmessage(ch,WM_LButtonDown,0,0);
sendmessage(ch,WM_LButtonUp,0,0);


sendmessage(hwin,WM_CLOSE,0,0); // send a close message so when the process finishs the program exits (not needed if your program closes straight away)

WaitForSingleObject(ProcInfo.hProcess, INFINITE); // wait till the program closes
SendMessage(JobForm.handle,WM_JOBDONE,0,0); // send a message to a different form to say the job is done (need to handle the wm_jobdone message on jobform).

end;


if you dont want to mess about with threads look only at the execute function and forget the last line too. post a reply if you have any questions

DaveEL