2017-03-19 40 views
-2

スタイルの色管理をオーバーライドするために、C++ Builder XE7でTEditのスタイルフックを作成する必要があります。次のようにDelphi exampleがあります。誰かがC++ Builder(フックユニット、登録、サンプルフォーム)で完全なサンプルを投稿できましたか?ありがとう!C++ BuilderでStyleHookを使用する

+0

は、私は、Delphiの例 –

+0

を翻訳します共感しますが、私たちは翻訳サービスではありません。このようなコードを翻訳するには、十分なDelphiを学ぶ必要があります。あなたがそうするまで、C++ Builderは非常に不満なツールになるでしょう。 – Giovanni

+0

Iを変換することができませんので、質問を投稿Delphiの例 –

答えて

1

Delphiの例の翻訳は、次のようになります

class TEditStyleHookColor : public TEditStyleHook 
{ 
    typedef TEditStyleHook inherited; 
private: 
    void UpdateColors(); 
protected: 
    virtual void __fastcall WndProc(TMessage &Message); 
public: 
    __fastcall TEditStyleHookColor(TWinControl *AControl); 
}; 

#include <Vcl.Styles.hpp> 

class TWinControlH : public TWinControl {}; 

__fastcall TEditStyleHookColor::TEditStyleHookColor(TWinControl *AControl) 
    : TEditStyleHook(AControl) 
{ 
    //call the UpdateColors method to use the custom colors 
    UpdateColors(); 
}; 

//Here you set the colors of the style hook 
void TEditStyleHookColor::UpdateColors() 
{ 
    if (Control->Enabled) 
    { 
     Brush->Color = (static_cast<TWinControlH*>(Control)->Color; //use the Control color 
     FontColor = static_cast<TWinControlH*>(Control)->Font->Color;//use the Control font color 
    } 
    else 
    { 
     //if the control is disabled use the colors of the style 
     TCustomStyleServices *LStyle = StyleServices(); 
     Brush->Color = LStyle->GetStyleColor(scEditDisabled); 
     FontColor = LStyle->GetStyleFontColor(sfEditBoxTextDisabled); 
    } 
} 

//Handle the messages of the control 
void __fastcall TEditStyleHookColor::WndProc(TMessage &Message) 
{ 
    switch (Message.Msg) 
    { 
     case CN_CTLCOLORMSGBOX: 
     case CN_CTLCOLORSCROLLBAR: 
     case CN_CTLCOLORSTATIC: 
     { 
      //Get the colors 
      UpdateColors(); 
      SetTextColor(reinterpret_cast<HDC>(Message.WParam), ColorToRGB(FontColor)); 
      SetBkColor(reinterpret_cast<HDC>(Message.WParam), ColorToRGB(Brush->Color)); 
      Message.Result = reinterpret_cast<LRESULT>(Brush->Handle); 
      Handled = true; 
      break; 
     } 
     case CM_ENABLEDCHANGED: 
     { 
      //Get the colors 
      UpdateColors(); 
      Handled = false; 
      break; 
     } 
     default: 
      inherited::WndProc(Message); 
      break; 
    } 
} 

... 

TStyleManager::Engine->RegisterStyleHook(__classid(TEdit), __classid(TEditStyleHookColor)); 
TStyleManager::Engine->RegisterStyleHook(__classid(TMaskEdit), __classid(TEditStyleHookColor)); 
TStyleManager::Engine->RegisterStyleHook(__classid(TLabeledEdit), __classid(TEditStyleHookColor)); 
TStyleManager::Engine->RegisterStyleHook(__classid(TButtonedEdit), __classid(TEditStyleHookColor)); 
+0

レミー、それは本当にうまくいった。どうもありがとう! – Giovanni

関連する問題