主程序调用子程序(web控件在子程序中),如何保证web窗体显示在主程序给定的窗口内?现在不得不采用绑架的方式,结果又导致频繁出现脱离现象,而且绑架的方式也不能防假死。难道delphi无法开发多进程浏览器?请问用什么方法实现对子程序的调用?确保web窗体显示在主程序给定的窗口内,不脱离,还能防假死。

解决方案 »

  1.   

    delphi多线程用过两次,感觉没有直接用时间控件控制简单一些。看看能不能用其它的方式代替一下线程。
      

  2.   

    有两种方法:
    1、CreateProcess后,用个sleep等下;
    2、用WaitForInputIdle
      

  3.   

    其实有一个比较好的方法,如果能获取到子进程中主窗体的handle,那么说明子进程的主窗体创建完毕。
      
    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;
      

  4.   

    function CreateProcess(lpApplicationName: PChar; lpCommandLine: PChar;
      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;
    这样可以做到一个进程的窗体在另一个进程窗体中显示;浏览器防假死我也想知道啊,期待楼下大虾会有这方面的回复!