文章 "图形界面 I:控件构成(第二章)"

 

新文章 图形界面 I:控件构成(第二章)已发布:

本文是关于图形界面系列第一部分文章的延续。第一篇文章图形界面 I:准备库结构(第一章) 详细介绍了此库的用处。第一部分文章的完整链接的列表在每一章的最后给出。在那里你可以找到并下载截至当前开发阶段的库的完整版本。文件必须位于和资料中同样的目录中。

前一章中,我们讨论了用于创建图形界面的类库结构。在那里讨论了:(1) 原始对象的派生类,(2) 所有控件的基类, (3) 创建存储控件指针和在公共事件处理程序中管理那些控件的主类。

在本文中我们将创建第一个图形界面的主元素 — 控件的一个窗体。多个控件可以以任何组合被附加到此窗体的任何地方。窗体是可以移动的,并且附着在其上的所有控件都将一起移动。

我们将要创建的窗口由哪些部分组成呢?

  1. 背景。所有的控件都将位于此区域。
  2. 头部。这个部分可以移动窗口并且包含下面列出的界面控件。
  3. 图标。利于视觉识别的附加物。
  4. 标题。窗口名称。
  5. “提示信息”按钮。按下此按钮可以开启控件提示显示模式。
  6. 最小化/最大化窗口按钮。
  7. 关闭窗口按钮。

图 1. 控件窗体的组合部分

图 1. 控件窗体的组合部分

作者:Anatoli Kazharski

 
您好,阿纳托利,我在基类中没有看到任何保存、加载表单参数(位置、状态......)的方法。考虑到表单的类型,你们是否计划在将来添加此类方法?
 
Ruslan Khasanov:
您好,阿纳托利,我在基类中没有看到任何保存、加载表单参数(位置、状态......)的方法。考虑到表单的类型,您是否计划在将来添加此类方法?

计划有这样一篇文章。但在我的版本中,保存和加载哪些参数将由 MQL 应用程序的开发人员决定。

 

下午好。阿纳托利,我当然要对您的劳动和工作表示最崇高的敬意。但我在以智能交易系统为例测试库时有一个问题。为什么窗口的颜色是黑色,而组成窗口的所有元素的颜色默认都设置为浅灰色?难道没有颜色重叠的地方吗?我附上一张截图:


 
Pavel Trofimov:

下午好。阿纳托利,我当然要对您的劳动和工作表示最崇高的敬意。不过,我在以智能交易系统(Expert Advisor)为例测试库时有一个问题。为什么窗口的颜色是黑色,而组成窗口的所有元素的颜色默认都设置为浅灰色?难道没有颜色重叠的地方吗?我附上了一张截图:

您可以在CWindow (文件Window.mqh的构造函数 中看到窗体的默认颜色。

如果需要更改窗体的颜色,请使用CWindow 类的相应方法。窗体的属性将在创建前设置。

该示例显示在文章中:

//+------------------------------------------------------------------+
//|| 为 | 控件创建表单
//+------------------------------------------------------------------+
bool CProgram::CreateWindow(const string caption_text)
  {
//--- 将窗口指针添加到窗口数组中
   CWndContainer::AddWindow(m_window);
//--- 属性
   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');
//--- 创建表格
   if(!m_window.CreateWindow(m_chart_id,m_subwin,caption_text,1,1))
      return(false);
//---
   return(true);
  }

//---

结果

 
谢谢你的澄清!
 

我找不到改变页眉文本颜色的方法,因此决定在 window.mqh 中添加:

//--- 标题属性
   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[];

和方法:

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

好了,这个方法也会相应改变:

//+------------------------------------------------------------------+
//|| 创建页眉文本标签|
//+------------------------------------------------------------------+
bool CWindow::CreateLabel(void)
  {
   string name=CElementBase::ProgramName()+"_window_label_"+(string)CElementBase::Id();
//--- 对象坐标
   int x=CElementBase::X()+m_label_x_gap;
   int y=CElementBase::Y()+m_label_y_gap;
//--- 设置文本标签
   if(!m_label.Create(m_chart_id,name,m_subwin,x,y))
      return(false);
//--- 设置属性
   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");
//--- 保存坐标
   m_label.X(x);
   m_label.Y(y);
//--- 从终点开始缩进
   m_label.XGap(x-m_x);
   m_label.YGap(y-m_y);
//--- 保存尺寸
   m_label.XSize(m_label.X_Size());
   m_label.YSize(m_label.Y_Size());
//-- 保存对象指针
   CElementBase::AddToArray(m_label);
   return(true);
  }
 
Alexander Fedosov:

我找不到改变页眉文本颜色的方法,所以决定在 window.mqh 中添加:

很好。我还将在下一篇文章中添加这一功能。

最新版本的程序库可在以下文章中下载:GUI X:绘制表格的新功能(第 9 版)

下周可能会发布新版本(第 10 版)。

 

您好,阿纳托利先生,您的文章非常好,编码也令人印象深刻。

我需要帮助在图表上建立我的面板。您能帮帮我吗?

谢谢。

 

你好。我想问一下如何才能修复所有这些错误。谢谢。

'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