while GetProcessWindow(ProcessInfo.dwProcessID)=0 do begin Application.ProcessMessages; Sleep(10); end; // 由 ProcessID 查找窗体 Handle function GetProcessWindow(ProcessID: Cardinal): HWND; var ProcWndInfo: TProcessWindow; begin ProcWndInfo.ProcessID := ProcessID; ProcWndInfo.FoundWindow := 0; EnumWindows(@EnumWindowsProc, Integer(@ProcWndInfo)); // 查找窗体 Result := ProcWndInfo.FoundWindow; end;
1、CreateProcess后,用个sleep等下;
2、用WaitForInputIdle
while GetProcessWindow(ProcessInfo.dwProcessID)=0 do
begin
Application.ProcessMessages;
Sleep(10);
end;
// 由 ProcessID 查找窗体 Handle
function GetProcessWindow(ProcessID: Cardinal): HWND;
var
ProcWndInfo: TProcessWindow;
begin
ProcWndInfo.ProcessID := ProcessID;
ProcWndInfo.FoundWindow := 0;
EnumWindows(@EnumWindowsProc, Integer(@ProcWndInfo)); // 查找窗体
Result := ProcWndInfo.FoundWindow;
end;
lpProcessAttributes, lpThreadAttributes: PSecurityAttributes;
bInheritHandles: BOOL; dwCreationFlags: DWORD; lpEnvironment: Pointer;
lpCurrentDirectory: PChar; const lpStartupInfo: TStartupInfo;
var lpProcessInformation: TProcessInformation): BOOL; stdcall;
使用CreateProcess创建子进程,得到进程id
使用@whhitxjl提供的函数GetProcessWindow返回主窗体句柄
使用Windows.SetParent赐予它父子关系;
function SetParent(hWndChild, hWndNewParent: HWND): HWND; stdcall;
这样可以做到一个进程的窗体在另一个进程窗体中显示;浏览器防假死我也想知道啊,期待楼下大虾会有这方面的回复!