【发布时间】:2020-10-26 00:05:43
【问题描述】:
我为 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;
}
}
}
}
【问题讨论】:
-
不知道 MQL5,但
CHART_WINDOW_HANDLE听起来不像真正的HWND窗口句柄,这是GetParent所期望的。 -
感谢@dxiv 我正在使用 CHART_WINDOW_HANDLE 因为文档:mql5.com/en/docs/constants/chartconstants/… MQL4 函数 WindowHandle() 在 MQL5 中不起作用mql5.com/en/docs/standardlibrary/cchart/cchartwindowhandle
-
@emkuel5 使用工具,例如Spy++,检查你传入的
hwnd的值是否是正确的窗口句柄? -
非常感谢@dxiv!现在终于可以使用 (int)ChartGetInteger(0,CHART_WINDOW_HANDLE) 你的评论让我朝着正确的方向前进,我希望我能投票给你。
-
非常感谢@RitaHan-MSFT,很高兴下次知道,这会节省我一些时间和头痛:)
标签: winapi mql5 metatrader5