2015-03-08 47 views
0

我在試圖在同一時間在任務欄上顯示多個表單時遇到了一些問題。 我發現我需要使用以下命令:如何使用FMX C++在任務欄上顯示輔助表單?

WS_EX_APPWINDOW 

所以我尋找多一點有關,然後找到它:

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; 
} 

但是,這種功能與VCL工作得(TCreateParams是不是成員Fmx :: Controls)。

所以,我更再次搜索一點點,發現它(此功能發生在OnCreate中表單功能):

SetWindowLong(Handle, GWL_EXSTYLE, WS_EX_APPWINDOW); 

但我得到了一些錯誤說法如下:

[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 *) 

待辦事項你知道有其他方法可以做到嗎? 如果你能幫助我,那麼從現在開始,謝謝!

回答

1

您顯示的代碼片段僅適用於VCL。

FireMonkey不允許您像VCL那樣自定義窗體HWND的創建。 HWND創建隱藏在FireMonkey內部使用的專用接口後面(TPlatformWin.CreateWindow())。這就是FireMonkey中沒有CreateParams的原因。

但是,您仍然可以訪問HWND,但只能在創建之後。有一個WindowHandleToPlatform()功能(取代舊功能FmxHandleToHWND())和一個FormToHWND功能(內部使用WindowHandleToPlatform())。所有這些功能都是針對Windows的,因此如果您正在編寫在多個平臺上運行的FireMonkey代碼,則必須使用#ifdef來包裝它們。

試試這個:

#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 

另見:

example of embarcadero WindowHandleToPlatform c++

+0

非常感謝,它的工作。然而,在條件(if)結構中存在一個錯誤,它不是「hWnd! - NULL」是「hWnd!= NULL」。所以,這就是我想說的: if(hWnd!= NULL) – mauroaraujo 2015-03-08 22:11:31

相關問題