Download MetaTrader 5
To add comments, please log in or register
Post web links to other trader's signals and make profit
MetaQuotes Software Corp.
Moderator
177179
MetaQuotes Software Corp. 2016.03.15 12:41 

New article Graphical Interfaces II: the Separation Line and Context Menu Elements (Chapter 2) has been published at mql5.com:

In this article we will create the separation line element. It will be possible to use it not only as an independent interface element but also as a part of many other elements. After that, we will have everything required for the development of the context menu class, which will be also considered in this article in detail. Added to that, we will introduce all necessary additions to the class, which is the base for storing pointers to all the elements of the graphical interface of the application.

The first article Graphical Interfaces I: Preparation of the Library Structure (Chapter 1) considers in detail what this library is for.

Developing the Class for Creating a Separation Line

In a context menu, besides different types of menu items, we can often see one more interface element - a separation line. This element can be encountered not only in context menus. For instance, the status bar of the MetaTrader trading terminal and the MetaEditor code editor have vertical separation lines. That is why we will create a separate class for this object so it can be used in any other control or even used as a separate element of the graphical interface.

To give an illusion of volume, a separation line must consist of at least two parts. If one line is lighter than the background and the other one is darker, this will create a visual effect of a groove on the surface. There are two ways of creating a separation line: (1) from two primitive objects of the CRectLabel type, which are already present in the Objects.mqh file or (2) create an object of the OBJ_BITMAP_LABEL type and use it as a canvas for drawing. Let us use the second option. The standard library suggests the CCanvas class for drawing. This class already contains all necessary methods for drawing simple geometrical figures, which significantly simplifies the implementation of the intended design and will save us a lot of time. 

The CCanvas class has to be embedded in a way so it can be used in a similar way to those primitive objects, which are already present in the Objects.mqh file. This can be easily achieved by making the CCanvas class derived from the CChartObjectBmpLabel class. A little change has to be introduced in the code of the CCanvas class so there are no errors or warnings later when the program is compiled. This is because in both the CCanvas class and the CChartObject class, which is the base class for the CChartObjectBmpLabel class, there is the m_chart_id field (variable). As a result, the compiler will give a warning that a variable with such a name already exists:

Fig. 1. Warning from the compiler that a variable with such a name already exists.

Author: Anatoli Kazharski

Radu
29
Radu 2016.03.17 11:07  

Thank you for the detailed articles. However, after compilation there is a compilation error:

'method' - undeclared identifier        MenuItem.mqh    229     103
'method' - some operator expected       MenuItem.mqh    229     103

 

This seems to be a typo, because the code is:

 

         ::Print(__FUNCTION__," > The type of the independent menu item can be only MI_SIMPLE or MI_HAS_CONTEXT_MENU, ",
                 "that is only with a context menu.\n",
                 __FUNCTION__," > The menu item type can be set using the CMenuItem::TypeMenuItem()") method;

 

After the correction:

         ::Print(__FUNCTION__," > The type of the independent menu item can be only MI_SIMPLE or MI_HAS_CONTEXT_MENU, ",
                 "that is only with a context menu.\n",
                 __FUNCTION__," > The menu item type can be set using the CMenuItem::TypeMenuItem() method");

 

The bigger problem is when I tried out the compiled code in MT4 and MT4 the same displaying error occurs. Here are two screenshots (one from MT4, one from MT5):

MT4

MT5 

All of the base features (moving the subwindow, clicking on the main items, hovering, etc) work great, but not the submenus.

Could you please tell me what could be the problem? 

/
To add comments, please log in or register