View Full Version : Running TMPGenc from Delphi
MattO
20th October 2002, 17:20
mmgrover & migor,
I have looked at the code for your RunCCE component.
I made a couple of changes, mainly filenames etc, to try and get it to run TMPGenc. I got it to run TMPGenc but I do not fully understand the code so I could not get it to do everything I wanted it to.
Would it be possible for you to code a RunTMPGenc component?
What I was hoping for ;) is:
1) Start TMPGenc.
2) Load a given .AVS file as the 'Video Source'.
3) Load a given .MCF file as a 'Configuration File'.
4) Encode the Video.
5) Close TMPGenc after completion of encoding.
thanks if you can
MattO
PS
mmgrover - how is the Mplex program coming on?
I'm not being pushy .. I'm just asking ;)
MattO
22nd October 2002, 22:50
hello all,
(sorry for the long post)
I have had a go myself, (borrowing migor and mmgrover's code), but its not working :(
For test purposes I put 1 button on a Form with the following code, this is in Delphi:
----------------------------------
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure Delay(n: LongInt);
var
Start: LongInt;
begin
Start := GetTickCount;
repeat Application.ProcessMessages;
until (GetTickCount - Start) >= n;
end;
procedure RunTMPGenc;
var
TMPGenc, Encode, LoadVideo, LoadMCF, OpenDialog, OpenFilename : HWnd;
Text: PChar;
Encoding : boolean;
begin
if WinExec(PChar('TMPGENC.EXE'), SW_SHOW) > 31 then
Begin
Delay(2000); // Allow TMPGenc time to startup
TMPGenc := FindWindow(nil,PChar('TMPGEnc')); // Identify TMPGenc's main window
SetWindowPos(TMPGenc,HWND_TOP,0,0,636,490,SWP_NOSIZE); // Resize TMPGenc's window to a set size, put it on top and make it so it cannot be resized
Delay(400); // Allow TMPGenc time to resize
LoadVideo := ChildWindowFromPoint(TMPGenc,point(410,345)); // 'Load Video' Button location
SendMessage(LoadVideo,BM_CLICK,0,0); // Click 'Load Video' button
Delay(400); // Allow TMPGenc time to show Open dialog
OpenDialog := FindWindow(nil,PChar('Open')); // Identify TMPGenc's Open File Dialog
OpenFilename := ChildWindowFromPoint(OpenDialog,point(100,215)); // Enter Filename location
Text := PChar('D:\TMPGENC.AVS');
SendMessage(OpenFilename,WM_SETTEXT,0,Integer(Text)); // Enter Filename
SendMessage(OpenFilename,WM_CHAR,13,0); // Send Return key to except Filename and close Dialog
Delay(400); // Allow TMPGenc time to accept data
LoadMCF := ChildWindowFromPoint(TMPGenc,point(540,445)); // 'Load' Configuration Button location
SendMessage(LoadMCF,BM_CLICK,0,0); // Click 'Load' Configuration button
Delay(400); // Allow TMPGenc time to show Open dialog
OpenDialog := FindWindow(nil,PChar('Open')); // Identify TMPGenc's Open File Dialog
OpenFilename := ChildWindowFromPoint(OpenDialog,point(100,215)); // Enter Filename location
Text := PChar('D:\MOVIE.MCF');
SendMessage(OpenFilename,WM_SETTEXT,0,Integer(Text)); // Enter Filename
SendMessage(OpenFilename,WM_CHAR,13,0); // Send Return key to accept Filename and close Dialog
Delay(400); // Allow TMPGenc time to accept data
Encode := ChildWindowFromPoint(TMPGenc,point(50,70)); // Encode Button location
SendMessage(Encode,BM_CLICK,0,0); // Click 'Encode' button
Encoding := True; // Set Encoding variable to True
WHILE Encoding DO // Whilst Encoding variable is True do the following
BEGIN
Delay(2000); // Allow TMPGenc time to start encoding
REPEAT Delay(20000); // Pause this program for 20 secs, but allow TMPGenc to continue
UNTIL IsWindowEnabled(Encode) <> False; // Check if TMPGenc's Encode button is Enabled, if it is not go back to the REPEAT line, if it is then encoding has finished so go to next line
Encoding := False; // Set Encoding variable to False to get out of WHILE loop
END;
SendMessage(TMPGenc,WM_CLOSE,0,0); // Close TMPGenc
End;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
RunTMPGenc;
end;
end.
----------------------------------
I think it is something to do with ChildWindowFromPoint & FindWindow.
Should I be using GetNextWindow with GW_CHILD? I have tried but keep failing. I think I am close but no ...
Please can someone have a look and explain where I am going wrong (in simple terms) ;)
thanks
MattO
migor
22nd October 2002, 23:03
MattO, where do you have a failure?
Now is not the time, but maybe a day after tomorrow I'll check your
code.
MattO
23rd October 2002, 09:01
migor,
It does not work at all with the above code (none of the clicks work). I have played with it again, and if I create another variable -
TMPGencFiles : HWnd;
- put this line after SetWindowPos -
TMPGencFiles := GetWindow(TMPGenc,GW_CHILD);
- then change the first location line to -
LoadVideo := ChildWindowFromPoint(TMPGencFiles,point(410,35));
- the 'LoadVideo' BM_CLICK works.
The lower panel in TMPGenc is obviously regarded as another Window / ChildWindow. I can then locate the LoadVideo and LoadMCF buttons relative to it (?).
But then the following OpenDialog does not work (it obviously isn't using the correct window / childwindow), using a GW_CHILD on the Open Dialog does not work, so how do I enter my text into the edit line in the Open Dialogs?
Also I do not know how to get to the Encode button after this as, I think, it is on a different ChildWindow, and if I use GetWindow with GW_CHILD I go deeper into the first GW_CHILD window (does this make any sense??). Can I 'tab' through the ChildWindows to find the Encode button? or the Window the Encode button is in?
Sorry if what I am saying does not make any sense, as I am not a programmer (but I am trying).
I hope this helps you help me.
MattO
MattO
24th October 2002, 20:57
migor,
I have been trying to locate the Open Dialog's using Delphi's WinSight, they show up as a 'Popup'. I managed to find the LoadVideo, LoadMCF and Encode Buttons (they were Childs), but I can not get the Open Dialog's :(
Also I think they keep changing location (depth?), but it could be me just going mad ;)
I think my code works for LoadVideo, LoadMCF and Encode buttons.
This is what I have so far.
--------------------
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure Delay(n: LongInt);
var
Start: LongInt;
begin
Start := GetTickCount;
repeat Application.ProcessMessages;
until (GetTickCount - Start) >= n;
end;
procedure RunTMPGenc;
var
TMPGenc, Dlg, Encode, LoadVideo, LoadMCF, OpenDialog, OpenFileName : HWnd;
Text: PChar;
Encoding : boolean;
StartUpInfo: TStartUpInfo;
ProcessInfo: TProcessInformation;
begin
FillChar(StartUpInfo, SizeOf(StartUpInfo), 0);
StartUpInfo.cb := SizeOf(StartUpInfo);
StartUpInfo.wShowWindow := SW_SHOW;
StartUpInfo.dwFlags := STARTF_USESHOWWINDOW;
If (CreateProcess(nil, PChar('TMPGENC.EXE'), nil, nil, FALSE, 0, nil, nil, StartUpInfo, ProcessInfo)) then
begin
Delay(2000);
TMPGenc := FindWindow(nil,PChar('TMPGEnc'));
Delay(400);
LoadVideo := GetWindow(TMPGenc,GW_CHILD);
LoadVideo := GetWindow(LoadVideo,GW_CHILD);
LoadVideo := GetNextWindow(LoadVideo,GW_HWNDNEXT);
LoadVideo := GetNextWindow(LoadVideo,GW_HWNDNEXT);
LoadVideo := GetNextWindow(LoadVideo,GW_HWNDNEXT);
LoadVideo := GetNextWindow(LoadVideo,GW_HWNDNEXT);
LoadVideo := GetNextWindow(LoadVideo,GW_HWNDNEXT);
LoadVideo := GetNextWindow(LoadVideo,GW_HWNDNEXT);
SendMessage(LoadVideo,BM_CLICK,0,0);
Delay(1000);
OpenDialog := GetNextWindow(TMPGenc,GW_HWNDNEXT);
OpenFileName := GetWindow(OpenDialog,GW_CHILD);
OpenFileName := GetNextWindow(OpenFileName,GW_HWNDNEXT);
OpenFileName := GetNextWindow(OpenFileName,GW_HWNDNEXT);
OpenFileName := GetNextWindow(OpenFileName,GW_HWNDNEXT);
OpenFileName := GetNextWindow(OpenFileName,GW_HWNDNEXT);
OpenFileName := GetNextWindow(OpenFileName,GW_HWNDNEXT);
OpenFileName := GetNextWindow(OpenFileName,GW_HWNDNEXT);
Text := PChar('D:\TMPGENC.AVS');
SendMessage(OpenFilename,WM_SETTEXT,0,Integer(Text));
SendMessage(OpenFilename,WM_CHAR,13,0);
Delay(1000);
LoadMCF := GetWindow(TMPGenc,GW_CHILD);
LoadMCF := GetWindow(LoadMCF,GW_CHILD);
LoadMCF := GetNextWindow(LoadMCF,GW_HWNDNEXT);
SendMessage(LoadMCF,BM_CLICK,0,0);
Delay(1000);
OpenDialog := GetNextWindow(TMPGenc,GW_HWNDNEXT);
OpenDialog := GetNextWindow(OpenDialog,GW_HWNDNEXT);
OpenFileName := GetWindow(OpenDialog,GW_CHILD);
OpenFileName := GetNextWindow(OpenFileName,GW_HWNDNEXT);
OpenFileName := GetNextWindow(OpenFileName,GW_HWNDNEXT);
OpenFileName := GetNextWindow(OpenFileName,GW_HWNDNEXT);
OpenFileName := GetNextWindow(OpenFileName,GW_HWNDNEXT);
OpenFileName := GetNextWindow(OpenFileName,GW_HWNDNEXT);
Text := PChar('D:\MOVIE.MCF');
SendMessage(OpenFilename,WM_SETTEXT,0,Integer(Text));
SendMessage(OpenFilename,WM_CHAR,13,0);
Delay(1000);
Encode := GetWindow(TMPGenc,GW_CHILD);
Encode := GetNextWindow(Encode,GW_HWNDNEXT);
Encode := GetNextWindow(Encode,GW_HWNDNEXT);
Encode := GetNextWindow(Encode,GW_HWNDNEXT);
Encode := GetWindow(Encode,GW_CHILD);
Encode := GetNextWindow(Encode,GW_HWNDNEXT);
SendMessage(Encode,BM_CLICK,0,0);
Encoding := True;
WHILE Encoding DO
BEGIN
Delay(2000);
REPEAT Delay(20000);
UNTIL IsWindowEnabled(Encode) <> False;
Encoding := False;
END;
SendMessage(TMPGenc,WM_CLOSE,0,0);
End;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
RunTMPGenc;
end;
end.
--------------------
How do you locate and identify Child Windows & Popups? What tool do you use?
thanks
MattO
migor
24th October 2002, 22:40
Hi MattO,
Here is an example of the code:
---------------------------------------------------------------
function WEnum(Wnd: hWnd; Res: PInteger): Bool; stdcall;
var
S : array[0..50] of char;
begin
Result := True;
if IsWindow(Wnd) and (IsWindowVisible(Wnd)) then
begin
GetWindowText(wnd,S,50);
Result := AnsiCompareText(S, 'Open') <> 0;
if not Result then Res^ := Wnd;
end;
end;
procedure RunTMPGenc;
var
TMPGenc, Wnd, ChldWnd : HWnd;
BottomPanel : Hwnd;
ed : integer;
Txt : PChar;
buf : Array[0..255] of char;
Encoding : boolean;
StartUpInfo: TStartUpInfo;
ProcessInfo: TProcessInformation;
begin
FillChar(StartUpInfo, SizeOf(StartUpInfo), 0);
StartUpInfo.cb := SizeOf(StartUpInfo);
StartUpInfo.wShowWindow := SW_SHOW;
StartUpInfo.dwFlags := STARTF_USESHOWWINDOW;
If (CreateProcess(nil, PChar('E:\VideoWorking\TMPGEnc-2\tmpgenc_avisynth.exe'),
nil, nil, FALSE, 0, nil, nil, StartUpInfo, ProcessInfo)) then
Begin
Delay(2000); // Allow TMPGenc time to startup
TMPGenc := FindWindow(nil,PChar('TMPGEnc')); // Identify TMPGenc's main window
//'Load video' button placed on the panel, which is a child of the main window
BottomPanel := GetWindow( TMPGenc, GW_CHILD );//Bottom panel (with buttons)
//Button coordinates are related to the panel
PostMessage(ChildWindowFromPoint(BottomPanel,point(410,32)),BM_CLICK,0,0); // Click 'Load Video' button
Delay(3000); // Allow TMPGenc time to show Open dialog !!!
EnumWindows( @WEnum, Integer(@Wnd)) ; //Find the 'Open' dialog window
ChldWnd := ChildWindowFromPoint(Wnd,point(150,198)) ; // File edit handle
Txt := PChar('D:\TMPGENC.AVS');
// SendMessage(Wnd,WM_SETTEXT,0,Integer(Txt));
// or
// SetWindowText(GetWindow( Wnd, GW_CHILD ), Txt);
// or
// SetDlgItemText( Wnd, GetDlgCtrlID(ChldWnd), Txt);
// GetDlgItem( Wnd, 1); // Handle of the 'Open' button
// GetDlgItem( Wnd, 2); // Handle of the 'Cancel' button
end;
end;
--------------------------------------------------------------
However, I'd like to point out that TMPEG has command line options.
It look similiar to this:
"TMPEG.exe Filename.tpr /Encode /Close". I don't know anything else about it and I don't know how to create a .tpr file, but DVD2SVCD is using this approach.
And here's the source code of the little program for searching windows:
---------------------------------------------------------------
procedure TForm1.ShowHwndAndClassName(CrPos: TPoint);
var
aName: array [0..255] of Char;
begin
hWnd := WindowFromPoint(CrPos);
laHandle.Caption := 'Handle : ' + IntToStr(hWnd);
if Boolean(GetClassName(hWnd, aName, 256)) then
laClassname.Caption := string(aName)
else
laClassname.Caption := 'Not found';
if IsWindowVisible(hWnd)
then laVisible.caption := 'VISIBLE'
else laVisible.caption := 'NOT VISIBLE';
GetWindowText(hWnd,aName,255);
laText.Caption := aName;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
rPos : TPoint;
begin
if Boolean(GetCursorPos(rPos)) then begin
ShowHwndAndClassName(rPos);
Windows.ScreenToClient(hWnd, rPos);
laCoord.Caption := '(' + inttostr(rPos.X) + ', ' + inttostr(rPos.Y) + ')';
end;
end;
----------------------------------------------------------------
MattO
25th October 2002, 09:51
migor,
thanks for that. I will check it out, and get back to you.
MattO
vBulletin® v3.8.11, Copyright ©2000-2024, vBulletin Solutions Inc.