CAppDialog Panel issue

 
Hello fellow traders.

I've been struggling on an issue with my GUI panel on my EA and I need help.

When the panel is created the Minimize/Maximize button and the Close button are contained into the Caption block like on the following image:

CDialog objects 

Here how it looks on my panel:



But when I minimize it, the buttons are not above the Caption element that is supposed to be used as the background:



And when I maximize it, I get the same issue:



I have tried to modify the size of the Caption object, but the buttons are being shifted accordingly instead of staying within the intended layout.

Here is some of my code that might be relavant to this issue:
#include <Controls\Defines.mqh> // IMPORT THEN REDEFINE BEFORE OTHER CONTROL IMPORTS

#undef   CONTROLS_DIALOG_CAPTION_HEIGHT
#undef   CONTROLS_DIALOG_BUTTON_OFF
#undef   CONTROLS_DIALOG_CLIENT_OFF
#undef   CONTROLS_DIALOG_MINIMIZE_LEFT
#undef   CONTROLS_DIALOG_MINIMIZE_TOP
#undef   CONTROLS_DIALOG_MINIMIZE_WIDTH
#undef   CONTROLS_DIALOG_MINIMIZE_HEIGHT

#define  CONTROLS_DIALOG_CAPTION_HEIGHT      (50)     // height of dialog header
#define  CONTROLS_DIALOG_BUTTON_OFF          (17)     // offset of dialog buttons
#define  CONTROLS_DIALOG_CLIENT_OFF          (17)     // offset of dialog client area
#define  CONTROLS_DIALOG_MINIMIZE_LEFT       (750)    // left coordinate of dialog in minimized state
#define  CONTROLS_DIALOG_MINIMIZE_TOP        (0)      // top coordinate of dialog in minimized state
#define  CONTROLS_DIALOG_MINIMIZE_WIDTH      (310)    // width of dialog in minimized state
#define  CONTROLS_DIALOG_MINIMIZE_HEIGHT     (CONTROLS_DIALOG_CAPTION_HEIGHT) // height of dialog in minimized state

#include <Trade\Trade.mqh>
#include <Trade\PositionInfo.mqh>
#include <Controls\Dialog.mqh>
#include <Controls\Picture.mqh>
#include <Controls\Label.mqh>
#include <Controls\Button.mqh>


// Create instances
CTrade        trade;
CPositionInfo posinfo;
CAppDialog    app;
CEdit*        edit;

// On OnInit() function
app.Create(0, "MyPanel", 0, intendLeft, intendUp, panelWidht, panelHeight);
         
         // Code used to modify the dimensions and colors of GUI elements
         int total=app.ControlsTotal();
         CWndClient*myclient;
         for(int i=0;i<total;i++)
           {
            CWnd*obj=app.Control(i);
            string name=obj.Name();
            
            if(StringFind(name,"Border")>0)
              {
               CPanel *panel=(CPanel*) obj;
               panel.ColorBorder(clrNONE);
               panel.ColorBackground(clrNONE);
               
               ChartRedraw();
              }
              
            if(StringFind(name,"Back")>0)
              {
               CPanel *panel=(CPanel*) obj;
               panel.ColorBackground(clrNONE);
               panel.ColorBorder(clrNONE);
               
               ChartRedraw();
              }
              
            if(StringFind(name,"Caption")>0)
              {
               edit=(CEdit*) obj;
               color ChartBGClr = (color)ChartGetInteger(0,CHART_COLOR_BACKGROUND,0);
               edit.ColorBackground(clrDodgerBlue);
               edit.ColorBorder(clrPink);
               edit.Text("MyPanel");
               edit.TextAlign(ALIGN_CENTER);
               if(DisplayMode==DarkMode)
                  edit.Color(clrAliceBlue);
               if(DisplayMode==LightMode)
                  edit.Color(clrBlack);
               edit.FontSize(7);
               edit.Height(50);
               edit.Width(522);
               panelCaptionWidth = 522;
               
               ChartRedraw();
              }
             
            if(StringFind(name,"Client")>0)
              {
               CWndClient *client=(CWndClient*)obj;
               client.ColorBackground(clrNONE);
               client.ColorBorder(clrNONE);
               myclient=client;
               
               ChartRedraw();
              }
         }

The solution might be something obvious to some of you, but I'm not familiar with how classes work and I'm still learning about it.
So hopefully someone can share a bit of his experience with me and kindly advise. 

If I forgot to share something essential please let me know and I will gladly share.

Thank you in advance to whoever will take the time to reply!
 
 
Please, provide small complete example to reproduce the problem. It looks like you did not use already existing workable examples, published on the site.
 
Stanislav Korotky #:
Please, provide small complete example to reproduce the problem. It looks like you did not use already existing workable examples, published on the site.

Hello Stanislav

Sure! Here is a small complete example to reproduce the problem (I confirm that it reproduces the problem on my side):

#include <Controls\Defines.mqh> // IMPORT THEN REDEFINE BEFORE OTHER CONTROL IMPORTS

#undef   CONTROLS_DIALOG_CAPTION_HEIGHT
#undef   CONTROLS_DIALOG_BUTTON_OFF
#undef   CONTROLS_DIALOG_CLIENT_OFF
#undef   CONTROLS_DIALOG_MINIMIZE_LEFT
#undef   CONTROLS_DIALOG_MINIMIZE_TOP
#undef   CONTROLS_DIALOG_MINIMIZE_WIDTH
#undef   CONTROLS_DIALOG_MINIMIZE_HEIGHT

#define  CONTROLS_DIALOG_CAPTION_HEIGHT      (50)     // height of dialog header
#define  CONTROLS_DIALOG_BUTTON_OFF          (17)     // offset of dialog buttons
#define  CONTROLS_DIALOG_CLIENT_OFF          (17)     // offset of dialog client area
#define  CONTROLS_DIALOG_MINIMIZE_LEFT       (750)    // left coordinate of dialog in minimized state
#define  CONTROLS_DIALOG_MINIMIZE_TOP        (0)      // top coordinate of dialog in minimized state
#define  CONTROLS_DIALOG_MINIMIZE_WIDTH      (310)    // width of dialog in minimized state  310
#define  CONTROLS_DIALOG_MINIMIZE_HEIGHT     (CONTROLS_DIALOG_CAPTION_HEIGHT) // height of dialog in minimized state

#include <Trade\Trade.mqh>
#include <Trade\PositionInfo.mqh>
#include <Controls\Dialog.mqh>
#include <Controls\Picture.mqh>
#include <Controls\Label.mqh>
#include <Controls\Button.mqh>


// Create instances
CTrade        trade;
CPositionInfo posinfo;
CAppDialog    app;
CEdit*        edit;

int OnInit(){
      
      int intendLeft  = 1;
      int intendUp    = 170;
      int panelWidht  = 527;
      int panelHeight = 380;
      
      if(!MQLInfoInteger(MQL_TESTER)){
      
         app.Create(0, "MyPanel", 0, intendLeft, intendUp, panelWidht, panelHeight);

         int total=app.ControlsTotal();
         CWndClient*myclient;
         for(int i=0;i<total;i++) {
            
                        CWnd*obj=app.Control(i);
            string name=obj.Name();
            
            if(StringFind(name,"Border")>0)
              {
               CPanel *panel=(CPanel*) obj;
               panel.ColorBorder(clrNONE);
               panel.ColorBackground(clrNONE);
               
               ChartRedraw();
              }
              
            if(StringFind(name,"Back")>0)
              {
               CPanel *panel=(CPanel*) obj;
               panel.ColorBackground(clrNONE);
               panel.ColorBorder(clrNONE);
               
               ChartRedraw();
              }
              
            if(StringFind(name,"Caption")>0)
              {
               edit=(CEdit*) obj;
               color ChartBGClr = (color)ChartGetInteger(0,CHART_COLOR_BACKGROUND,0);
               edit.ColorBackground(clrDodgerBlue);
               edit.ColorBorder(clrPink);
               edit.Text("MyPanel");
               edit.TextAlign(ALIGN_CENTER);
               edit.FontSize(7);
               edit.Height(50);
               edit.Width(522);
               
               ChartRedraw();
              }
             
            if(StringFind(name,"Client")>0)
              {
               CWndClient *client=(CWndClient*)obj;
               client.ColorBackground(clrNONE);
               client.ColorBorder(clrNONE);
               myclient=client;
               
               ChartRedraw();
              }
         }
         }
         
         return(INIT_SUCCEEDED);
}


void OnChartEvent(const int id, 
                  const long &lparam, 
                  const double &dparam, 
                  const string &sparam){
   
   app.ChartEvent(id,lparam,dparam,sparam);
   
}
 
Yoloic #:


Sure! Here is a small complete example to reproduce the problem (I confirm that it reproduces the problem on my side):

Yes, this is a bug in the standard controls library. Surely it has some, part of them is fixed in numerous publications on the site, part is still there. I think the only way to fix it is to debug the lib inside.

Apart from that your code also has bugs, should be:

int OnInit()
{
   ...
   app.Run();
   return...
}
...
void OnDeinit(const int reason)
{
   app.Destroy(reason);
}

Without this it doesn't process close button and closes entire chart if the EA is removed from the chart.

 
Stanislav Korotky #:

Yes, this is a bug in the standard controls library. Surely it has some, part of them is fixed in numerous publications on the site, part is still there. I think the only way to fix it is to debug the lib inside.

Apart from that your code also has bugs, should be:

Without this it doesn't process close button and closes entire chart if the EA is removed from the chart.


So this is a bug... Do you have a rough idea of which library could contain a bug? Or it's hard to tell?
I don't think that my current level of understanding of classes allow me to debug it properly but I will try tomorrow.

Also, I added the app.Run(); to my code, I didn't know about it!
Thank you very much for the feedback! I'm very impressed by the number of tools and publications you have posted!

 
Yoloic #:


So this is a bug... Do you have a rough idea of which library could contain a bug? Or it's hard to tell?
I don't think that my current level of understanding of classes allow me to debug it properly but I will try tomorrow.

I'm not an expert in the standard library. In the past I was compelled to debug it line by line (jumping between many mqh-files) in order to fix other bugs surfaced in my projects.