Discussion of article "Graphical Interfaces I: Form for Controls (Chapter 2)"

 

New article Graphical Interfaces I: Form for Controls (Chapter 2) has been published:

This article is the continuation of the first part of the series about graphical interfaces. The first article Graphical Interfaces I: Preparation of the Library Structure (Chapter 1) considers in detail what this library is for. A full list of the links to the articles of the first part is at the end of each chapter. There you can also find and download a complete version of the library at the current stage of development. The files must be located in the same directories as in the archive.

In the previous chapter we discussed a library structure for creating graphical interfaces. There (1) derived classes for primitive objects, (2) a base class for all controls, (3) principle classes for storing control pointers and managing those controls in the common event handler were created.

In this article we shall create the first and main element of the graphical interface — a form for controls. Multiple controls can be attached to this form anywhere and in any combination. The form will be movable and all controls attached to it will be moved together with it.

What parts will constitute the window that we are going to create?

  1. Background. All the controls will be located in this area.
  2. Header. This part enables moving the window and contains the interface controls listed below.
  3. Icon. Additional attributes for visual identification.
  4. Caption. Window name.
  5. The "Tooltip" button. Pressing this button enables the mode of showing control tooltips where they are present.
  6. Button for minimizing/maximizing the window.
  7. Button for closing the window.

Fig. 1. Compound parts of the form for controls

Fig. 1. Compound parts of the form for controls

Author: Anatoli Kazharski

 
Greetings Anatoly, I didn't see any methods for saving, loading form parameters (position, state...) in the base class. Are you planning to add such methods in the future, taking into account the type of forms?
 
Ruslan Khasanov:
Greetings Anatoly, I didn't see any methods for saving, loading form parameters (position, state...) in the base class. Are you planning to add such methods in the future, taking into account the type of forms?

Such an article is planned. But in my version, which parameters to save and load will be determined by the developer of MQL-application.

 

Good afternoon. Anatoly, of course I want to express my deepest respect for your labour and the work you have done. But I have a question while testing the library on the example of an Expert Advisor. Why is the window colour black, while all the colours of the elements that make up the window are set as LightGray by default? Isn't there a colour overlap somewhere, which results in a black window? I attach a screenshot:


 
Pavel Trofimov:

Good afternoon. Anatoly, of course I want to express my deepest respect for your labour and the work you have done. But I have a question while testing the library on the example of an Expert Advisor. Why is the window colour black, while all the colours of the elements that make up the window are set as LightGray by default? Isn't there a colour overlap somewhere, which results in a black window? I have attached a screenshot:

You can see the default colours of the form in the constructor of the CWindow class (file Window.mqh).

If you need to change the colours of the form, use the corresponding methods of the CWindow class. Properties of the form are set before its creation.

This example was shown in the article:

//+------------------------------------------------------------------+
//|| Creates a form for the | controls
//+------------------------------------------------------------------+
bool CProgram::CreateWindow(const string caption_text)
  {
//--- Add the window pointer to the window array
   CWndContainer::AddWindow(m_window);
//--- Properties
   m_window.XSize(200);
   m_window.YSize(200);
   m_window.WindowBgColor(clrWhiteSmoke);
   m_window.WindowBorderColor(clrLightSteelBlue);
   m_window.CaptionBgColor(clrLightSteelBlue);
   m_window.CaptionBgColorHover(C'200,210,225');
//--- Form creation
   if(!m_window.CreateWindow(m_chart_id,m_subwin,caption_text,1,1))
      return(false);
//---
   return(true);
  }

//---

Result:

 
Thanks for the clarification!
 

I couldn't find a method that changed the colour of the Header text, so I decided to add in window.mqh:

//--- Header properties
   string            m_caption_text;
   int               m_caption_height;
   color             m_caption_text_color;
   color             m_caption_bg_color;
   color             m_caption_bg_color_off;
   color             m_caption_bg_color_hover;
   color             m_caption_color_bg_array[];

And methods:

void              CaptionTextColor(const color text_color)                { m_caption_text_color=text_color;        }
color             CaptionTextColor(void)                            const { return(m_caption_text_color);           }

Well and this method changes accordingly:

//+------------------------------------------------------------------+
//|| Creates a header text label|
//+------------------------------------------------------------------+
bool CWindow::CreateLabel(void)
  {
   string name=CElementBase::ProgramName()+"_window_label_"+(string)CElementBase::Id();
//--- Object coordinates
   int x=CElementBase::X()+m_label_x_gap;
   int y=CElementBase::Y()+m_label_y_gap;
//--- Set the text label
   if(!m_label.Create(m_chart_id,name,m_subwin,x,y))
      return(false);
//--- Set properties
   m_label.Description(m_caption_text);
   m_label.Font(CElementBase::Font());
   m_label.FontSize(CElementBase::FontSize());
   m_label.Color(m_caption_text_color);
   m_label.Corner(m_corner);
   m_label.Selectable(false);
   m_label.Z_Order(m_button_zorder);
   m_label.Tooltip("\n");
//--- Save the coordinates
   m_label.X(x);
   m_label.Y(y);
//--- Indents from the end point
   m_label.XGap(x-m_x);
   m_label.YGap(y-m_y);
//--- Save dimensions
   m_label.XSize(m_label.X_Size());
   m_label.YSize(m_label.Y_Size());
//--- Save the object pointer
   CElementBase::AddToArray(m_label);
   return(true);
  }
 
Alexander Fedosov:

I couldn't find a method that changed the colour of the Header text, so I decided to add in window.mqh:

Good. I will also add this feature in one of the next articles.

The latest version of the library can be downloaded in this article: GUIs X: New features for a drawn table (build 9).

A new version(build 10) may be released next week.

 

Hello Mr. Anatoli, your articles are so nice and the coding are impressive.

I need a help to build my panel on the chart. Can you please help me?

Thanks.

 

HI. I would like to ask how I can fix all these errors. Thank you

'Window.mqh'    Window.mqh      1       1
'Element.mqh'   Element.mqh     1       1
'Objects.mqh'   Objects.mqh     1       1
'Enums.mqh'     Enums.mqh       1       1
'Defines.mqh'   Defines.mqh     1       1
'ChartObjectsBmpControls.mqh'   ChartObjectsBmpControls.mqh     1       1
'ChartObject.mqh'       ChartObject.mqh 1       1
'Object.mqh'    Object.mqh      1       1
'StdLibErr.mqh' StdLibErr.mqh   1       1
'ChartObjectsTxtControls.mqh'   ChartObjectsTxtControls.mqh     1       1
'Colors.mqh'    Colors.mqh      1       1
undefined class 'CBmpLabel' cannot be used      Window.mqh      25      15
   see declaration of class 'CBmpLabel' Objects.mqh     20      7
undefined class 'CLabel' cannot be used Window.mqh      26      12
   see declaration of class 'CLabel'    Objects.mqh     19      7
undefined class 'CBmpLabel' cannot be used      Window.mqh      27      15
   see declaration of class 'CBmpLabel' Objects.mqh     20      7
undefined class 'CBmpLabel' cannot be used      Window.mqh      28      15
   see declaration of class 'CBmpLabel' Objects.mqh     20      7
undefined class 'CBmpLabel' cannot be used      Window.mqh      29      15
   see declaration of class 'CBmpLabel' Objects.mqh     20      7
undefined class 'CBmpLabel' cannot be used      Window.mqh      30      15
   see declaration of class 'CBmpLabel' Objects.mqh     20      7
'ENUM_WINDOW_TYPE' - unexpected token, probably type is missing?        Window.mqh      36      5
'm_window_type' - semicolon expected    Window.mqh      36      22
'ENUM_WINDOW_TYPE' - unexpected token, probably type is missing?        Window.mqh      99      5
'WindowType' - semicolon expected       Window.mqh      99      23
'void' - name expected  Window.mqh      102     5
'}' - expressions are not allowed on a global scope     Window.mqh      104     5
'const' modifier not allowed for nonmember functions    Window.mqh      118     28
'const' modifier not allowed for nonmember functions    Window.mqh      126     30
'const' modifier not allowed for nonmember functions    Window.mqh      132     29
'const' modifier not allowed for nonmember functions    Window.mqh      138     32
'const' modifier not allowed for nonmember functions    Window.mqh      144     37
'public' - unexpected token, probably type is missing?  Window.mqh      168     3
'long' - unexpected token, probably type is missing?    Window.mqh      170     46
'double' - unexpected token, probably type is missing?  Window.mqh      170     66
'string' - unexpected token, probably type is missing?  Window.mqh      170     88
'virtual' - unexpected token    Window.mqh      172     5
'virtual' - unexpected token    Window.mqh      174     5
'virtual' - unexpected token    Window.mqh      176     5
'virtual' - unexpected token    Window.mqh      177     5
'virtual' - unexpected token    Window.mqh      178     5
'virtual' - unexpected token    Window.mqh      179     5
'virtual' - unexpected token    Window.mqh      181     5
'virtual' - unexpected token    Window.mqh      182     5
'}' - expressions are not allowed on a global scope     Window.mqh      183     1
'RollUpSubwindowMode' - member function not defined     Window.mqh      222     15
'ChangeSubwindowHeight' - member function not defined   Window.mqh      235     15
'Hide' - member function not defined    Window.mqh      294     15
'DefaultIcon' - member function not defined     Window.mqh      362     17
'advisor.bmp' as resource "::Images\EasyAndFastGUI\Icons\bmp16\advisor.bmp"     advisor.bmp     1       1
'indicator.bmp' as resource "::Images\EasyAndFastGUI\Icons\bmp16\indicator.bmp" indicator.bmp   1       1
'script.bmp' as resource "::Images\EasyAndFastGUI\Icons\bmp16\script.bmp"       script.bmp      1       1
'm_window_type' - struct member undefined       Window.mqh      193     5
'm_chart' - undeclared identifier       Window.mqh      210     5
'SetWindowProperties' - undeclared identifier   Window.mqh      212     5
')' - expression expected       Window.mqh      212     25
'm_window_type' - undeclared identifier Window.mqh      286     8
'W_DIALOG' - undeclared identifier      Window.mqh      286     25
'.' - struct or class type expected     Window.mqh      396     15
'Create' - undeclared identifier        Window.mqh      396     16
'Create' - some operator expected       Window.mqh      396     16
'(' - unbalanced left parenthesis       Window.mqh      396     7
',' - unexpected token  Window.mqh      396     33
'name' - some operator expected Window.mqh      396     35
expression has no effect        Window.mqh      396     23
',' - unexpected token  Window.mqh      396     49
expression has no effect        Window.mqh      396     41
',' - unexpected token  Window.mqh      396     52
expression has no effect        Window.mqh      396     51
')' - unexpected token  Window.mqh      396     55
expression has no effect        Window.mqh      396     54
')' - unexpected token  Window.mqh      396     56
'.' - struct or class type expected     Window.mqh      402     11
'BmpFileOn' - undeclared identifier     Window.mqh      402     12
'BmpFileOn' - some operator expected    Window.mqh      402     12
')' - unexpected token  Window.mqh      402     40
expression has no effect        Window.mqh      402     27
'.' - struct or class type expected     Window.mqh      403     11
'BmpFileOff' - undeclared identifier    Window.mqh      403     12
'BmpFileOff' - some operator expected   Window.mqh      403     12
')' - unexpected token  Window.mqh      403     41
expression has no effect        Window.mqh      403     28
'.' - struct or class type expected     Window.mqh      404     11
'Corner' - undeclared identifier        Window.mqh      404     12
'Corner' - some operator expected       Window.mqh      404     12
')' - unexpected token  Window.mqh      404     27
expression has no effect        Window.mqh      404     19
'.' - struct or class type expected     Window.mqh      405     11
'Selectable' - undeclared identifier    Window.mqh      405     12
'Selectable' - some operator expected   Window.mqh      405     12
')' - unexpected token  Window.mqh      405     28
expression has no effect        Window.mqh      405     23
'.' - struct or class type expected     Window.mqh      406     11
'Z_Order' - undeclared identifier       Window.mqh      406     12
'Z_Order' - some operator expected      Window.mqh      406     12
')' - unexpected token  Window.mqh      406     35
expression has no effect        Window.mqh      406     20
'.' - struct or class type expected     Window.mqh      407     11
'Tooltip' - undeclared identifier       Window.mqh      407     12
'Tooltip' - some operator expected      Window.mqh      407     12
')' - unexpected token  Window.mqh      407     24
expression has no effect        Window.mqh      407     21
'.' - struct or class type expected     Window.mqh      409     11
'X' - some operator expected    Window.mqh      409     12
'.' - struct or class type expected     Window.mqh      410     11
'Y' - some operator expected    Window.mqh      410     12
'.' - struct or class type expected     Window.mqh      412     11
'XGap' - some operator expected Window.mqh      412     12
'.' - struct or class type expected     Window.mqh      413     11
'YGap' - some operator expected Window.mqh      413     12
'.' - struct or class type expected     Window.mqh      415     11
'.' - struct or class type expected     Window.mqh      415     24
'X_Size' - undeclared identifier        Window.mqh      415     25
'X_Size' - some operator expected       Window.mqh      415     25
'(' - unexpected token  Window.mqh      415     31
'XSize' - some operator expected        Window.mqh      415     12
'.' - struct or class type expected     Window.mqh      416     11
'.' - struct or class type expected     Window.mqh      416     24
'Y_Size' - undeclared identifier        Window.mqh      416     25
'Y_Size' - some operator expected       Window.mqh      416     25
'(' - unexpected token  Window.mqh      416     31
'YSize' - some operator expected        Window.mqh      416     12
'm_icon' - parameter conversion not allowed     Window.mqh      418     26
   void CElement::AddToArray(CChartObject&)     Element.mqh     195     10
'm_icon_file' - undeclared identifier   Window.mqh      109     9
'm_tooltips_button' - undeclared identifier     Window.mqh      112     9
'm_right_limit' - undeclared identifier Window.mqh      115     9
'm_is_minimized' - undeclared identifier        Window.mqh      119     16
expression not boolean  Window.mqh      119     16
'm_is_minimized' - undeclared identifier        Window.mqh      122     9
100 errors, 11 warnings         101     12