Dialog takes always close event

 

Hi,

the minimal example shown here is an AppDialog with a Button which should create a separate Dialog with a second Button.

The problem is that clicking on any area of the Dialog (except the caption) set the Dialog to be Visible(false).

I've checked the event

ON_EVENT(ON_CLICK,m_button_close,OnClickButtonClose)

defined in Include\Controls\Dialog.mqh but it seems to work correctly: it closes the Dialog when the bitmap "close" receives a click.

This issue is very similar to this one https://www.mql5.com/en/forum/376645, except that there the Dialog(s) are created at the beginning and immediately set to Hide(), while I would like to create the Dialog only on request.

Is that the only approach or am I missing something in my code?

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


#define X1 (0)
#define Y1 (0)
#define X2 (500)
#define Y2 (250)


class CGui: public CAppDialog {
  private:
    CButton button1;
    CButton button2;
    CDialog dialog;
  public:
    CGui(void);
    ~CGui(void);
    virtual bool Create();
    virtual bool OnEvent(const int id, const long &lparam, const double &dparam, const string &sparam);
  protected:
    bool CreateButton1();
    bool CreateButton2();
    bool CreateDialog();
    void OnClickButton1();
};


EVENT_MAP_BEGIN(CGui)
  ON_NAMED_EVENT(ON_CLICK, button1, OnClickButton1)
EVENT_MAP_END(CAppDialog)


CGui::CGui(void) {}
CGui::~CGui(void) {}


bool CGui::Create() {
  CAppDialog::Create(0, "App", 0, X1, Y1, X2, Y2);
  CreateButton1();
 
  return(true);
}


bool CGui::CreateButton1() {
  int x1 = 0;
  int y1 = 0;
  int x2 = x1 + 100;
  int y2 = y1 + 20;
  button1.Create(0, "Button1", 0, x1, y1, x2, y2);
  button1.Text("Button 1");
  Add(button1);

  return(true);
}


void CGui::OnClickButton1() {
  CreateDialog();
  CreateButton2();
}


bool CGui::CreateDialog() {
  int x1 = 0;
  int y1 = 0;
  int x2 = x1 + 200;
  int y2 = y1 + 100;
  dialog.Create(0, "Dialog", 0, x1, y1, x2, y2);
  Add(dialog);

  return(true);
}


bool CGui::CreateButton2() {
  int xx1 = 50;
  int yy1 = 20;
  int xx2 = xx1 + 100;
  int yy2 = yy1 + 20;
  button2.Create(0, "Button2", 0, xx1, yy1, xx2, yy2);
  button2.Text("Button 2");
  dialog.Add(button2);
 
  return(true);
}


CGui Gui;


int OnInit() {
  Gui.Create();
  Gui.Run();
 
  return(INIT_SUCCEEDED);
}


void OnDeinit(const int reason) {
  Gui.Destroy(reason);
}


void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam) {
  Gui.ChartEvent(id, lparam, dparam, sparam);
}
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...
 
dcstoyanov:


I've checked the event

ON_EVENT(ON_CLICK,m_button_close,OnClickButtonClose)

defined in Include\Controls\Dialog.mqh but it seems to work correctly: it closes the Dialog when the bitmap "close" receives a click.

I think it should be:

ON_NAMED_EVENT(ON_CLICK,m_button_close,OnClickButtonClose)

Then the code example must be correct as follows:

void CGui::OnClickButton1() {
  if (!dialog.IsVisible()) {
    dialog.Visible(true);
  }
  else {
    CreateDialog();
    CreateButton2();
  }  
}

Can someone confirm (that is a bug in the Library)?

 
dcstoyanov:


This issue is very similar to this one https://www.mql5.com/en/forum/376645, except that there the Dialog(s) are created at the beginning and immediately set to Hide(), while I would like to create the Dialog only on request.

Is that the only approach or am I missing something in my code?

Unfortunately, creating the Dialog "on request" produces an invalid ID (lparam = -1) and so, all events that rely on lparam are not associated with the Dialog and its objects.

Apparently, the only correct way is to create the Dialog and all its objects and then control their visibility.