Question

The short version -

I have an OpenGL Window which is created using WinApi calls. I would prefer to keep it this way, instead of wrapping OpenGL into a VCL Form.

To provide some preference menus and file dialogs, I resorted to using VCL forms, and the typical dialogs (TOpenDialog, TSaveDialog).

What I'm wondering is - how do I get these Forms and Dialogs to see my OpenGL Window as their owner?

I have attempted to pass my window handle over to the forms, but I feel certain that I'm doing this improperly, as it has no effect.

Form1 := TForm1.Create(nil);   
Form1.ParentWindow := hwnd; //handle to OpenGL Window

What is it that a VCL form requires in order to see a native window as it's owner?

The Long Version -

My application has two modes. Standalone mode, where it runs by itself. Secondarily, there's a Plugin Mode that runs in the process space of a host application.

When in standalone mode, I have no issues with the VCL forms and Dialogs. Even though their ownership is uncertain, it doesn't affect usability in any way.

When in plugin mode, I am finding that the host application will take control of my VCL Forms, and the Open&Save Dialogs.

So, when running in a host's process space, my VCL Forms are rendered very strangely. I've attempted to repair them manually, but they will not respond to style changes.

Edit - Details on Dialogs

My main concern is the rendering of the VCL Forms, but here are some more details on the Dialogs, if it's of any use.

I'm executing dialogs like this:

if FileOpenDialog.Execute(hwnd) then
Begin
  //open up file
End;

And it has no effect. The dialog will act the same as though I had not passed a handle to it. Bear in mind that I am using Delphi 2006, and this version of Delphi is still utilizing the old file dialogs, which were introduced in Windows XP.

Finally - when running as a Plugin, my Open/Save dialogs will appear as though they belong to the host application on the taskbar. So, the host has a taskbar Tab. My application also has it's own Tab. My Open Dialog appears attached to the Host's Tab, when I execute it.

Images

Preference Menu In Standalone Mode:

Preference Menu In Standalone Mode

Preference Menu as Plugin in Host:

Preference Menu In Host

If I could simply change the color of the black text, that would be good enough, but I can't seem to do it.

Was it helpful?

Solution

For the VCL forms you need to override CreateParams and set Params.WndParent to the owning window. That will be your OpenGL window as I understand.

procedure TMyForm.CreateParams(var Params: TCreateParams);
begin
  inherited;
  Params.WndParent := MyOpenGLWindow;
end;

The common dialog classes have an Execute overload that receives a window handle. Pass the handle of your OpenGL window and that OpenGL window will be the owner window of the dialog.

On the subject of your forms rendering strangely it's hard to give definitive advice. My guess is that the strangeness is due to the host app not enabling themes. If you control the host fix it there. Otherwise you need to use activation contexts. My answer to this question gives sample code: Possible to do runtime optional toggling of **runtime themes** by adding an application manifest at runtime?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top