4

Based on the Embedding window into another process question I'm embedding an application which has only a TWebBrowser component on the main form, on my main application. Even I'm embedding it to a TScrollBox component the scroll bars don't appear when the main application is resizing. I've made some research on this issue, but without success. How can I enable the scrollbox's scrollbars?

LE: To clarify the question: Application A is a simple form with an TWebBrowser component on it. Application B, the main application, is embedding application A on a TScrollBox placed on a form, with Align set to alClient. Code for embedding A into 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; 

When resizing the main application(B), the scrollbars of the TScrollBox component from B are not showed and the application A rests at it was set from the begging.

Solution: Based on Kobik's comment the application A is embedded into app B inside a TPanel aligned to alClient inside a TScrollBox. On the OnPanelResize event the following code is run:

 if IsWindow(App_B_WindowHandle) then SetWindowPos(App_B_WindowHandle, 0, 0, 0, Panel1.Width, Panel1.Height, SWP_ASYNCWINDOWPOS); 
5
  • 1
    This just isn't going to work. Windows is not designed for such actions. Cross process window parenting stopped being reasonable over 20 years ago when Win32 was introduced. Commented Nov 10, 2015 at 12:17
  • @DavidHeffernan - I know David. Solution is working, but I agree with you that this should not be done like this. Commented Nov 10, 2015 at 12:21
  • It's unlikely to work properly. There's bound to be more probs that you have not found yet. Commented Nov 10, 2015 at 12:49
  • @DavidHeffernan, Google Chrome for example hosts each tab webpage in a different process. Commented Nov 10, 2015 at 12:58
  • It runs its own co-operative IPC to do that. Commented Nov 10, 2015 at 13:35

1 Answer 1

1

Put a VCL container (e.g. TPanel) inside the TScrollbox. and embed the client application inside the Panel. This way the TScrollbox will be able to handle the Panel correctly. You cannot simply Align the embedded application inside a Delphi container. You might want to handle the TPanel.OnResize to adjust a new dimensions for the the embedded application (if needed).

In any case, as you already know, the whole idea is a world of pain.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.