求助:如何通过MQL4读取MT4一键交易中的手数数值
MT4一键交易手数获取问题求助
我需要通过MQL4获取MT4一键交易界面中的手数(对应界面内的手数输入框)。目前已导入user32.dll相关函数并编写了获取逻辑,能定位到承载手数的Edit控件句柄,但使用GetWindowTextW和SendMessageW(WM_GETTEXT)均无法读取其中文本;另外,定位依赖的Afx类名在重启MT4后会发生变化,请求技术协助解决这两个问题。
已导入的user32.dll代码
#import "user32.dll" int FindWindowW(string className, string windowName); int FindWindowExW(int hwndParent, int hwndChildAfter, string className, string windowName); int GetWindowTextW(int hWnd, string lpString, int nMaxCount); int GetParent(int hWnd); int SendMessageW(int hWnd, int Msg, int wParam, string lParam); #import
当前手数获取函数
double GetLotSizeFromOneClickTrading() { int hwndMT4 = FindWindowW("MetaQuotes::MetaTrader::4.00", NULL); if (hwndMT4 == 0) return -1; int hwndMDIClient = FindWindowExW(hwndMT4, 0, "MDIClient", NULL); if (hwndMDIClient == 0) return -2; int hwndAboveChart = FindWindowExW(hwndMDIClient, 0, "Afx:00610000:b:00010003:00000006:000715CD", NULL); if (hwndAboveChart == 0) return -3; int hwndChart = FindWindowExW(hwndAboveChart, 0, "AfxFrameOrView140s", NULL); if (hwndChart == 0) return -4; int hwndEdit = FindWindowExW(hwndChart, 0, "Edit", NULL); if (hwndEdit == 0) return -5; // Get the lot size text from the edit box string lotSizeText; GetWindowTextW(hwndEdit, lotSizeText, 31); // Convert the text to a double and return it return StringToDouble(lotSizeText); }
问题细节
- 定位使用的
Afx:00610000:b:00010003:00000006:000715CD类名,重启MT4后会动态变化,该类名由WinSpy++获取 - 已确认
hwndEdit为目标Edit控件的句柄,但以下两种文本读取方式均无效:
方式1:使用GetWindowTextW
// Get the lot size text from the edit box string lotSizeText; GetWindowTextW(hwndEdit, lotSizeText, 31);
方式2:使用SendMessageW(WM_GETTEXT)
// Get the lot size text from the edit box string lotSizeText; const int WM_GETTEXT = 0x000D; SendMessageW(hwndEdit, WM_GETTEXT, 31, lotSizeText);
内容的提问来源于stack exchange,提问作者Sahil Bagdi
相关产品推荐
相关产品推荐

