我在主窗体上使用 PageControl 作为其他窗体的停靠站点。
其中一种形式,fPanelSonar,有一个面板,用作我加载的第 3 方应用程序的容器,如下所示:
var
i : Integer;
ExecutePingViewer : string;
sePingViewer,seOVREC: TShellExecuteInfo;
begin
Timer1.Enabled := False;
fPanelSonar.hdlPing360 := FindWindow(nil, PChar('Ping Viewer - v2.0.4'));
if fPanelSonar.hdlPing360 = 0 then
begin
ExecutePingViewer:='C:\Program Files (x86)\Oceanvault\pingviewer_release\deploy\pingviewer.exe';
FillChar(sePingViewer, SizeOf(sePingViewer), 0) ;
sePingViewer.cbSize := SizeOf(TShellExecuteInfo) ;
with sePingViewer do
begin
fMask := SEE_MASK_NOCLOSEPROCESS;
Wnd := 0;
lpFile := PChar(ExecutePingViewer) ;
nShow := SW_HIDE;
end;
if ShellExecuteEx(@sePingViewer) then
begin
fPanelSonar.hdlPing360 := FindWindow(nil, PChar('Ping Viewer - v2.0.4'));
Windows.SetParent(hdlPing360, pSonar.Handle);
ShowWindow(hdlPing360, SW_SHOWMAXIMIZED);
end
else ShowMessage('Error loading Ping360!') ;
end;
这很好用,我的第 3 方应用程序已按我的需要加载。
问题是当我将 fPanelSonar 放入 PageControl 时,即使它的进程“pingviewer.exe”仍在运行,第 3 方应用程序也会消失。
由于我保存了 hwnd fPanelSonar.hdlPing360 我应该能够再次将其设置回其父级,但它似乎虽然这个句柄是无效的,因为它不起作用。(即使我取消了它)。
此外,一旦我停靠/取消停靠,我就找不到任何其他手柄:
FindWindowEx(fPanelSonar.pSonar.Handle,0,nil, PChar('Ping Viewer - v2.0.4'));
我仍然可以使用我在论坛上找到的这个函数找到进程 ID,所以我知道它没有被杀死。(我也可以在窗口的任务管理器中看到它)
function GetPIDbyProcessName(processName:String):integer;
var
GotProcess: Boolean;
tempHandle: tHandle;
procE: tProcessEntry32;
begin
tempHandle:=CreateToolHelp32SnapShot(TH32CS_SNAPALL, 0);
procE.dwSize:=SizeOf(procE);
GotProcess:=Process32First(tempHandle, procE);
{$B-}
if GotProcess and (procE.szExeFile <> processName) then
repeat GotProcess := Process32Next(tempHandle, procE);
until (not GotProcess) or (procE.szExeFile = processName);
{$B+}
if GotProcess then
result := procE.th32ProcessID
else
result := 0; // process not found in running process list
CloseHandle(tempHandle);
end;
我试图找到带有进程 ID 的硬件,但它不起作用。
请注意,如果我在分配 pingviewer.exe 父级之前对接 fPanelSonar,它确实有效。
目前,我可以使用停靠/取消停靠事件来终止 pingviewer 进程并加载一个新进程,但这非常混乱......
所以我有点困惑为什么会发生这种情况以及如何正确解决它。
干杯,E。