问题描述
我发现了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)