根据“向另一个进程嵌入窗口”问题,我正在将只有TWebBrowser组件的应用程序嵌入到我的主应用程序中。即使我将其嵌入到TScrollBox组件中,当主应用程序调整大小时,滚动条也不会出现。我已经对此问题进行了一些研究,但没有成功。如何启用滚动框的滚动条?
LE:为了澄清问题:应用程序A是一个简单的表单,上面有一个TWebBrowser组件。应用程序B,即主应用程序,将应用程序A嵌入到放置在表单上且Align属性设置为alClient的TScrollBox中。将应用程序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中。在OnPanelResize事件中运行以下代码:
if IsWindow(App_B_WindowHandle) then
SetWindowPos(App_B_WindowHandle, 0, 0, 0, Panel1.Width, Panel1.Height, SWP_ASYNCWINDOWPOS);