minimize/maximize a chart window in MQL5

1.2k views Asked by At

I found a very useful 'indicator' for MT4 that lets you maximize/minimize any chart by double/triple-clicking on it.

I've been trying to port it to MT5 unsuccessfully.

I am not sure what I am doing wrong with the Windows API. I did change the types to ulong/uint as per MSDN. I am also using CHART_WINDOW_HANDLE to get the hwnd.

The mouse clicking counter seems to work but I never managed to maximize or minimize a chart window with the below code.

Any help would be greatly appreciated.

//+------------------------------------------------------------------+
//|                                                     ClickMax.mq5 |
//|                               Copyright © 2020  | 2016, MaryJane |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2020 | 2016, MaryJane"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 0
#property indicator_plots   0
#property strict

input uint clickDelay = 300;
input bool tripleClick = true;

#define SW_MAXIMIZE     3
#define SW_RESTORE      9

//+------------------------------------------------------------------------------------------------------------------------------------------------------+
// --- DLLs
#import "user32.dll"
   ulong GetParent(ulong hWnd);
   ulong GetWindow(ulong hWnd, uint uCmd);
   bool ShowWindow(ulong hWnd, int nCmdShow);
   bool IsZoomed(ulong hWnd);
#import

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   if(!TerminalInfoInteger(TERMINAL_DLLS_ALLOWED))
     {

      Alert("You have to allow DLLs for ClickMax to work");
      return(INIT_FAILED);

     }
   else
      return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                         |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
   return(0);
  }

//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {

   static uint clicktime      = GetTickCount();
   static int  clickcount     = 0;
   bool        doubleclick    = false;
   if(_IsX64)
     {
      ulong hwnd = GetParent(CHART_WINDOW_HANDLE);
      //ulong hwnd = CHART_WINDOW_HANDLE;
      if(id == CHARTEVENT_CLICK)
        {
         uint test = GetTickCount() - clicktime;
         if(GetTickCount() - clicktime < clickDelay)
            clickcount++;
         else
            clickcount = 0;
         if((tripleClick && clickcount==2) ||
            (!tripleClick && clickcount==1))
            doubleclick = true;
         clicktime = GetTickCount();

         if(doubleclick)
           {
            if(!IsZoomed(hwnd))
               ShowWindow(hwnd, SW_MAXIMIZE);
            else
               ShowWindow(hwnd, SW_RESTORE);
            clickcount = 0;
           }
        }
     }
  }
1

There are 1 answers

0
emkuel5 On

as hinted by @dxiv in the comments, CHART_WINDOW_HANDLE is not an actual HWND. This is: (int)ChartGetInteger(0,CHART_WINDOW_HANDLE)