Download MetaTrader 5

Control classes without CDialog - How to work with CComboBox(), CListView(), CSpinEdit and so on ...

To add comments, please log in or register
Doerk Hilger
1181
Doerk Hilger  

Hi there,

I startet to write my own set of classes to create a own panel. Everything is (almost) fine so far, but those classes, which are derived from CWndContainer simply don't want to work. These are CComboBox, CListView and CSpinEdit. The controls are shown, but there is no interaction/reaction when I click on them. Whats the trick? Anybody an idea?

 Of course I've passed the parameters from OnChartEvent() to their OnEvent() function, but nothing happens. CButton Objects by the way don't act correctly when I click on them, because the .Locking() property is not interpreted, but I guess it's the same reason as with the other controls.

 Imam totally new to MQL, but have lots of experience with C++ and I was really wondering, whats possible with MQL. Great job by the developers, chapeau!

 

Doerk 

Vladimir Karputov
Moderator
49967
Vladimir Karputov  
Doerk:

Hi there,

I startet to write my own set of classes to create a own panel. Everything is (almost) fine so far, but those classes, which are derived from CWndContainer simply don't want to work. These are CComboBox, CListView and CSpinEdit. The controls are shown, but there is no interaction/reaction when I click on them. Whats the trick? Anybody an idea?

 Of course I've passed the parameters from OnChartEvent() to their OnEvent() function, but nothing happens. CButton Objects by the way don't act correctly when I click on them, because the .Locking() property is not interpreted, but I guess it's the same reason as with the other controls.

 Imam totally new to MQL, but have lots of experience with C++ and I was really wondering, whats possible with MQL. Great job by the developers, chapeau!

 

Doerk 

Let's start with a simple. Write element on the base of the CButton. Email Adviser (based on the standard Controls.mq5). Insert the Adviser your control. Then show code.
Doerk Hilger
1181
Doerk Hilger  

Hi, 

thanks for your reply. It´s just like that. Actually, the button should not lock and the combo should show a drop down-list, but neither the one nor the other happens.

Thanks in advance

Files:
Doerk Hilger
1181
Doerk Hilger  
//+------------------------------------------------------------------+
//|                                                  ControlTest.mq4 |
//+------------------------------------------------------------------+

#property strict


#include <Controls\Button.mqh>
#include <Controls\ComboBox.mqh>

   CButton b;
   CComboBox c;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---


   if (!b.Create(NULL,"Button",NULL,0,0,200,100))
      return(INIT_FAILED);
      
   b.Text("Click");
   b.Locking(False);
   

   if (!c.Create(NULL,"Combo",NULL,0,120,300,140))
      return(INIT_FAILED);

   c.AddItem("Item 1",1);
   c.AddItem("Item 2",2);
   c.AddItem("Item 3",3);
   
   c.Select(0);
   
   
//---
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
      b.OnEvent(id,lparam,dparam,sparam);
      c.OnEvent(id,lparam,dparam,sparam);
   
  }
//+------------------------------------------------------------------+
Doerk Hilger
1181
Doerk Hilger  

OK, reason for the problem with the buttons behavior found by myself. If you add this somewhere in your code, i. E. during OnInit(), the button reacts correctly. But still no reason for the problem with CComboBox and/or CSpinEdit. It cannot be that complicated, but CDialog or any other class above seems to do anything that I cannot figure out at the moment. 

 

      ChartSetInteger(NULL,CHART_EVENT_MOUSE_MOVE, true);
      ChartSetInteger(NULL,CHART_EVENT_OBJECT_CREATE,true);
      ChartSetInteger(NULL,CHART_EVENT_OBJECT_DELETE, true);
 
Vladimir Karputov
Moderator
49967
Vladimir Karputov  
Here's an example from MQL5. Simply remove the folder in C:\Users\ * * \AppData\Roaming\MetaQuotes\Terminal\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \MQL4\Experts\
Files:
Examples.zip 4 kb
Doerk Hilger
1181
Doerk Hilger  

Hey Vladimir,

 thanks, i knew this sample. Of course that works, cause it uses the CDialog Class. But I don´t want to use that class, I want to create my own class, that´s the problem. So I need a reason how to get this working within the code snipped I´ve posted just right before.

 :)

 Doerk 

Vladimir Karputov
Moderator
49967
Vladimir Karputov  

For the control of the CButton class based you can select such handlers:

//+------------------------------------------------------------------+
//|                                                          Wnd.mqh |
//|                   Copyright 2009-2013, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
.
.
.
protected:
   //--- internal event handlers
   virtual bool      OnCreate(void)                          { return(true);                 }
   virtual bool      OnDestroy(void)                         { return(true);                 }
   virtual bool      OnMove(void)                            { return(true);                 }
   virtual bool      OnResize(void)                          { return(true);                 }
   virtual bool      OnEnable(void)                          { return(true);                 }
   virtual bool      OnDisable(void)                         { return(true);                 }
   virtual bool      OnShow(void)                            { return(true);                 }
   virtual bool      OnHide(void)                            { return(true);                 }
   virtual bool      OnActivate(void)                        { return(true);                 }
   virtual bool      OnDeactivate(void)                      { return(true);                 }
   virtual bool      OnClick(void);
   virtual bool      OnDblClick(void);
   virtual bool      OnChange(void)                          { return(true);                 }
   //--- mouse event handlers
   virtual bool      OnMouseDown(void);
   virtual bool      OnMouseUp(void);
   //--- handlers of dragging
   virtual bool      OnDragStart(void);
   virtual bool      OnDragProcess(const int x,const int y);
   virtual bool      OnDragEnd(void);
   //--- methods for drag-object
   virtual bool      DragObjectCreate(void)                  { return(false);                }
   virtual bool      DragObjectDestroy(void);
  };
//+------------------------------------------------------------------+
//| Common handler of chart events                                   |
//+------------------------------------------------------------------+


Of them actually can use only this: (implemented in Button1)

   virtual bool      OnActivate(void)                        { return(true);                 }
   virtual bool      OnDeactivate(void)                      { return(true);                 }
Files:
Doerk Hilger
1181
Doerk Hilger  

Thank you again for your effort. But I still don't have a clue how I can convince this control to do its job - outside - a CDialog environment :) I dont want to use the CDialog Class at all, just the CComboBox() control i. E. on a plain chart-screen with nothing else around it. 

 Any ideas more? 

Vladimir Karputov
Moderator
49967
Vladimir Karputov  
Doerk:

Thank you again for your effort. But I still don't have a clue how I can convince this control to do its job - outside - a CDialog environment :) I dont want to use the CDialog Class at all, just the CComboBox() control i. E. on a plain chart-screen with nothing else around it. 

 Any ideas more? 

At the moment there are no ideas. By the way, I do not know how the control can operate without the Panel.
Doerk Hilger
1181
Doerk Hilger  

If it works with the panel, there must be a solution how to make it work also without, cause the CDialog is n not a kind of a wizard ;)

Anyway, I am one step further: If I use the debugger, and go through step by step, the List drops down, but when I simply let it run, it does not. WTF? :D I will figure it out ;) 

12
To add comments, please log in or register