CAppDialogとボタンなどのコンポーネントに色設定をしてみたいと思います
color
色の指定は、カラー型の color を使い
以下のような方法を使います
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
color clr; // RGBをC''に10進数、16進数で色を指定 clr = C'125, 125, 125'; // Gray clr = C'0x00, 0x00, 0xFF'; // Blue // 定義されたWebカラー名を指定 clr = clrRed; // Red clr = clrYellow; // Yellow // そのまま10進数、16進数で色を指定 clr = 0xFFFFFF; // White clr = 16777215; // White clr = 0x008000; // Green clr = 32768; // Green |
CAppDialog 色設定
CAppDialog の色設定ではmその階層構造を理解しておく必要があります
パネル前面はClientで覆われています
Backで残りのパネルをほぼカバーしBorderはあまり影響がでません
また、Captionにはタイトルがありここは独立しています
ただ、隣のMin/Max Closeアイコンの領域はBackになります
例として、それぞれに簡単な色設定をしてみます
setDialogColor(void) というメソッドを作り
コントロールはいろいろな名前があるので、BackやClientなどでコントロールを探し
ColorBackground()を使って色設定をします
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
class CTestPanel : public CAppDialog{ private: CEdit testEdit; CButton okButton; CLabel testLabel; public: CTestPanel(void){}; ~CTestPanel(void){}; //--- create virtual bool Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2); void setDialogColor(void); ... } ... void CTestPanel::setDialogColor(void){ string prefix=Name(); int total=ControlsTotal(); for(int i=0;i<total;i++){ CWnd*obj=Control(i); string name=obj.Name(); if(name==prefix+"Border"){ CPanel *panel=(CPanel*) obj; panel.ColorBackground(clrAqua); // panel.ColorBorder(clrBlue); ChartRedraw(); } if(name==prefix+"Caption"){ CEdit *edit=(CEdit*) obj; edit.ColorBackground(clrAqua); edit.Color(clrBlue); ChartRedraw(); } if(name==prefix+"Back"){ CPanel *panelB=(CPanel*) obj; panelB.ColorBackground(clrYellow); // panelB.ColorBorder(clrRed); ChartRedraw(); } if(name==prefix+"Client"){ CWndClient *wndclient=(CWndClient*) obj; wndclient.ColorBackground(C'200,255,220'); // wndclient.ColorBorder(clrRed); ChartRedraw(); } } } ... int OnInit(){ if(!TPanel.Create( ChartID(), "TestPanel", 0, 160, 40, 360, 210 )){ return(INIT_FAILED); } TPanel.setDialogColor(); ... } |
尚、CAppDialogの最小化、終了アイコンの背景はBackと同じになるので(ここでは黄色)
どれかの色に合わせたほうがいいかもしません
CEdit, CBUtton, CLabel 色設定
CEdit や CBUtton などの色設定はそれぞれのCreateでColorBackground()から色設定ができます
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
// CEdit bool CTestPanel::CreateEdit(void){ if(!testEdit.Create(m_chart_id, "Edit01", m_subwin, 45, 26, 145, 46)) return(false); // allow editing if(!testEdit.ReadOnly(false)) return(false); if(!testEdit.Text("Enter text")) return(false); if(!testEdit.Color(C'0,0,0')) return(false); if(!testEdit.ColorBackground(C'220,255,200')) return(false); if(!testEdit.ColorBorder(clrGreen)) return(false); if(!Add(testEdit)) return(false); return(true); } // CButton bool CTestPanel::CreateButton(void){ if(!okButton.Create(m_chart_id, "Button01", m_subwin, 45, 56, 145, 76)) return(false); if(!okButton.Text("OK")) return(false); if(!okButton.Color(C'255,255,255')) return(false); if(!okButton.ColorBackground(C'200,180,255')) return(false); if(!okButton.ColorBorder(C'0,0,255')) return(false); if(!Add(okButton)) return(false); return(true); } // CLabel bool CTestPanel::CreateLabel(void){ if(!testLabel.Create(m_chart_id, "Label", m_subwin, 45, 86, 145, 106)) return(false); if(!testLabel.Text("")) return(false); if(!testLabel.Color(clrRed)) return(false); if(!Add(testLabel)) return(false); return(true); } |
ColorBorder()を使えばよりわかりやすくすることができます
サンプルコード
以下、まとめたコードになります
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
#include <Controls\Dialog.mqh> #include <Controls\Edit.mqh> #include <Controls\Button.mqh> #include <Controls\Label.mqh> class CTestPanel : public CAppDialog{ private: CEdit testEdit; CButton okButton; CLabel testLabel; public: CTestPanel(void){}; ~CTestPanel(void){}; //--- create virtual bool Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2); void setDialogColor(void); protected: bool CreateEdit(void); bool CreateButton(void); void OnClickButton(void); bool CreateLabel(void); // Event Handler EVENT_MAP_BEGIN(CTestPanel) ON_EVENT(ON_CLICK, okButton, OnClickButton) EVENT_MAP_END(CAppDialog) }; bool CTestPanel::Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2){ if(!CAppDialog::Create(chart, name, subwin, x1, y1, x2, y2)) return(false); if(!CreateEdit()) return(false); if(!CreateButton()) return(false); if(!CreateLabel()) return(false); return(true); } bool CTestPanel::CreateEdit(void){ if(!testEdit.Create(m_chart_id, "Edit01", m_subwin, 45, 26, 145, 46)) return(false); // allow editing if(!testEdit.ReadOnly(false)) return(false); if(!testEdit.Text("Enter text")) return(false); if(!testEdit.Color(C'0,0,0')) return(false); if(!testEdit.ColorBackground(C'220,255,200')) return(false); if(!testEdit.ColorBorder(clrGreen)) return(false); if(!Add(testEdit)) return(false); return(true); } bool CTestPanel::CreateButton(void){ if(!okButton.Create(m_chart_id, "Button01", m_subwin, 45, 56, 145, 76)) return(false); if(!okButton.Text("OK")) return(false); if(!okButton.Color(C'255,255,255')) return(false); if(!okButton.ColorBackground(C'200,180,255')) return(false); if(!okButton.ColorBorder(C'0,0,255')) return(false); if(!Add(okButton)) return(false); return(true); } bool CTestPanel::CreateLabel(void){ if(!testLabel.Create(m_chart_id, "Label", m_subwin, 45, 86, 145, 106)) return(false); if(!testLabel.Text("")) return(false); if(!testLabel.Color(clrRed)) return(false); if(!Add(testLabel)) return(false); return(true); } void CTestPanel::OnClickButton(){ string inputString = testEdit.Text(); testLabel.Text(inputString); Print("Inpput: ", inputString); } void CTestPanel::setDialogColor(void){ string prefix=Name(); int total=ControlsTotal(); for(int i=0;i<total;i++){ CWnd*obj=Control(i); string name=obj.Name(); if(name==prefix+"Caption"){ CEdit *edit=(CEdit*) obj; edit.ColorBackground(clrAqua); edit.Color(clrBlue); ChartRedraw(); } if(name==prefix+"Border"){ CPanel *panel=(CPanel*) obj; panel.ColorBackground(clrAqua); //panel.ColorBorder(clrBlue); ChartRedraw(); } if(name==prefix+"Back"){ CPanel *panelB=(CPanel*) obj; panelB.ColorBackground(clrYellow); //panelB.ColorBorder(clrRed); ChartRedraw(); } if(name==prefix+"Client"){ CWndClient *wndclient=(CWndClient*) obj; wndclient.ColorBackground(C'200,255,220'); //wndclient.ColorBorder(clrRed); ChartRedraw(); } } } CTestPanel TPanel; int OnInit(){ if(!TPanel.Create( ChartID(), "TestPanel", 0, 160, 40, 360, 210 )){ return(INIT_FAILED); } TPanel.setDialogColor(); TPanel.Run(); return(INIT_SUCCEEDED); } void OnDeinit(const int reason){ TPanel.Destroy(reason); } void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam ){ TPanel.ChartEvent(id, lparam, dparam, sparam); } |
実行するとパネルの色設定ができます
コメントアウトしている
ColorBorder() にて枠線色を入れることもできます