DislikedHello Guys, How to disable Obj_Button from clicking in OnTick Function at Testing mode. I want to disable a button after pressing one time only. it will stay pressed state until i press other button.Ignored
Inserted Code
#property strict #include <chartobjects/chartobjectstxtcontrols.mqh> #include <arrays/list.mqh> class Buttons; //+------------------------------------------------------------------+ class MyButton : public CChartObjectButton { protected: static int s_num; Buttons *m_mgr; public: MyButton(Buttons *mgr):m_mgr(mgr){} bool create(string title, int x,int y,int xsize, int ysize); bool onclick(string button_name); }; int MyButton::s_num = 0; bool MyButton::create(string title, int x,int y,int xsize, int ysize) { return ( this.Create(0, "__button__" + string(++s_num), 0, x, y, xsize, ysize) && this.Description(title) ); } bool MyButton::onclick(string button_name) { if (button_name != this.Name()) return false; if (!this.State()) this.State(true); else for (MyButton *b=m_mgr.GetFirstNode(); CheckPointer(b); b=b.Next()) if (&this != b) b.State(false); return true; } //+------------------------------------------------------------------+ class Buttons : public CList { public: bool init(int num_buttons); bool newButton(string title="Button"); void onclick(string button); }; bool Buttons::init(int num_buttons) { for (int i=0; i<num_buttons; i++) if (!this.newButton(string(i+1))) return false; return true; } void Buttons::onclick(string button_name) { for (MyButton *b=this.GetFirstNode(); CheckPointer(b); b=b.Next()) if (b.onclick(button_name)) break; } bool Buttons::newButton(string title="Button") { MyButton *b = new MyButton(&this); int n = this.Total(); return (b.create(title, n * 50, 50, 50, 50) && this.Add(b) >= 0); } //+------------------------------------------------------------------+ Buttons *g_buttons; //+------------------------------------------------------------------+ int OnInit() { g_buttons = new Buttons(); return g_buttons.init(20) ? INIT_SUCCEEDED : INIT_FAILED; } void OnDeinit(const int reason) { delete g_buttons; } //+------------------------------------------------------------------+ void OnTick() {} //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { if (id == CHARTEVENT_OBJECT_CLICK) g_buttons.onclick(sparam); } //+------------------------------------------------------------------+