How to show a secondary form on taskbar using FMX C++?

左心房为你撑大大i 提交于 2020-01-06 23:43:13

问题


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:


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++



来源:https://stackoverflow.com/questions/28929163/how-to-show-a-secondary-form-on-taskbar-using-fmx-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!