Mql5 create unclickable button.

 

Well, I have the next issue. I create button inherided from CButton class.
TryIng to iverride OnMouseUp and Down functions to prevent a button click. But it doesn't work.

I want to use a button as a label with a background and the ability to change its color. Or as a color indicator (light bulb). But I can't do anything to prevent the button from being pressed.

I tried to do this in a custom class inheriting from CAppDialog.

#include <Controls\Dialog.mqh>
#include <Controls\Button.mqh>
#include <Controls\Label.mqh>

// UI Section
class CControlPanel : public CAppDialog
{
   private:
      CLabel m_mask;
      CButton m_m5label;
      
   public:
      CControlPanel();   
      ~CControlPanel();

      virtual bool Create(const long chart, const string name, const int subwin, const int x1, const int y1, const int x2, const int y2);
      virtual bool OnEvent(const int id, const long &lparam, const double &dparam, const string &sparam);
      
   protected:
      bool CreateUnclickableButton(CButton &button, string text, color clr,
         const long chart, const string name, const int subwin, const int x1, const int y1, const int x2, const int y2);
      void OnClickUnclickableButtonM5();
};

EVENT_MAP_BEGIN(CControlPanel)
ON_EVENT(ON_CLICK, m_m5label, OnClickUnclickableButtonM5)
EVENT_MAP_END(CAppDialog)

CControlPanel::CControlPanel(){};
CControlPanel::~CControlPanel(){};

bool CControlPanel::Create(const long chart, const string name, const int subwin, const int x1, const int y1, const int x2, const int y2)
{
   if(!CAppDialog::Create(chart, name, subwin, x1, y1, x2, y2)) return false;
   if(!CreateUnclickableButton(m_m5label, "M5", clrLinen, chart, Prefix + "m5label", subwin, 5, 5, 45, 45)) return false;
   
   return true;
}

bool CControlPanel::CreateUnclickableButton(CButton &button, string text, color clr,
   const long chart, const string name, const int subwin, const int x1, const int y1, const int x2, const int y2)
{
   if(!button.Create(chart, name, subwin, x1, y1, x2, y2)) return false;
   if(!button.Text(text)) return false;
   if(!button.ColorBackground(clr)) return false;
   Add(button);
   return true;
}

void CControlPanel::OnClickUnclickableButtonM5()
{
   m_m5label.ColorBackground(clrLinen);
   m_m5label.Pressed(false);
}

CControlPanel Panel;
 
class CControlPanel : public CAppDialog {
public: 
...
void ChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam);
...
}

void CControlPanel ::ChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam) {
  CAppDialog::ChartEvent(id, lparam, dparam, sparam);
...

}
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam) {
  Panel.ChartEvent(id, lparam, dparam, sparam);
}

Try this

 
Le Minh Duc #:

Try this

Thank you Le Minh Duc.

This solution works much better.

But isn't there any way to completely disable interaction with the button. Perhaps we need to override methods of more basic classes?

 
Mykola Khandus #:

Thank you Le Minh Duc.

This solution works much better.

But isn't there any way to completely disable interaction with the button. Perhaps we need to override methods of more basic classes?

Oh, so you want to disable a button?
Try it:

m_m5label.Disable();