最小化/最大化MQL5中的图表窗口



我为MT4找到了一个非常有用的"指示器",可以通过双击/三次来最大化/最小化任何图表。

我一直试图将它移植到MT5,但没有成功。

我不确定我对Windows API做了什么错误。我确实根据MSDN将类型更改为ulong/uint。我还使用CHART_WINDOW_HANDLE来获取hwnd。

鼠标点击计数器似乎可以工作,但我从未用下面的代码最大化或最小化图表窗口。

如有任何帮助,我们将不胜感激。

//+------------------------------------------------------------------+
//|                                                     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;
}
}
}
}
正如@dxiv在评论中暗示的那样,CHART_WINDOW_HANDLE不是一个实际的HWND。这是:(int(ChartGetInteger(0,CHART_WINDOW_HANDLE(

最新更新