Discussion of article "Graphical Interfaces IV: the Multi-Window Mode and System of Priorities (Chapter 2)"

 

New article Graphical Interfaces IV: the Multi-Window Mode and System of Priorities (Chapter 2) has been published:

In this chapter, we will extend the library implementation to the possibility of creating multi-window interfaces for the MQL applications. We will also develop a system of priorities for left mouse clicking on graphical objects. This is required to avoid problems when elements do not respond to the user's actions.

The Multi-Window Mode

Let us consider the multi-window mode of the graphical interface of the library under development. Up to now, the ENUM_WINDOW_TYPE enumeration provided two identifiers for the main (W_MAIN) and dialog (W_DIALOG) windows. The single-window mode was the only mode in use. After we introduce some additions, enabling the multi-window mode will simply involve the creation and addition of the required number of control forms to the base.

In the main class for event handling CWndEvents create a field for storing the index of the currently active window.

class CWndEvents : public CWndContainer
  {
protected:
   //--- Index of the active window
   int               m_active_window_index;
  };

Let us see how the index of the active window is going to be identified. For instance, the user assigns the opening of a dialog window (W_DIALOG) to some button. When the button is pressed, the ON_CLICK_BUTTON custom event is generated. This event can be tracked in the CProgram::OnEvent() event handler of the custom class. We will also use the CWindow::Show() method of the form which is to be shown. It is not sufficient in the current implementation of the library and we will introduce necessary additions.

Fig. 2. Library structure at the current stage of development.

Author: Anatoli Kazharski

 
MetaQuotes Software Corp.:

New article Graphical Interfaces IV: the Multi-Window Mode and System of Priorities (Chapter 2) has been published:

Author: Anatoli Kazharski

Thank you for the excellent series of articles.  I enjoyed reading the MQL4 codes.  Program.mqh is the following two error:

//error#1: array out of range in 'Program.mqh' (753,32)

//Fixed by changing lines 742-746
   string text[2]=
     {
      "\"Icon button\" (1) control",
      "Opens the dialog box (2)."
     };

//error#2: array out of range in 'Program.mqh' (1012,32)

//Fixed by changing lines 1000-1005
   string text[3]=
     {
      "\"Icon button\" (5) control",
      "This is the second line of the tooltip.",
      "This is the third line of the tooltip."
     };
 
Kaleem Haider:

Thank you for the excellent series of articles.  I enjoyed reading the MQL4 codes.  Program.mqh is the following two error:

Thank.

In my version of these errors not.

742-746:

//+------------------------------------------------------------------+
//| Tooltip 1                                                        |
//+------------------------------------------------------------------+
bool CProgram::CreateTooltip1(void)
  {
#define TOOLTIP1_LINES_TOTAL 2
//--- 
   m_tooltip1.WindowPointer(m_window1);
   m_tooltip1.ElementPointer(m_icon_button1);
//--- 
   string text[]=
     {
      "Line 1",
      "Line 2"
     };
//--- 
   m_tooltip1.Header("Icon Button 1");
   m_tooltip1.XSize(250);
   m_tooltip1.YSize(70);
//--- 
   for(int i=0; i<TOOLTIP1_LINES_TOTAL; i++)
      m_tooltip1.AddString(text[i]);
//--- 
   if(!m_tooltip1.CreateTooltip(m_chart_id,m_subwin))
      return(false);
//--- 
   CWndContainer::AddToElementsArray(0,m_tooltip1);
   return(true);
  }

//---

1000-1005:

//+------------------------------------------------------------------+
//| Tooltip 5                                                        |
//+------------------------------------------------------------------+
bool CProgram::CreateTooltip5(void)
  {
#define TOOLTIP5_LINES_TOTAL 3
//--- 
   m_tooltip5.WindowPointer(m_window1);
   m_tooltip5.ElementPointer(m_icon_button5);
//--- 
   string text[]=
     {
      "Line 1",
      "Line 2",
      "Line 3"
     };
//--- 
   m_tooltip5.Header("Icon Button 5");
   m_tooltip5.XSize(250);
   m_tooltip5.YSize(80);
//--- 
   for(int i=0; i<TOOLTIP5_LINES_TOTAL; i++)
      m_tooltip5.AddString(text[i]);
//--- 
   if(!m_tooltip5.CreateTooltip(m_chart_id,m_subwin))
      return(false);
//--- 
   CWndContainer::AddToElementsArray(0,m_tooltip5);
   return(true);
  }
 
Anatoli Kazharski:

Thank.

In my version of these errors not.

742-746:

//---

1000-1005:

The errors are in the article download section.  Maybe it wasn't updated.
 

It looks like Kaleem uses a slightly outdated platform version.

But for the sake of clarity and making less error-prone, the source code should be changed to define the arrays with explicit sizes as text[TOOLTIP1_LINES_TOTAL] and text[TOOLTIP5_LINES_TOTAL]. Otherwise you can get out of bounds error in future if arrays will change but defines will not by an omission.

 
Kaleem Haider:
The errors are in the article download section.  Maybe it wasn't updated.

Checked.

Yes, the English version has these errors. It seems that when the editors working on the translation into English, have accidentally deleted delimiters (,) elements of arrays. 

 
Stanislav Korotky:

It looks like Kaleem uses a slightly outdated platform version.

But for the sake of clarity and making less error-prone, the source code should be changed to define the arrays with explicit sizes as text[TOOLTIP1_LINES_TOTAL] and text[TOOLTIP5_LINES_TOTAL]. Otherwise you can get out of bounds error in future if arrays will change but defines will not by an omission.

I am using MetaTrader 4 Version: 4.00 Build 950.  Isn't this the latest version?
 
Kaleem Haider:
I am using MetaTrader 4 Version: 4.00 Build 950.  Isn't this the latest version?
960 seems to be the latest version.
Reason: