Download MetaTrader 5
To add comments, please log in or register
Add our channel to friends and follow the news!
eugenio
57
eugenio 2014.04.13 20:45 

Hi guy

I try to use class but I have big problems......follows my test code:

//+------------------------------------------------------------------+
//|                                                        #Test.mq4 |
//+------------------------------------------------------------------+

#include <Controls\Dialog.mqh>

CDialog myDialog;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
   if ( !myDialog.Create(ChartID(),"First dialog box",0,50,50,700,700) )
     return(INIT_FAILED);
   
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   myDialog.Destroy( reason );
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,         // Event identifier  
                  const long& lparam,   // Event parameter of long type
                  const double& dparam, // Event parameter of double type
                  const string& sparam) // Event parameter of string type
{
   myDialog.OnEvent(id,lparam,dparam,sparam);
}
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
{
}
//+------------------------------------------------------------------+

In the image there is the result

the dialog is create but the dialog does not move even if there is control in OnChartEvent

the button close you can not see the buttons in close

how I do to insert the close button and for example a combo box or an edit?

Please help me wiith an example

Thanks

Raaneip
15
Raaneip 2014.04.16 16:21  
e.bravetti:

Hi guy

I try to use class but I have big problems......follows my test code:

In the image there is the result

the dialog is create but the dialog does not move even if there is control in OnChartEvent

the button close you can not see the buttons in close

how I do to insert the close button and for example a combo box or an edit?

Please help me wiith an example

Thanks



This should get you going:

#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "https://www.mql4.com"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_plots               0
#property indicator_buffers             0
#property indicator_minimum             0.0
#property indicator_maximum             0.0
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

#include <MyAppDialog.mqh>

MyAppDialog InstMyAppDialog;

int OnInit()
  {
  if(!InstMyAppDialog.Create(0,"My App Dialog",0,0,0,0,300))
     return(INIT_FAILED);
  if(!InstMyAppDialog.Run())
     return(INIT_FAILED);   
//--- indicator buffers mapping
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
   
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
   InstMyAppDialog.ChartEvent(id,lparam,dparam,sparam);
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//|                                                  MyAppDialog.mqh |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              https://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "https://www.mql4.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
#include <Controls\Dialog.mqh>
#include <MyWndContainer.mqh>

class MyAppDialog : public CAppDialog
  {
private:
   MyWndContainer    InstMyWndContainer;
   CLabel            lblMyAppLabel;
   bool              CreateMyContainer(void);
   bool              CreateMyAppLabel(void);

public:
                     MyAppDialog();
                    ~MyAppDialog();

virtual bool      Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2);                    
                    
  };
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
MyAppDialog::MyAppDialog()
  {
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
MyAppDialog::~MyAppDialog()
  {
  }
//+------------------------------------------------------------------+

bool MyAppDialog::Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2)
  {
//--- calling the method of the parent class
   if(!CAppDialog::Create(chart,name,subwin,x1,y1,x2,y2))  
      return(false);
//--- additional controls shall be created here
   if(!CreateMyContainer())
      return(false);
   if(!CreateMyAppLabel())
      return(false);   
   Run();
//--- success
   return(true);
  }
  
bool MyAppDialog::CreateMyContainer(void)
  {  
  if(!InstMyWndContainer.Create(m_chart_id,"My Container",m_subwin,0,0,0,300))
      return(false);
  if(!Add(InstMyWndContainer))
      return(false);  
  InstMyWndContainer.Show();       
  return(true);    
  }
  
bool MyAppDialog::CreateMyAppLabel(void)    
   {
   if(!lblMyAppLabel.Create(m_chart_id,"lblMyAppLabel"+m_name, m_subwin,100,5,50,102))              
      return(false);
  lblMyAppLabel.Text("MyAppLabel:");
  lblMyAppLabel.FontSize(8);
  if(!Add(lblMyAppLabel))
      return(false);
   return(true);
   }
//+------------------------------------------------------------------+
//|                                               MyWndContainer.mqh |
//|                                                                  |
//|                                              https://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright ""
#property link      "https://www.mql4.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
#include <Controls\WndContainer.mqh>
#include <Controls\Label.mqh>

class MyWndContainer : public CWndContainer
  {
private:
   CLabel      lblMyLabel;
   bool        CreateMyLabel(void);

public:
                     MyWndContainer();
                    ~MyWndContainer();
                    
virtual bool      Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2);  
                    
  };
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
MyWndContainer::MyWndContainer()
  {
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
MyWndContainer::~MyWndContainer()
  {
  }
//+------------------------------------------------------------------+

bool MyWndContainer::Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2)
   {
   if(!CWndContainer::Create(chart,name,subwin,x1,y1,x2,y2))  
      return(false);
   if(!CreateMyLabel())
      return(false);
   return(true);
   }      


bool MyWndContainer::CreateMyLabel(void)
  {
  if(!lblMyLabel.Create(m_chart_id,"lblMyLabel"+m_name, m_subwin,10,5,50,22))              
      return(false);
  lblMyLabel.Text("MyLabel:");
  lblMyLabel.FontSize(8);
  if(!Add(lblMyLabel))
      return(false);   
  return(true);    
  }
Hope it helps.
eugenio
57
eugenio 2014.04.16 20:18  

Hi Raaneip

Thanks for your reply.....tomorrow I try your code

thanks and regards

Eugenio

/
To add comments, please log in or register