一键获取交易手数 MT4

问题描述 投票:0回答:1

我想通过 MT4 中的一键交易获取手数,请参见下图以了解我在说什么:

当然使用MQL4

进口:

#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 -> This value change on restart, I got this from WinSpy++
hwndEdit -> This variable will conatain the Edit box handle
现在我只需要其中的文本,但我无法获取它

我的尝试: 但我无法获得手数,我尝试过以下方法:

1.)

// Get the lot size text from the edit box
   string lotSizeText;
   GetWindowTextW(hwndEdit, lotSizeText, 31);

什么也没做,我的变量中没有得到任何东西

2.)

// Get the lot size text from the edit box
   string lotSizeText;
   const int WM_GETTEXT = 0x000D;
   SendMessageW(hwndEdit, WM_GETTEXT, 31, lotSizeText);

再说一次,什么也没做

我很高兴终于找到了编辑框句柄,但我无法从中获取文本,这是最糟糕的

我们将非常感谢一些帮助

mql4 mql5 mt4
1个回答
0
投票

我也有类似的问题。 我发现一旦我手动单击编辑框,GetWindowTextW(...) 就会正确返回值。

我尝试自动模拟鼠标点击。 SendInput(...) 是我能够获得相同效果的唯一 API。但我认为这不是一个完美的解决方案。

我希望这有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.