4
votes

I'm currently experimenting with Firemonkey and came across this. When having multiple forms in my application, I get the same amount of items in my windows menu bar for one application (see screenshot).

In regular VCL applications, there is only one item identifying the application (so my screenshot would only contain 'Form2' item).

Does anybody know how I can accomplish the same behaviour as a VCL application, so only one item for my multiple-form application???

multiple items

Thanks in advance!

Thijs

Edit: I managed to show the second form, with just one item at the bottom menu, but the property 'Transparency' of the form needs to be true! So in order to make the second form visible, a TRectangle needs to be placed in the second form (no frame with the caption and buttons are visible)...

1
Happens in Vista also... at least with fmx...Peter

1 Answers

3
votes

I found the workaround to this.

When you create a form with an owner, FireMonkey is supposed to pass the owner on down to the Windows CreateWindowEx function, but it does not.

In unit FMX.Platform.Win, in the CreateWindow() function, change this:

  Wnd := CreateWindowEx(ExStyle, WindowClass.lpszClassName, PChar(AForm.Caption), Style,
    Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT),
    GetDesktopWindow, 0, hInstance, nil);

To this:

  // If there's an owner, and it's a form, then create the window as a child
  if (AForm <> nil) and (AForm.Owner <> nil) and (AForm.Owner is TForm) then
  begin
    // Child window
    Wnd := CreateWindowEx(ExStyle, WindowClass.lpszClassName, PChar(AForm.Caption), Style,
      Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT),
      HandleToHWND(TForm(AForm.Owner).Handle), 0, hInstance, nil);
  end
  else
  begin
    // Desktop window
    Wnd := CreateWindowEx(ExStyle, WindowClass.lpszClassName, PChar(AForm.Caption), Style,
      Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT),
      GetDesktopWindow, 0, hInstance, nil);
  end;

So, if you're going to create a child, especially modal form, make sure that you assign the parent form as the owner when you create it like this:

MyModalForm := TMyModalForm.Create(MyParentForm);
MyModalForm.ShowModal;

Then, everything will work as expected, after the fix.

Don't forget to remove the child form from the list of Auto-create forms in your project settings.