How to show a secondary form on taskbar using FMX

2019-09-01 06:34发布

I'm with a little problem when trying to show more than one form on taskbar on the same time. I found I need to use the following:

WS_EX_APPWINDOW

So I search a little bit more about and then found it:

class TForm2 : public TForm
{
__published:    // IDE-managed Components
private:        // User declarations
public:         // User declarations
        __fastcall TForm2(TComponent* Owner);
        void __fastcall CreateParams(Controls::TCreateParams &Params);

};

void __fastcall TForm2::CreateParams(Controls::TCreateParams &Params)
{
  TForm::CreateParams(Params);
  Params.ExStyle   = Params.ExStyle | WS_EX_APPWINDOW;
  Params.WndParent = ParentWindow;
}

However that function works just with VCL (TCreateParams is not a member of Fmx::Controls).

So, I search a little bit more again and found it (This function goes at OnCreate form function):

SetWindowLong(Handle, GWL_EXSTYLE, WS_EX_APPWINDOW); 

But I got something wrong saying the following:

[bcc32 Error] Codigo.cpp(19): E2034 Cannot convert 'TWindowHandle * const' to 'HWND__ *'
  Full parser context
    Codigo.cpp(18): parsing: void _fastcall TfrmCodigo::FormCreate(TObject *)
[bcc32 Error] Codigo.cpp(19): E2342 Type mismatch in parameter 'hWnd' (wanted 'HWND__ *', got 'TWindowHandle *')
  Full parser context
    Codigo.cpp(18): parsing: void _fastcall TfrmCodigo::FormCreate(TObject *)

Do you know any other alternative to do this? If you can help me or not, since now, thanks A LOT!

1条回答
贪生不怕死
2楼-- · 2019-09-01 06:47

The code snippets you have shown are for VCL only.

FireMonkey does not allow you to customize the creation of a Form's HWND like VCL does. The HWND creation is hidden behind a private interface that FireMonkey uses internally (TPlatformWin.CreateWindow()). That is why there is no CreateParams in FireMonkey.

However, you can still access the HWND, but only after it has been created. There is a WindowHandleToPlatform() function (which replaces the older FmxHandleToHWND() function), and a FormToHWND function (which uses WindowHandleToPlatform() internally). All of these functions are Windows-specific, so you have to wrap them with an #ifdef if you are writing FireMonkey code that runs on multiple platforms.

Try this:

#ifdef _Windows
#include <FMX.Platform.Win.hpp>
#endif

...

#ifdef _Windows
//HWND hWnd = FmxHandleToHWND(Form2->Handle);
//HWND hWnd = WindowHandleToPlatform(Form2->Handle)->Wnd;
HWND hWnd = FormToHWND(Form2);
if (hWnd != NULL)
{
    LONG Style = GetWindowLong(hWnd, GWL_EXSTYLE); // <-- don't forget this step!
    SetWindowLong(hWnd, GWL_EXSTYLE, Style | WS_EX_APPWINDOW); 
}
#endif

Also see:

example of embarcadero WindowHandleToPlatform c++

查看更多
登录 后发表回答