TRUE parenting of a Firemonkey form within ANOTHER Firemonkey Form

  

I am using Firemonkey and OpenGL and while I have no problem creating an openGL context for an entire window, I need to be able to take that window (with its GL Context) and truly parent it to another window so that it moves and resizes along with it.

I know that very similar questions have been asked about parenting FMX forms, but I cannot use the standard pseudo-embedding answer where you transfer the parenting of all the contents of one form to the other form as I require the handle and the DC of the original form.

The following straight-forward code that used to work (pre-Berlin) is not working in Berlin.

Winapi.Windows.SetParent(WindowHandleToPlatform(ChildForm).Wnd, WindowHandleToPlatform(TargetParentForm).Wnd);

The above seems to have no effect at all and when I do a sanity check and call GetParent on the ChildForm’s HWND after running it, I get a return of 0, unparented.

I found a code fragment that showed I needed to play games with the GWL_STYLE, to wit:

ChildHandle := WindowHandleToPlatform(ChildForm).Wnd;
TargetParent := WindowHandleToPlatform(ParentForm).Wnd;
Winapi.Windows.SetWindowLong(ChildHandle , GWL_STYLE,Winapi.Windows.GetWindowLong(ChildHandle , GWL_STYLE) and not (WS_POPUP OR WS_CHILD));
Winapi.Windows.SetParent(ChildHandle , TargetParent );
Winapi.Windows.SetWindowLong(ChildHandle , GWL_STYLE, Winapi.Windows.GetWindowLong(TrueHandle, GWL_STYLE) or WS_CHILD);
Winapi.Windows.SetParent(ChildHandle , TargetParent );

…and while this does appear to succeed (in that running GetParent on the ChildHandle after this DOES return a handle), the actual result is unfortunately still the same; the “Child Form” is not parented.

I’m sure this has to be possible because at worked in pre-Berlin versions, but I cannot figure out how to do it now. Any help or insight would be greatly appreciated.

Comments are closed.