V
vvyang
Unregistered / Unconfirmed
GUEST, unregistred user!
1、我用 CreateProcess 启动了一个外部程序,紧接着用 FindWindow 来取得该程序主窗口的句柄,但是发现只要外部程序启动得稍微慢一些便无法找到主窗口。程序片段如下:<br>function EmbedWindow(lpApplicationName, lpClassName, lpWindowName: PChar;<br> hWndParent: HWND): THandle;<br>var<br> lpStartupInfo: _STARTUPINFOA;<br> lpProcessInfo: _PROCESS_INFORMATION;<br> hWndChild: HWND;<br>begin<br> FillChar(lpStartupInfo, SizeOf(lpStartupInfo), 0);<br> lpStartupInfo.cb := SizeOf(StartupInfo);<br> CreateProcess(lpApplicationName, nil, nil, nil, False, DETACHED_PROCESS,<br> nil, nil, lpStartupInfo, lpProcessInfo);<br> Result := lpProcessInfo.hProcess;<br> WaitForInputIdle(Result, INFINITE);<br><br> //这里怎样判断主窗口已经初始化完毕<br> hWndChild := FindWindow(lpClassName, lpWindowName);<br><br>{ 这是无奈写的低效代码,倒也能解决问题<br> hWndChild := 0;<br> while hWndChild = 0 do<br> begin<br> hWndChild := FindWindow(lpClassName, lpWindowName);<br> Application.ProcessMessages;<br> end;<br>}<br> ......<br>end;<br>2、各位给点意见,帮个忙。