Delphi - 嵌入式应用程序滚动条不可见

Delphi - embedded application scrollbars not visible

基于 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 嵌入到应用程序 B 内的 TPanel 中,与 TScrollBox 内的 alClient 对齐。在 OnPanelResize 事件中,以下代码是 运行:

  if IsWindow(App_B_WindowHandle) then
    SetWindowPos(App_B_WindowHandle, 0, 0, 0, Panel1.Width, Panel1.Height, SWP_ASYNCWINDOWPOS);

将 VCL 容器(例如 TPanel)放入 TScrollbox。并将客户端应用程序嵌入到面板中。这样 TScrollbox 将能够正确处理面板。您不能简单地将嵌入式应用程序对齐到 Delphi 容器内。您可能想要处理 TPanel.OnResize 以调整嵌入式应用程序的新尺寸(如果需要)。

无论如何,如你所知,整个想法是一个痛苦的世界。