//+------------------------------------------------------------------+
//| ControlsButton.mq5 |
//| Copyright 2000-2024, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property description "Panneaux de Contrôle et Dialogues. Classe de démonstration CButton"
#include <Controls\Dialog.mqh>
#include <Controls\Button.mqh>
//+------------------------------------------------------------------+
//| définition |
//+------------------------------------------------------------------+
//--- placement
#define INDENT_LEFT (11) // indentation depuis la gauche (avec respect de la largeur de la bordure)
#define INDENT_TOP (11) // indentation depuis la sommet (avec respect de la largeur de la bordure)
#define INDENT_RIGHT (11) // indentation depuis la droite (avec respect de la largeur de la bordure)
#define INDENT_BOTTOM (11) // indentation depuis le fond (avec respect de la largeur de la bordure)
#define CONTROLS_GAP_X (5) // coordonnée X du gap
#define CONTROLS_GAP_Y (5) // coordonnée Y du gap
//--- pour les boutons
#define BUTTON_WIDTH (100) // largeur
#define BUTTON_HEIGHT (20) // hauteur
//--- pour la zone d'indication
#define EDIT_HEIGHT (20) // hauteur
//--- pour les contrôles de type groupe
#define GROUP_WIDTH (150) // largeur
#define LIST_HEIGHT (179) // hauteur
#define RADIO_HEIGHT (56) // hauteur
#define CHECK_HEIGHT (93) // hauteur
//+------------------------------------------------------------------+
//| Class CControlsDialog |
//| Usage : dialogue principale de l'application des Contrôles |
//+------------------------------------------------------------------+
class CControlsDialog : public CAppDialog
{
private:
CButton m_button1; // Objet bouton
CButton m_button2; // Objet bouton
CButton m_button3; // Objet bouton fixe
public:
CControlsDialog(void);
~CControlsDialog(void);
//--- création
virtual bool Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2);
//--- gestionnaire d'évènement du graphique
virtual bool OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam);
protected:
//--- crée des contrôles dépendants
bool CreateButton1(void);
bool CreateButton2(void);
bool CreateButton3(void);
//--- gestionnaires des évènements de contrôle dépendants
void OnClickButton1(void);
void OnClickButton2(void);
void OnClickButton3(void);
};
//+------------------------------------------------------------------+
//| Gestionnaire d'évènement |
//+------------------------------------------------------------------+
EVENT_MAP_BEGIN(CControlsDialog)
ON_EVENT(ON_CLICK,m_button1,OnClickButton1)
ON_EVENT(ON_CLICK,m_button2,OnClickButton2)
ON_EVENT(ON_CLICK,m_button3,OnClickButton3)
EVENT_MAP_END(CAppDialog)
//+------------------------------------------------------------------+
//| Constructeur |
//+------------------------------------------------------------------+
CControlsDialog::CControlsDialog(void)
{
}
//+------------------------------------------------------------------+
//| Destructeur |
//+------------------------------------------------------------------+
CControlsDialog::~CControlsDialog(void)
{
}
//+------------------------------------------------------------------+
//| Création |
//+------------------------------------------------------------------+
bool CControlsDialog::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);
//--- crée des contrôles dépendants
if(!CreateButton1())
return(false);
if(!CreateButton2())
return(false);
if(!CreateButton3())
return(false);
//--- succès
return(true);
}
//+------------------------------------------------------------------+
//| Crée le bouton "Button1" |
//+------------------------------------------------------------------+
bool CControlsDialog::CreateButton1(void)
{
//--- coordonnées
int x1=INDENT_LEFT;
int y1=INDENT_TOP+(EDIT_HEIGHT+CONTROLS_GAP_Y);
int x2=x1+BUTTON_WIDTH;
int y2=y1+BUTTON_HEIGHT;
//--- création
if(!m_button1.Create(m_chart_id,m_name+"Button1",m_subwin,x1,y1,x2,y2))
return(false);
if(!m_button1.Text("Button1"))
return(false);
if(!Add(m_button1))
return(false);
//--- succès
return(true);
}
//+------------------------------------------------------------------+
//| Crée le bouton "Button2" |
//+------------------------------------------------------------------+
bool CControlsDialog::CreateButton2(void)
{
//--- coordonnées
int x1=INDENT_LEFT+(BUTTON_WIDTH+CONTROLS_GAP_X);
int y1=INDENT_TOP+(EDIT_HEIGHT+CONTROLS_GAP_Y);
int x2=x1+BUTTON_WIDTH;
int y2=y1+BUTTON_HEIGHT;
//--- création
if(!m_button2.Create(m_chart_id,m_name+"Button2",m_subwin,x1,y1,x2,y2))
return(false);
if(!m_button2.Text("Button2"))
return(false);
if(!Add(m_button2))
return(false);
//--- succès
return(true);
}
//+------------------------------------------------------------------+
//| Crée le bouton fixe "Button3" |
//+------------------------------------------------------------------+
bool CControlsDialog::CreateButton3(void)
{
//--- coordonnées
int x1=INDENT_LEFT+2*(BUTTON_WIDTH+CONTROLS_GAP_X);
int y1=INDENT_TOP+(EDIT_HEIGHT+CONTROLS_GAP_Y);
int x2=x1+BUTTON_WIDTH;
int y2=y1+BUTTON_HEIGHT;
//--- création
if(!m_button3.Create(m_chart_id,m_name+"Button3",m_subwin,x1,y1,x2,y2))
return(false);
if(!m_button3.Text("Locked"))
return(false);
if(!Add(m_button3))
return(false);
m_button3.Locking(true);
//--- succès
return(true);
}
//+------------------------------------------------------------------+
//| Gestionnaire d'évènement |
//+------------------------------------------------------------------+
void CControlsDialog::OnClickButton1(void)
{
Comment(__FUNCTION__);
}
//+------------------------------------------------------------------+
//| Gestionnaire d'évènement |
//+------------------------------------------------------------------+
void CControlsDialog::OnClickButton2(void)
{
Comment(__FUNCTION__);
}
//+------------------------------------------------------------------+
//| Gestionnaire d'évènement |
//+------------------------------------------------------------------+
void CControlsDialog::OnClickButton3(void)
{
if(m_button3.Pressed())
Comment(__FUNCTION__+" Etat du contrôle : On");
else
Comment(__FUNCTION__+" Etat du contrôle : Off");
}
//+------------------------------------------------------------------+
//| Variables Globales |
//+------------------------------------------------------------------+
CControlsDialog ExtDialog;
//+------------------------------------------------------------------+
//| Fonction d'initialisation de l'Expert |
//+------------------------------------------------------------------+
int OnInit()
{
//--- crée le dialogue de l'application
if(!ExtDialog.Create(0,"Controls",0,40,40,380,344))
return(INIT_FAILED);
//--- lance l'application
ExtDialog.Run();
//--- succès
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Fonction de désinitialisation de l'Expert |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//--- supprime le commentaire
Comment("");
//--- détruit le dialogue
ExtDialog.Destroy(reason);
}
//+------------------------------------------------------------------+
//| Fonction d'évènement du graphique |
//+------------------------------------------------------------------+
void OnChartEvent(const int id, // identifiant de l'évènement
const long& lparam, // paramètre d'évènement de type long
const double& dparam, // paramètre d'évènement de type double
const string& sparam) // paramètre d'évènement de type string
{
ExtDialog.ChartEvent(id,lparam,dparam,sparam);
}
|