Quiero iniciar una aplicación desde Delphi y obtener un control para que pueda incrustar la ventana principal de dicha aplicación en un marco de tipo TFrame. Hasta ahora he intentado:¿Cómo iniciar una aplicación y obtener un control con Delphi?
Function TFrmEmbeddedExe.StartNewApplication : Boolean;
var
SEInfo: TShellExecuteInfo;
ExitCode : DWORD;
begin
FillChar(SEInfo, SizeOf(SEInfo), 0) ;
SEInfo.cbSize := SizeOf(TShellExecuteInfo) ;
with SEInfo do
begin
fMask := SEE_MASK_NOCLOSEPROCESS;
Wnd := self.Handle;
lpFile := PChar(self.fexecuteFileName) ;// Example could be 'C:\Windows\Notepad.exe'
nShow := SW_SHOWNORMAL;//SW_HIDE;
end;
if ShellExecuteEx(@SEInfo) then
begin
sleep(1500);
self.fAppWnd := FindWindow(nil, PChar(self.fWindowCaption)); //Example : 'Untitled - Notepad'
if self.fAppWnd <> 0 then
begin
Windows.SetParent(self.fAppWnd, SEInfo.Wnd);
ShowWindow(self.fAppWnd, SW_SHOWMAXIMIZED);
result := true;
end
else
result := false;
end
else
result := false;
end ;
El código anterior funciona realmente, pero FINDWINDOW encontrará ningún instans dadas de la aplicación empecé. Quiero incrustar las instans exactas que Shellexecuted. Si el Bloc de notas se ha iniciado un par de veces, no hay forma de que pueda obtener el correcto utilizando FindWindow.
que he intentado:
Function TfrmEmbeddedExe.CreateProcessNewApplication : Boolean;
var
zAppName: array[0..512] of char;
StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
Res : DWORD;
DoWait : Boolean;
begin
DoWait := False;
StrPCopy(zAppName, self.fexecuteFileName); //'C:\Windows\Notepad.exe'
FillChar(StartupInfo, Sizeof(StartupInfo), #0);
StartupInfo.cb := Sizeof(StartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow := SW_SHOWNORMAL;
if CreateProcess (zAppName,
nil, { pointer to command line string }
nil, { pointer to process security attributes }
nil, { pointer to thread security attributes }
false, { handle inheritance flag }
CREATE_NEW_CONSOLE or { creation flags }
NORMAL_PRIORITY_CLASS,
nil, { pointer to new environment block }
nil, { pointer to current directory name }
StartupInfo, { pointer to STARTUPINFO }
ProcessInfo) then { pointer to PROCESS_INF }
begin
if DoWait then //just set it to false... so it will never enter here
begin
WaitforSingleObject(ProcessInfo.hProcess, INFINITE);
GetExitCodeProcess(ProcessInfo.hProcess, Res);
end
else
begin
self.fAppWnd := ProcessInfo.hProcess;
Windows.SetParent(self.fAppWnd, self.Handle);
ShowWindow(self.fAppWnd, SW_SHOWMAXIMIZED);
CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread);
end;
result := true;
end
else begin
Result := false;
end;
end;
POR FAVOR NO CORRER ENCIMA DE CÓDIGO! Produce resultados extraños que implican elegir una ventana aparentemente aleatoria en todas las aplicaciones en ejecución e incrustar eso (incluso elementos de menú desde el menú de inicio de Windows ...)
Así que básicamente lo que necesito es cómo iniciar una aplicación, y agarrar un identificador a la ventana principal de las aplicaciones.
Cualquier ayuda es muy apreciada
Saludos
Jens Fudge
Un identificador de proceso no es un identificador de ventana. Ver http://stackoverflow.com/questions/1888863/how-to-get-main-window-handle-from-process-id –
Leyendo el título, estaba a punto de entrar e insistir en que esto * debe * ser un duplicar, pero después de ver que está integrando esta aplicación en la suya, eso lo diferencia. Gran pregunta –
No agregue firmas a su publicación. [StackOverflow ya muestra uno para usted] (http://stackoverflow.com/faq#signatures). – Deanna