238 lines
8.5 KiB
MQL5
238 lines
8.5 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| ColorPanel.mqh |
|
|
//| Copyright 2019, MetaQuotes Software Corp. |
|
|
//| https://www.mql5.com |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "Copyright 2019, MetaQuotes Software Corp."
|
|
#property link "https://www.mql5.com"
|
|
#property version "1.00"
|
|
#property strict
|
|
|
|
#ifdef __MQL5__
|
|
#include <Controls\AppDialog.mqh>
|
|
#else
|
|
#include <Controls\Dialog.mqh>
|
|
#endif
|
|
|
|
#include <Controls\Button.mqh>
|
|
|
|
#define XRGB(r,g,b) (0xFF000000|(uchar(r)<<16)|(uchar(g)<<8)|uchar(b))
|
|
#define GETRGB(clr) ((clr)&0xFFFFFF)
|
|
|
|
#define INDENT_LEFT (11) // indent from left (with allowance for border width)
|
|
#define INDENT_TOP (11) // indent from top (with allowance for border width)
|
|
#define CONTROLS_GAP_X (5) // gap by X coordinate
|
|
//--- for buttons
|
|
#define BUTTON_WIDTH (100) // size by X coordinate
|
|
#define BUTTON_HEIGHT (20) // size by Y coordinate
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
class CColorPanel : public CAppDialog
|
|
{
|
|
private:
|
|
CButton m_button1;
|
|
CButton m_button2;
|
|
|
|
long m_testchartid;
|
|
color m_testcolor;
|
|
|
|
public:
|
|
CColorPanel();
|
|
~CColorPanel();
|
|
virtual bool Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2);
|
|
virtual bool OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam);
|
|
virtual void OnTimerEvent(void);
|
|
void FensterAuslesen(void);
|
|
|
|
protected:
|
|
bool CreateButton1(void);
|
|
void OnClickButton1(void);
|
|
|
|
bool CreateButton2(void);
|
|
void OnClickButton2(void);
|
|
|
|
};
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
EVENT_MAP_BEGIN(CColorPanel)
|
|
ON_EVENT(ON_CLICK,m_button1,OnClickButton1)
|
|
ON_EVENT(ON_CLICK,m_button2,OnClickButton2)
|
|
EVENT_MAP_END(CAppDialog)
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
CColorPanel::CColorPanel()
|
|
{
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
CColorPanel::~CColorPanel()
|
|
{
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
bool CColorPanel::Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2)
|
|
{
|
|
//--- call method of parent class
|
|
if(!CAppDialog::Create(chart,name,subwin,x1,y1,x2,y2))
|
|
return(false);
|
|
//--- create dependent controls
|
|
|
|
if(!CreateButton1())
|
|
return(false);
|
|
if(!CreateButton2())
|
|
return(false);
|
|
//---
|
|
|
|
// if(!m_panel_flag && !CreateWhiteBorder())
|
|
// return(false);
|
|
// if(!CreateBackground())
|
|
// return(false);
|
|
// if(!CreateCaption())
|
|
// return(false);
|
|
// if(!CreateButtonClose())
|
|
// return(false);
|
|
// if(!CreateClientArea())
|
|
// return(false);
|
|
////--- set up additional areas
|
|
// m_norm_rect.SetBound(m_rect);
|
|
////--- succeed
|
|
return(true);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Create the "Button1" button |
|
|
//+------------------------------------------------------------------+
|
|
bool CColorPanel::CreateButton1(void)
|
|
{
|
|
//--- coordinates
|
|
int x1=INDENT_LEFT; // x1 = 11 pixels
|
|
int y1=INDENT_TOP; // y1 = 11 pixels
|
|
int x2=x1+BUTTON_WIDTH; // x2 = 11 + 100 = 111 pixels
|
|
int y2=y1+BUTTON_HEIGHT; // y2 = 11 + 20 = 32 pixels
|
|
//--- create
|
|
if(!m_button1.Create(0,"Button1",0,x1,y1,x2,y2))
|
|
return(false);
|
|
if(!m_button1.Text("Client Color"))
|
|
return(false);
|
|
if(!Add(m_button1))
|
|
return(false);
|
|
//--- succeed
|
|
return(true);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Create the "Button2" button |
|
|
//+------------------------------------------------------------------+
|
|
bool CColorPanel::CreateButton2(void)
|
|
{
|
|
//--- coordinates
|
|
int x1=INDENT_LEFT+BUTTON_WIDTH+CONTROLS_GAP_X; // x1 = 11 + 100 + 5 = 116 pixels
|
|
int y1=INDENT_TOP; // y1 = 11 pixels
|
|
int x2=x1+BUTTON_WIDTH; // x2 = 11 + 100 = 111 pixels
|
|
int y2=y1+BUTTON_HEIGHT; // y2 = 11 + 20 = 32 pixels
|
|
//--- create
|
|
if(!m_button2.Create(0,"Button2",0,x1,y1,x2,y2))
|
|
return(false);
|
|
if(!m_button2.Text("Caption Color"))
|
|
return(false);
|
|
if(!Add(m_button2))
|
|
return(false);
|
|
//--- succeed
|
|
return(true);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Event handler |
|
|
//+------------------------------------------------------------------+
|
|
void CColorPanel::OnClickButton1(void)
|
|
{
|
|
// string prefix=Name();
|
|
// int total=testPanel.ControlsTotal();
|
|
// for(int i=0;i<total;i++)
|
|
// {
|
|
// CWnd*obj=testPanel.Control(i);
|
|
// string name=obj.Name();
|
|
// //---
|
|
// if(name==prefix+"Client")
|
|
// {
|
|
// CWndClient *wndclient=(CWndClient*) obj;
|
|
// color clr=(color)GETRGB(XRGB(rand()%255,rand()%255,rand()%255));
|
|
// //wndclient.ColorBackground(clr);
|
|
//
|
|
// ChartRedraw();
|
|
// return;
|
|
// }
|
|
// }
|
|
//CWndClient *wndclient=testPanel.Control(m_testchartid);
|
|
color clr=(color)GETRGB(XRGB(rand()%255,rand()%255,rand()%255));
|
|
testPanel.Control((int) m_testchartid).ColorBackground(clr);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Event handler |
|
|
//+------------------------------------------------------------------+
|
|
void CColorPanel::OnClickButton2(void)
|
|
{
|
|
string prefix=Name();
|
|
int total=testPanel.ControlsTotal();
|
|
for(int i=0;i<total;i++)
|
|
{
|
|
CWnd*obj=testPanel.Control(i);
|
|
string name=obj.Name();
|
|
//---
|
|
if(name==prefix+"Caption")
|
|
{
|
|
CEdit *edit=(CEdit*) obj;
|
|
color clr=(color)GETRGB(XRGB(rand()%255,rand()%255,rand()%255));
|
|
edit.ColorBackground(clr);
|
|
ChartRedraw();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
void CColorPanel::OnTimerEvent(void)
|
|
{
|
|
//---
|
|
bool schleife=true;
|
|
long i=0;
|
|
i=(long)m_testcolor;
|
|
while(schleife)
|
|
{
|
|
//Print("Bin in der schleife = "+(string)i);
|
|
Print("Farbnummer = "+(string)i+" Name ist = "+ColorToString((color)i,true));
|
|
//Sleep(2000);
|
|
if(i>=1000)
|
|
schleife=false;
|
|
else
|
|
i++;
|
|
}
|
|
m_testcolor=(color)i;
|
|
//Print(ColorToString(i,true));
|
|
Print("schleife beendet");
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
void CColorPanel::FensterAuslesen(void)
|
|
{
|
|
m_testcolor=0;
|
|
string prefix=Name();
|
|
int total=testPanel.ControlsTotal();
|
|
for(int i=0;i<total;i++)
|
|
{
|
|
CWnd*obj=testPanel.Control(i);
|
|
string namee=obj.Name();
|
|
//---
|
|
if(namee==prefix+"Client")
|
|
{
|
|
CWndClient *wndclient=(CWndClient*) obj;
|
|
//color clr=(color)GETRGB(XRGB(rand()%255,rand()%255,rand()%255));
|
|
//wndclient.ColorBackground(clr);
|
|
m_testchartid=wndclient.Id();
|
|
Print("Chart-ID = "+(string)m_testchartid);
|
|
ChartRedraw();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
//+------------------------------------------------------------------+
|