Delphi Xe2 with Firemonkey : Can you have a non-client area that is painted in a style other than the default Windows nonclient paint style?
Asked Answered
H

3

14

Here is a sample of a delphi application I am making using firemonkey + Delphi XE2.

As you can see, you can use the visual style "stylebook" in Firemonkey to customize the appearance of most things inside the window frame. However the outside of the window frame is drawn using whatever style Windows decides. Now if I was using VCL instead of Firemonkey, I could apply "VCL Styles" and "skin" the whole VCL application in a dark color scheme.

My guess is that this is NOT YET posssible with Delphi XE2 + Firemonkey. Can anyone show how to do this?

enter image description here

At designtime, the "preview" of your form shows a nice black border. But when I run my app, the Windows XP "Luna" theme border (the blue parts in the picture below) looks atrocious. Ironically, the VCL is prettier (in XE2 with styles) than Firemonkey...

Hluchy answered 26/1, 2012 at 2:25 Comment(2)
Yes. I didn't find any video, image or tutorial of a Firemonkey style applied in runtime on a windows frame. I suppose is not possible yet (or at least not without "ninja" skills)Mathre
It also seems it is not possible to apply styles to TMainMenu yet.Hluchy
Y
4

You can create a VCL Forms application as usual, with styles if you like, at runtime load your Firemonkey form and set your VCL form as its parent:

uses
  FMX.Platform.Win, FMX.Forms,
  Unit2;

procedure TForm1.FormCreate(Sender: TObject);
var
  Form2: TForm2;
begin
  Form2 := TForm2.Create(nil);
  Form2.BorderStyle := FMX.Forms.TFmxFormBorderStyle.bsNone;
  Form2.SetBounds(0, 0, ClientWidth, ClientHeight);
  Winapi.Windows.SetParent(FmxHandleToHWND(Form2.Handle), Handle);
  Form2.Show;
end;

In the following screenshot, Form1 is the VCL application main form (with Carbon style) and the dark-grey area with the button is the embedded Firemonkey form:

Firemonkey form embedded in a VCL form

Note that I'm not handling resizing of the parent window - it should resize the emebedded form, too, emulating alClient alignment. It seems there are many potential problems with this approach - I think there's a reason why the IDE doesn't let you easily mix Firemonkey forms with VCL forms - it warns about possible "compilation errors or unexpected behavior."

Youngstown answered 27/1, 2012 at 9:38 Comment(3)
Nice idea! Perhaps in a future version of Delphi, they might adapt the codebase of VCL styles to allow skinning the nonclient area of a firemonkey app, at least on windows.Hluchy
Agreed, nice idea! Just one drawback: It is not a Firemonkey application anymore...Mathre
This is now working out of the box in XE3 and later. #12720249Hluchy
J
2

Firemonkey is cross platform. By and large you cannot do anything that is platform dependent within the FMX framework itself. You can however make calls to the underlying platform (be it windows, OSX or iOS) to access platform specific functionality. This should be done within conditionally compiled code.

eg.

{$IF DCC}
  something;
{$ENDIF}

{$IF FPC}
  somethingelse;
{$ENDIF}

Looking at it from another viewpoint, it may be possible for you do do all of your FMX work on a TRectangle (for example), then use AddObject (or assign its parent), to a VCL form.

Jenness answered 27/1, 2012 at 8:7 Comment(0)
T
0

If you change the forms BorderStyle to bsNone, you can add whatever chrome you want. You will, of course, need to manually handle maximise, minimise, close, resize etc actions.

Toh answered 26/1, 2012 at 21:34 Comment(1)
That's still not even going to work, because it will remove the window from the list of application windows. BorderStyle=bsNone also sets WS_POPUP on Windows.Hluchy

© 2022 - 2024 — McMap. All rights reserved.