基于 Embedding window into another process问题,我在我的主应用程序中嵌入了一个在主窗体上只有一个TWebBrowser组件的应用程序.即使我将它嵌入到TScrollBox组件中,当主应用程序调整大小时,滚动条
LE:澄清问题:应用程序A是一个带有TWebBrowser组件的简单表单.应用程序B是主应用程序,它将应用程序A嵌入到放置在表单上的TScrollBox上,并将Align设置为alClient.将A嵌入B的代码
procedure ShowAppEmbedded(WindowHandle: THandle; Container: TWinControl); var WindowStyle : Integer; FAppThreadID: Cardinal; begin /// Set running app window styles. WindowStyle := GetWindowLong(WindowHandle, GWL_STYLE); WindowStyle := WindowStyle - WS_CAPTION - WS_BORDER - WS_OVERLAPPED - WS_THICKFRAME; SetWindowLong(WindowHandle,GWL_STYLE,WindowStyle); /// Attach container app input thread to the running app input thread, so that /// the running app receives user input. FAppThreadID := GetWindowThreadProcessId(WindowHandle, nil); AttachThreadInput(GetCurrentThreadId, FAppThreadID, True); /// Changing parent of the running app to our provided container control Windows.SetParent(WindowHandle,Container.Handle); SendMessage(Container.Handle, WM_UPDATEUISTATE, UIS_INITIALIZE, 0); UpdateWindow(WindowHandle); /// This prevents the parent control to redraw on the area of its child windows (the running app) SetWindowLong(Container.Handle, GWL_STYLE, GetWindowLong(Container.Handle,GWL_STYLE) or WS_CLIPCHILDREN); /// Make the running app to fill all the client area of the container SetWindowPos(WindowHandle,0,0,0,Container.ClientWidth,Container.ClientHeight,SWP_NOZORDER); SetForegroundWindow(WindowHandle); end;
调整主应用程序(B)的大小时,不会显示来自B的TScrollBox组件的滚动条,并且应用程序A停留在它上面是从请求设置的.
解决方案:根据Kobik的评论,应用程序A嵌入到与TScrollBox内的alClient对齐的TPanel内的应用程序B中.在OnPanelResize事件上运行以下代码:
if IsWindow(App_B_WindowHandle) then SetWindowPos(App_B_WindowHandle, 0, 0, 0, Panel1.Width, Panel1.Height, SWP_ASYNCWINDOWPOS);将VCL容器(例如TPanel)放入TScrollbox中.并将客户端应用程序嵌入Panel中.这样TScrollbox就能正确处理Panel.您不能简单地将嵌入式应用程序与Delphi容器对齐.您可能希望处理TPanel.OnResize以调整嵌入式应用程序的新维度(如果需要).
无论如何,正如你所知,整个想法都是痛苦的世界.