Cita:
Empezado por MARIA_MAR
Muchas gracias Nelson, es justo lo que necesitaba.
Necesito saber otra cosa, ¿cómo puedo yo redimensionar la ventana en la que se ejecuta este programa Windows sin llegar a minimizarla?, pues a veces es demasiado grande y no me deja ver mi programa Delphi que queda detrás.
¿Se podria ejecutar dentro de un form de Delphi?.
|
Hola.
Form donde se incrustará la aplicación:
Código Delphi
[-]
...
type
TForm2 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
FHwnd: HWND;
public
property HandleToApp: HWND read FHwnd write FHwnd;
end;
var
Form2: TForm2;
implementation
procedure TForm2.FormCreate(Sender: TObject);
begin
BorderIcons:= [];
BorderStyle:= bsSizeable;
FormStyle := fsStayOnTop;
end;
procedure TForm2.FormDestroy(Sender: TObject);
begin
if FHwnd <> 0 then
SendMessage(FHwnd, WM_CLOSE, 0, 0);
end;
Form que lo invoca:
Código Delphi
[-]
...
implementation
uses Unit2;
function ProcessIDToWnd(const tagPID: WORD):HWND;
var
aHWnd :HWND;
aPID :WORD;
begin
Result := 0;
aPID := 0;
aHWnd := FindWindow(nil, nil);
while aHWnd <> 0 do
begin
if GetParent(aHWnd) = 0 then
begin
GetWindowThreadProcessId(aHWnd, @aPID);
if aPID = tagPID then
begin
Result := aHWnd;
Break;
end;
end;
aHWnd := GetWindow(aHWnd, GW_HWNDNEXT);
end;
end;
function ExecuteApp(const CmdLine:string):HWND;
var
PI :PROCESS_INFORMATION;
SI :STARTUPINFO;
RE :LONGBOOL;
begin;
Result := 0;
ZeroMemory(@PI, SizeOf(PI));
ZeroMemory(@SI, SizeOf(SI));
SI.cb := SizeOf(SI);
RE := CreateProcessA(nil, PChar(CmdLine), nil, nil, True,
NORMAL_PRIORITY_CLASS, nil, nil, SI, PI);
WaitForSingleObject(PI.hProcess, 150); if RE then
begin
Result := ProcessIDToWnd(PI.dwProcessID);
CloseHandle(PI.hThread);
CloseHandle(PI.hProcess);
end;
end;
procedure TForm1.btAbrirFormClick(Sender: TObject);
begin
Form2:= TForm2.Create(Self);
Form2.Show;
FhWnd := ExecuteApp('calc.exe'); if FhWnd <> 0 then
begin
Form2.HandleToApp := FhWnd;
Windows.SetParent(FhWnd, Form2.Handle);
Windows.MoveWindow(FhWnd, 0, 0, ClientWidth, ClientHeight, True);
Windows.SetFocus(FhWnd);
end
else
ShowMessage('Error al iniciar la aplicación');
end;
Saludos.