c++c++builderfiremonkey-fm3c++builder-xe6

How to get the screen size with C++ builder (Firemonkey)


I know it is a stupid question, but when changing visual libraries I found a "throuble" with FMX... My problem is: I need to do my own border, so I set the propriety to Border Style:"None", but the application runs in full screen, also covering the windows toolbar, so I would like a way to resize the application form according to the screen eg.:

mainForm->Height = Screen->Height - 10;

It is possible using VCL, but are there any way to do it using FMX library? The maximum I conquested with FMX is (I don't know how does it returns values, and the kind of values):

Screen->Size(); // TSize

I've also conquested it now, but I have compiler error:

TSize* Tamanho = new TSize;
Tamanho = Screen->Size();
frmPrincipal->Width = Tamanho->Width;
frmPrincipal->Height = Tamanho->Height - 10;

Error:"E2034 Cannot covert 'TSize' to 'TSize*'"

Finally I've tried to put it on frmPrincipal.h, but the same error:

TSize *Tamanho;

PS.: Other possible solutions to solve the "main problem" are acceptable...

Thanks a LOT!


Solution

  • TScreen::Size() return an actual instance of the TSize struct, not a TSize* pointer. You need to change your code accordingly:

    TSize Tamanho = Screen->Size();
    frmPrincipal->Width = Tamanho.Width;
    frmPrincipal->Height = Tamanho.Height - 10;
    

    Alternatively, you can use FMX's Platform Services framework to access the IFMXScreenService interface directly (this is what TScreen::Size() uses internally):

    _di_IInterface Intf;
    if (TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXScreenService), Intf))
    {
        _di_IFMXScreenService Svc = Intf; 
        TPoint size = Svc->GetScreenSize().Round();
        frmPrincipal->Width = size.X;
        frmPrincipal->Height = size.Y - 10;
    }