CAppDialog indestructible Close button

 

Greetings,


I am struggling to get rid of a panel's close button. The reason to do such thing is, I successfuly created a CAppDialog panel with a guide found on YouTube, and one of the buttons should wipe all the objects created by the expert so far, but since it is irreversible, I want a verification from the user, so the button would first pop a window up, to press another button once again.

In the OnInit() function, I've started both panels:

int OnInit()
{
   if(!panel1.Oninit())
   {
      return INIT_FAILED;
   }

   if(!panel2.Oninit())
   {
      return INIT_FAILED;
   }
   else
   {
      panel2.Hide();
   }
}

I've created two separate event handlers for these, and the appropriate button should show panel2:

if(id == CHARTEVENT_OBJECT_CLICK && sparam == "ButtonDeleteAll")
{
   panel2.Show();
}

It works good so far, but the problem is, the popup window has its own minmax and close buttons, and if the close button is pressed, the expert deinitializes. I tried:

panel2.Control(3).Hide();
panel2.Control(5).Hide();

panel2.Control(3).Destroy();
panel2.Control(5).Destroy();

panel2.Control(3).Deactivate();
panel2.Control(5).Deactivate();

panel2.Control(3).Disable();
panel2.Control(5).Disable();

Which actually hidden the buttons, but when  clicking on that part of the dialog, it is still acts as normally, removing the expert from the chart, and I get a ExpertRemove() function called record in the experts log.

I wanted to try 

void OnClickButtonClose()
{
   Verification.Hide();
}

but it didn't work either. Not sure if I even used that properly at the proper place. I want to get rid of the secondary close button completely, and only to hide the second panel once again, when the user presses the verification answer button.

I found a similar topic: https://www.mql5.com/en/forum/376645 but he uses CDialog instead, and I'm not sure if its the same problem. What do I do wrong?


I'm new to CAppDialog and classes in general, so please forgive the noob question :)

Thank you in advance

J

AppDialog with multiple Dialogs close problem
AppDialog with multiple Dialogs close problem
  • 2021.08.31
  • www.mql5.com
Hello everybody, I'm trying to create a expert advisor (mql4) with multiple dialogs using standard library...
 

I dwelled deeper in the usage of classes. Now I understand (more or less) what is happening when I define my subclass of CDialog in my expert. I studied virtual functions, such as the OnClickButtonClose(). I tried to implement that, but it still closes the whole expert. I desperately want to disable those buttons, from the user to press them (i.e. to close the expert unintentionally) and only allow the user to hide the panel upon pressing any of the buttons created. The way I tried to override:

class panel2: public CAppDialog
{

...some code...

   public:
   
... some other code...

   void OnClickButtonClose() override
   {
   }

};

I really do believe that the solution must be here somewhere I just couldn't figure out how to use the override modifier properly just yet.

Any recommendations, what do I do wrong?

 
J.P.Satrio #:

I dwelled deeper in the usage of classes. Now I understand (more or less) what is happening when I define my subclass of CDialog in my expert. I studied virtual functions, such as the OnClickButtonClose(). I tried to implement that, but it still closes the whole expert. I desperately want to disable those buttons, from the user to press them (i.e. to close the expert unintentionally) and only allow the user to hide the panel upon pressing any of the buttons created. The way I tried to override:

I really do believe that the solution must be here somewhere I just couldn't figure out how to use the override modifier properly just yet.

Any recommendations, what do I do wrong?

class panel2: public CAppDialog
{

...some code...

   public:
   
... some other code...

    virtual void OnClickButtonClose()override
      {
      Alert("Close");
      }

};

This is the correct way to override the base class function. 

 

When you have more than one panels on the chart the ChartEvents can mix up. 

Set the Id of second panel to a higher value in OnInit than the total number of controls in first panel.

 

int OnInit()
{
   if(!panel1.Oninit())
   {
      return INIT_FAILED;
   }

   if(!panel2.Oninit())
   {
      return INIT_FAILED;
   }
   else
   {
      panel2.Id(100);
      panel2.Hide();
   }



}

 
Laszlo Tormasi #:

This is the correct way to override the base class function. 

I think I've tried that way already, which didn't work earlier, but this time... not sure if it was the 'virtual' keyword, or the distinction of the handler Ids, or both... but it worked, tysm :) 

Reason: