Download MetaTrader 5

Discussion of article "Graphical Interfaces V: The Combobox Control (Chapter 3)"

To add comments, please log in or register
Sell your applications via the Market. It is secure!
MetaQuotes Software Corp.
Moderator
181209
MetaQuotes Software Corp. 2016.05.25 09:58 

New article Graphical Interfaces V: The Combobox Control (Chapter 3) has been published:

In the first two chapters of the fifth part of the series, we developed classes for creating a scrollbar and a view list. In this chapter, we will speak about creating a class for the combobox control. This is also a compound control containing, among others, elements considered in the previous chapters of the fifth part.

In this article we have considered a compound control combobox. Schematic of the library for creating graphical interfaces at the current stage of development looks as shown below:

 Fig. 3. Structure of the library at the current stage of development.

Fig. 3. Structure of the library at the current stage of development.

Author: Anatoli Kazharski

Amir Yacoby
1195
Amir Yacoby 2016.05.25 18:02  
//+------------------------------------------------------------------+

//|                                                     ComboBox.mqh |
//|                        Copyright 2015, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#include "Element.mqh"
#include "Window.mqh"
#include "ListView.mqh"
//+------------------------------------------------------------------+
//| Êëàññ äëÿ ñîçäàíèÿ êîìáèíèðîâàííîãî ñïèñêà                       |
//+------------------------------------------------------------------+
class CComboBox : public CElement
  {
private:
   //--- Óêàçàòåëü íà ôîðìó, ê êîòîðîé ýëåìåíò ïðèñîåäèí¸í
   CWim_buttonndow          *m_wnd;
   //--- Îáúåêòû äëÿ ñîçäàíèÿ êîìáî-áîêñà
   CRectLabel        m_area;
Any reason why the comments are not in English anymore?
marquez
123
marquez 2016.05.30 23:48  
Amir Yacoby:
Any reason why the comments are not in English anymore?

I have ssen the same, and think they have currently 2 things.


1. Some issues still to be needed to be fixed (especially in MT4 !)
2. Currently no Person who can translate it to english. For me it is also not clear, why the main comments are not in english. But so long the functions declared in english, and the most examples like above is available in english, it doesn´t matters.


Kaleem Haider
74604
Kaleem Haider 2016.06.10 19:27  
MetaQuotes Software Corp.:

New article Graphical Interfaces V: The Combobox Control (Chapter 3) has been published:

Author: Anatoli Kazharski

Good job with the articles.  I am enjoying the next series of articles.  Can you please check SplitButton.mqh line 90? I am getting error

return - cannot convert from const pointer to nonconst pointer.  

I removed the "const" to make it work.  
Anatoli Kazharski
56919
Anatoli Kazharski 2016.06.10 22:14  
Kaleem Haider:

return - cannot convert from const pointer to nonconst pointer.  

I removed the "const" to make it work.  

Yes. It is necessary to remove the const wherever you get this error. Later I will update files in all articles.

Rodrigo Pandini
539
Rodrigo Pandini 2016.11.20 23:16  

[WIN7 64bits - MetaTrader5 build 1472]

Strange behavior of SplitString with ComboBox.

I create a combobox to control the sl e tp for a order, but when I tried get the selected item there is problem.
When the user click in the sell or buy buttons, the program get the selected item from combobox and calculate the sl and tp for the order.
When I run it in Debugging mode (F5) there no problem. But when I drag it from the EA list and drop to the chart, the problem appears.
Seens like the EasyAndFast library override in some way the SplitString, or PrintFormat, or StringToDouble functions, or something like that. But I not sure at all.
Here is my example:

//+------------------------------------------------------------------+
//| Creates combobox TP:SL                                           |
//+------------------------------------------------------------------+
bool CProgram::CreateTPSLComboBox(const int x_gap, const int y_gap, const string text) {
  // Total number of the list view items
  #define ITEMS_TOTAL1 4

  // Pass the panel object
  _tpslCombobox.WindowPointer(_mainWindow);
  
  // Attach to the first tab
  _mainTabs.AddToElementsArray(0, _tpslCombobox);  
  
  // Coordinates
  int x = _mainWindow.X() + x_gap;
  int y = _mainWindow.Y() + y_gap;
  
  // Array of the item values in the list view
  string items_text[ITEMS_TOTAL1] = {"2:4", "2:3", "3:4", "0:0"};
  
  // Set properties before creation
  _tpslCombobox.XSize(90);
  _tpslCombobox.YSize(18);
  _tpslCombobox.LabelText(text);
  _tpslCombobox.ButtonXSize(45);
  _tpslCombobox.ItemsTotal(ITEMS_TOTAL1);
  _tpslCombobox.VisibleItemsTotal(4);
  _tpslCombobox.AreaColor(clrWhite);

  // Store the item values in the combobox list view
  for(int i = 0; i < ITEMS_TOTAL1; i++)
    _tpslCombobox.ValueToList(i, items_text[i]);
  
  // Get the list view pointer
  CListView *lv = _tpslCombobox.GetListViewPointer();
  
  // Set the list view properties
  lv.LightsHover(true);
  lv.SelectedItemByIndex(lv.SelectedItemIndex() == WRONG_VALUE ? 0 : lv.SelectedItemIndex());
  
  // Create control
  if(!_tpslCombobox.CreateComboBox(m_chart_id, m_subwin, x, y))
    return(false);

  // Add the object to the common array of object groups
  CWndContainer::AddToElementsArray(0, _tpslCombobox);
  return(true);
}

...

//+------------------------------------------------------------------+
//| Sell function                                                    |
//+------------------------------------------------------------------+
void CProgram::Sell() {
  string sep = ":";
  ushort usep;
  usep = StringGetCharacter(sep, 0);
  string s[];
  double tp = 0.0;
  double sl = 0.0;
  if(StringSplit(_tpslCombobox.ButtonText(), usep, s) == 2) {
    PrintFormat("s01: %s - s02: %s", s[0], s[1]); // output: s01: 2 - s02: 4 
    tp = StringToDouble(s[0]);
    sl = StringToDouble(s[1]);
  }
  PrintFormat("tp: %.2f - sl: %.2f", tp, sl); // output: tp: 2.00 - sl: 2.00
...

The output: "tp:2.00 - sl: 2.00" should be "tp:2.00 - sl: 4.00".
But again, the problem appears only when I drag and drop to the chart. When I run it in debug mode everything is ok.
Some advise?

------
UPDATE: 
It looks like a problem in MetaTrader 5, not in the EasyAndFast library specifically.
Here is a test:
//+------------------------------------------------------------------+
//|                                                         test.mq5 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
    string sep = ":";
    ushort usep;
    usep = StringGetCharacter(sep, 0);
    string s[];
    double tp = 0.0;
    double sl = 0.0;
    if(StringSplit("2:4", usep, s) == 2) {
      tp = StringToDouble(s[0]);
      sl = StringToDouble(s[1]);
    }
    PrintFormat("tp: %.2f - sl: %.2f", tp, sl);
  }
//+------------------------------------------------------------------+
Output: "tp: 2.00 - sl: 4.00" in Debug mode (F5).
Output: "tp: 2.00 - sl: 2.00" when you drag and drop the script to the chart.

If someone else confirm this, I will report to ServiceDesk.
Thank you.

[WIN7 64bits - MetaTrader5 build 1472]
To add comments, please log in or register