基于将窗口嵌入到另一个流程问题中,我将在主应用程序的主窗体上嵌入一个只有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嵌入到应用程序B中,位于与TScrollBox中的alClient对齐的TPanel中。在OnPanelResize事件上,运行以下代码:
if IsWindow(App_B_WindowHandle) then
SetWindowPos(App_B_WindowHandle, 0, 0, 0, Panel1.Width, Panel1.Height, SWP_ASYNCWINDOWPOS);
在TScrollbox
中放入一个VCL容器(例如TPanel
)。并将客户端应用程序嵌入面板中。这样TScrollbox
将能够正确处理面板。您不能简单地在Delphi容器中对齐嵌入式应用程序。您可能需要处理TPanel.OnResize
以调整嵌入式应用程序的新维度(如果需要)。
无论如何,正如你已经知道的,整个想法是一个充满痛苦的世界。