在 MQL5 中使用 AutoIt

  • 最后,我们将实现 MetaTrader 4 文章中演示的相同功能,即在终端设定中设置 MetaQuotes ID 的能力。

AutoIt

AutoIt 是一种用于自动化 Microsoft Windows 图形用户界面的脚本语言。 除提供窗口管理以外,它还能直接访问用户界面组件、以及鼠标和键盘敲击的输入模拟。 AutoIt 的一部分是 AutoItX,它是一个 dll,实现了 AutoIt 脚本语言的一些功能。 通过与这个 dll 交互,我们可以赋予 MQL5 的 gui 类似脚本功能。

安装

AutoIt 软件可从此链接处免费获得。 它可以在 x86 版本的所有 Microsoft Windows 直至 Windows 10 上运行。 它是一个 32 位应用程序,携带多个 64 位组件,也包括 64 位版本的 AutoItX。 如果您希望了解有关 AutoIt 的更多信息,那么阅读应用程序安装一部分的帮助文件是必不可少的。 在我们深入研究之前,我们需要意识到 AutoIt 的局限性。

局限性

AutoIt 的局限性在于,它只能与 Win32 API 提供的标准 Microsoft Windows 组件一起可靠工作。 如果一个程序用到定制的控件,那么它将无法工作。 对于使用跨平台框架创建的软件,这一点基本上确定无疑。 我们可以利用 AutoIt 的窗口信息工具检查程序的用户界面是否能与 AutoIt 兼容。另一个需要注意的限制是,AutoItX 只实现了 AutoIt 脚本语言的部分功能。 一个组件可以由 AutoIt 操控,但相同的功能也许无法经由 AutoItX 操控。

AutoIt 的窗口信息工具

AutoIt 附带一个名为 AutoIt Window Info Tool 的应用程序,用于获取有关应用程序窗口的信息。

拖拽 Finder 工具覆盖到目标应用程序的任何部分,我们就可以获得特定组件的属性。 这些组件被称为控件。 控件可以是按钮、下拉菜单或选项卡。 这些仅是少数几个例子,还有许多类型的控件用于构建应用程序。 每个控件都与一个窗口相关联。 一个应用程序可由多个窗口组成。 通常有一个主窗口,其它子窗口依附或驻靠在主窗口上。 如果子窗口依附或驻靠到主应用程序窗口,则这些子窗口中内含的所有控件均变为主应用程序窗口的一部分。 利用 AutoIt 精确定位到一个控件时,控件关联的窗口很重要,无论是子窗口还是主应用程序窗口。

查看下图,我们可以看到 finder 工具被拖拽到 Metatrader 5(Metatrader 5)应用程序的不同区域。 当选定选项菜单时,请注意窗口信息工具的设置。 冻结、始终在顶部、以及用 Spy++ 控制检测逻辑,几个选项均被勾选。

窗口选项卡的显示聚焦在应用程序窗口的属性,此处列出了窗口的标题和类别。 这些属性可用作它的唯一性标识。 移至控件选项卡,我们可以看到控件的属性,我们感兴趣的是 ClassnameNN 属性。 (注意在 AutoIt 上下文中的类名引用的是控件的类型)。 该属性是把控件类型以及实例标识符的数字形式加以组合。 了解控件的类型非常重要,因为这将决定 AutoIt 调用哪些函数处理它。

AutoItX 集成

为了确保能与 MetaTrader 5 成功集成,我们首先要确保终端在运行时能够找到所需的 dll。 为了实现这一点,我们简单地将所需的 dll 复制到 MetaTrader 5 安装目录的 Libraries 文件夹当中。 默认的 AutoIt3 安装目录位于 Program files (x86) 文件夹之中。 其中的 AutoItX 文件夹包含所有与 AutoItX 相关的组件,也包括 AutoItX3_Dll 头文件,其中列出了 Dll 中公开的所有函数原型。 这些对于您的 MetaTrader 5(64 或 32 位)构建版本获取相应的 dll 非常重要。

#pragma once

///
//
// AutoItX v3
//
// Copyright (C)1999-2013:
//    - Jonathan Bennett <jon at autoitscript dot com>
//    - See "AUTHORS.txt" for contributors.
//
// This file is part of AutoItX.  Use of this file and the AutoItX DLL is subject
// to the terms of the AutoItX license details of which can be found in the helpfile.
//
// When using the AutoItX3.dll as a standard DLL this file contains the definitions,
// and function declarations required to use the DLL and AutoItX3_DLL.lib file.
//
///


#ifdef __cplusplus
#define AU3_API extern "C"
#else
#define AU3_API
#endif


// Definitions
#define AU3_INTDEFAULT        (-2147483647)  // "Default" value for _some_ int parameters (largest negative number)

//
// nBufSize
// When used for specifying the size of a resulting string buffer this is the number of CHARACTERS
// in that buffer, including the null terminator.  For example:
//
// WCHAR szBuffer[10];
// AU3_ClipGet(szBuffer, 10);
//
// The resulting string will be truncated at 9 characters with the the terminating null in the 10th.
//


///
// Exported functions
///

#include <windows.h>
AU3_API void WINAPI AU3_Init(void);
AU3_API int AU3_error(void);

AU3_API int WINAPI AU3_AutoItSetOption(LPCWSTR szOption, int nValue);


AU3_API void WINAPI AU3_ClipGet(LPWSTR szClip, int nBufSize);
AU3_API void WINAPI AU3_ClipPut(LPCWSTR szClip);
AU3_API int WINAPI AU3_ControlClick(LPCWSTR szTitle, LPCWSTR szText, LPCWSTR szControl, LPCWSTR szButton, int nNumClicks, int nX = AU3_INTDEFAULT, int nY = AU3_INTDEFAULT);
AU3_API int WINAPI AU3_ControlClickByHandle(HWND hWnd, HWND hCtrl, LPCWSTR szButton, int nNumClicks, int nX = AU3_INTDEFAULT, int nY = AU3_INTDEFAULT);
AU3_API void WINAPI AU3_ControlCommand(LPCWSTR szTitle, LPCWSTR szText, LPCWSTR szControl, LPCWSTR szCommand, LPCWSTR szExtra, LPWSTR szResult, int nBufSize);
AU3_API void WINAPI AU3_ControlCommandByHandle(HWND hWnd, HWND hCtrl, LPCWSTR szCommand, LPCWSTR szExtra, LPWSTR szResult, int nBufSize);
AU3_API void WINAPI AU3_ControlListView(LPCWSTR szTitle, LPCWSTR szText, LPCWSTR szControl, LPCWSTR szCommand, LPCWSTR szExtra1, LPCWSTR szExtra2, LPWSTR szResult, int nBufSize);
AU3_API void WINAPI AU3_ControlListViewByHandle(HWND hWnd, HWND hCtrl, LPCWSTR szCommand, LPCWSTR szExtra1, LPCWSTR szExtra2, LPWSTR szResult, int nBufSize);
AU3_API int WINAPI AU3_ControlDisable(LPCWSTR szTitle, LPCWSTR szText, LPCWSTR szControl);
AU3_API int WINAPI AU3_ControlDisableByHandle(HWND hWnd, HWND hCtrl);
AU3_API int WINAPI AU3_ControlEnable(LPCWSTR szTitle, LPCWSTR szText, LPCWSTR szControl);
AU3_API int WINAPI AU3_ControlEnableByHandle(HWND hWnd, HWND hCtrl);
AU3_API int WINAPI AU3_ControlFocus(LPCWSTR szTitle, LPCWSTR szText, LPCWSTR szControl);
AU3_API int WINAPI AU3_ControlFocusByHandle(HWND hWnd, HWND hCtrl);
AU3_API void WINAPI AU3_ControlGetFocus(LPCWSTR szTitle, LPCWSTR szText, LPWSTR szControlWithFocus, int nBufSize);
AU3_API void WINAPI AU3_ControlGetFocusByHandle(HWND hWnd, LPWSTR szControlWithFocus, int nBufSize);
AU3_API HWND WINAPI AU3_ControlGetHandle(HWND hWnd, LPCWSTR szControl);
AU3_API void WINAPI AU3_ControlGetHandleAsText(LPCWSTR szTitle, /*[in,defaultvalue("")]*/LPCWSTR szText, LPCWSTR szControl, LPWSTR szRetText, int nBufSize);
AU3_API int WINAPI AU3_ControlGetPos(LPCWSTR szTitle, LPCWSTR szText, LPCWSTR szControl, LPRECT lpRect);
AU3_API int WINAPI AU3_ControlGetPosByHandle(HWND hWnd, HWND hCtrl, LPRECT lpRect);
AU3_API void WINAPI AU3_ControlGetText(LPCWSTR szTitle, LPCWSTR szText, LPCWSTR szControl, LPWSTR szControlText, int nBufSize);
AU3_API void WINAPI AU3_ControlGetTextByHandle(HWND hWnd, HWND hCtrl, LPWSTR szControlText, int nBufSize);
AU3_API int WINAPI AU3_ControlHide(LPCWSTR szTitle, LPCWSTR szText, LPCWSTR szControl);
AU3_API int WINAPI AU3_ControlHideByHandle(HWND hWnd, HWND hCtrl);
AU3_API int WINAPI AU3_ControlMove(LPCWSTR szTitle, LPCWSTR szText, LPCWSTR szControl, int nX, int nY, int nWidth = -1, int nHeight = -1);
AU3_API int WINAPI AU3_ControlMoveByHandle(HWND hWnd, HWND hCtrl, int nX, int nY, int nWidth = -1, int nHeight = -1);
AU3_API int WINAPI AU3_ControlSend(LPCWSTR szTitle, LPCWSTR szText, LPCWSTR szControl, LPCWSTR szSendText, int nMode = 0);
AU3_API int WINAPI AU3_ControlSendByHandle(HWND hWnd, HWND hCtrl, LPCWSTR szSendText, int nMode = 0);
AU3_API int WINAPI AU3_ControlSetText(LPCWSTR szTitle, LPCWSTR szText, LPCWSTR szControl, LPCWSTR szControlText);
AU3_API int WINAPI AU3_ControlSetTextByHandle(HWND hWnd, HWND hCtrl, LPCWSTR szControlText);
AU3_API int WINAPI AU3_ControlShow(LPCWSTR szTitle, LPCWSTR szText, LPCWSTR szControl);
AU3_API int WINAPI AU3_ControlShowByHandle(HWND hWnd, HWND hCtrl);
AU3_API void WINAPI AU3_ControlTreeView(LPCWSTR szTitle, LPCWSTR szText, LPCWSTR szControl, LPCWSTR szCommand, LPCWSTR szExtra1, LPCWSTR szExtra2, LPWSTR szResult, int nBufSize);
AU3_API void WINAPI AU3_ControlTreeViewByHandle(HWND hWnd, HWND hCtrl, LPCWSTR szCommand, LPCWSTR szExtra1, LPCWSTR szExtra2, LPWSTR szResult, int nBufSize);

AU3_API void WINAPI AU3_DriveMapAdd(LPCWSTR szDevice, LPCWSTR szShare, int nFlags, /*[in,defaultvalue("")]*/LPCWSTR szUser, /*[in,defaultvalue("")]*/LPCWSTR szPwd, LPWSTR szResult, int nBufSize);
AU3_API int WINAPI AU3_DriveMapDel(LPCWSTR szDevice);
AU3_API void WINAPI AU3_DriveMapGet(LPCWSTR szDevice, LPWSTR szMapping, int nBufSize);

AU3_API int WINAPI AU3_IsAdmin(void);

AU3_API int WINAPI AU3_MouseClick(/*[in,defaultvalue("LEFT")]*/LPCWSTR szButton, int nX = AU3_INTDEFAULT, int nY = AU3_INTDEFAULT, int nClicks = 1, int nSpeed = -1);
AU3_API int WINAPI AU3_MouseClickDrag(LPCWSTR szButton, int nX1, int nY1, int nX2, int nY2, int nSpeed = -1);
AU3_API void WINAPI AU3_MouseDown(/*[in,defaultvalue("LEFT")]*/LPCWSTR szButton);
AU3_API int WINAPI AU3_MouseGetCursor(void);
AU3_API void WINAPI AU3_MouseGetPos(LPPOINT lpPoint);
AU3_API int WINAPI AU3_MouseMove(int nX, int nY, int nSpeed = -1);
AU3_API void WINAPI AU3_MouseUp(/*[in,defaultvalue("LEFT")]*/LPCWSTR szButton);
AU3_API void WINAPI AU3_MouseWheel(LPCWSTR szDirection, int nClicks);

AU3_API int WINAPI AU3_Opt(LPCWSTR szOption, int nValue);


AU3_API unsigned int WINAPI AU3_PixelChecksum(LPRECT lpRect, int nStep = 1);
AU3_API int WINAPI AU3_PixelGetColor(int nX, int nY);
AU3_API void WINAPI AU3_PixelSearch(LPRECT lpRect, int nCol, /*default 0*/int nVar, /*default 1*/int nStep, LPPOINT pPointResult);
AU3_API int WINAPI AU3_ProcessClose(LPCWSTR szProcess);
AU3_API int WINAPI AU3_ProcessExists(LPCWSTR szProcess);
AU3_API int WINAPI AU3_ProcessSetPriority(LPCWSTR szProcess, int nPriority);
AU3_API int WINAPI AU3_ProcessWait(LPCWSTR szProcess, int nTimeout = 0);
AU3_API int WINAPI AU3_ProcessWaitClose(LPCWSTR szProcess, int nTimeout = 0);

AU3_API int WINAPI AU3_Run(LPCWSTR szProgram, /*[in,defaultvalue("")]*/LPCWSTR szDir, int nShowFlag = SW_SHOWNORMAL);
AU3_API int WINAPI AU3_RunWait(LPCWSTR szProgram, /*[in,defaultvalue("")]*/LPCWSTR szDir, int nShowFlag = SW_SHOWNORMAL);
AU3_API int WINAPI AU3_RunAs(LPCWSTR szUser, LPCWSTR szDomain, LPCWSTR szPassword, int nLogonFlag, LPCWSTR szProgram, /*[in,defaultvalue("")]*/LPCWSTR szDir, int nShowFlag = SW_SHOWNORMAL);
AU3_API int WINAPI AU3_RunAsWait(LPCWSTR szUser, LPCWSTR szDomain, LPCWSTR szPassword, int nLogonFlag, LPCWSTR szProgram, /*[in,defaultvalue("")]*/LPCWSTR szDir, int nShowFlag = SW_SHOWNORMAL);


AU3_API void WINAPI AU3_Send(LPCWSTR szSendText, int nMode = 0);
AU3_API int WINAPI AU3_Shutdown(int nFlags);
AU3_API void WINAPI AU3_Sleep(int nMilliseconds);
AU3_API int WINAPI AU3_StatusbarGetText(LPCWSTR szTitle, /*[in,defaultvalue("")]*/LPCWSTR szText, /*[in,defaultvalue(1)]*/int nPart, LPWSTR szStatusText, int nBufSize);
AU3_API int WINAPI AU3_StatusbarGetTextByHandle(HWND hWnd, /*[in,defaultvalue(1)]*/int nPart, LPWSTR szStatusText, int nBufSize);

AU3_API void WINAPI AU3_ToolTip(LPCWSTR szTip, int nX = AU3_INTDEFAULT, int nY = AU3_INTDEFAULT);

AU3_API int WINAPI AU3_WinActivate(LPCWSTR szTitle, /*[in,defaultvalue("")]*/LPCWSTR szText);
AU3_API int WINAPI AU3_WinActivateByHandle(HWND hWnd);
AU3_API int WINAPI AU3_WinActive(LPCWSTR szTitle, /*[in,defaultvalue("")]*/LPCWSTR szText);
AU3_API int WINAPI AU3_WinActiveByHandle(HWND hWnd);
AU3_API int WINAPI AU3_WinClose(LPCWSTR szTitle, /*[in,defaultvalue("")]*/LPCWSTR szText);
AU3_API int WINAPI AU3_WinCloseByHandle(HWND hWnd);
AU3_API int WINAPI AU3_WinExists(LPCWSTR szTitle, /*[in,defaultvalue("")]*/LPCWSTR szText);
AU3_API int WINAPI AU3_WinExistsByHandle(HWND hWnd);
AU3_API int WINAPI AU3_WinGetCaretPos(LPPOINT lpPoint);
AU3_API void WINAPI AU3_WinGetClassList(LPCWSTR szTitle, /*[in,defaultvalue("")]*/LPCWSTR szText, LPWSTR szRetText, int nBufSize);
AU3_API void WINAPI AU3_WinGetClassListByHandle(HWND hWnd, LPWSTR szRetText, int nBufSize);
AU3_API int WINAPI AU3_WinGetClientSize(LPCWSTR szTitle, /*[in,defaultvalue("")]*/LPCWSTR szText, LPRECT lpRect);
AU3_API int WINAPI AU3_WinGetClientSizeByHandle(HWND hWnd, LPRECT lpRect);
AU3_API HWND WINAPI AU3_WinGetHandle(LPCWSTR szTitle, /*[in,defaultvalue("")]*/LPCWSTR szText);
AU3_API void WINAPI AU3_WinGetHandleAsText(LPCWSTR szTitle, /*[in,defaultvalue("")]*/LPCWSTR szText, LPWSTR szRetText, int nBufSize);
AU3_API int WINAPI AU3_WinGetPos(LPCWSTR szTitle, /*[in,defaultvalue("")]*/LPCWSTR szText, LPRECT lpRect);
AU3_API int WINAPI AU3_WinGetPosByHandle(HWND hWnd, LPRECT lpRect);
AU3_API DWORD WINAPI AU3_WinGetProcess(LPCWSTR szTitle, /*[in,defaultvalue("")]*/LPCWSTR szText);
AU3_API DWORD WINAPI AU3_WinGetProcessByHandle(HWND hWnd);
AU3_API int WINAPI AU3_WinGetState(LPCWSTR szTitle, /*[in,defaultvalue("")]*/LPCWSTR szText);
AU3_API int WINAPI AU3_WinGetStateByHandle(HWND hWnd);
AU3_API void WINAPI AU3_WinGetText(LPCWSTR szTitle, /*[in,defaultvalue("")]*/LPCWSTR szText, LPWSTR szRetText, int nBufSize);
AU3_API void WINAPI AU3_WinGetTextByHandle(HWND hWnd, LPWSTR szRetText, int nBufSize);
AU3_API void WINAPI AU3_WinGetTitle(LPCWSTR szTitle, /*[in,defaultvalue("")]*/LPCWSTR szText, LPWSTR szRetText, int nBufSize);
AU3_API void WINAPI AU3_WinGetTitleByHandle(HWND hWnd, LPWSTR szRetText, int nBufSize);
AU3_API int WINAPI AU3_WinKill(LPCWSTR szTitle, /*[in,defaultvalue("")]*/LPCWSTR szText);
AU3_API int WINAPI AU3_WinKillByHandle(HWND hWnd);
AU3_API int WINAPI AU3_WinMenuSelectItem(LPCWSTR szTitle, /*[in,defaultvalue("")]*/LPCWSTR szText, LPCWSTR szItem1, LPCWSTR szItem2, LPCWSTR szItem3, LPCWSTR szItem4, LPCWSTR szItem5, LPCWSTR szItem6, LPCWSTR szItem7, LPCWSTR szItem8);
AU3_API int WINAPI AU3_WinMenuSelectItemByHandle(HWND hWnd, LPCWSTR szItem1, LPCWSTR szItem2, LPCWSTR szItem3, LPCWSTR szItem4, LPCWSTR szItem5, LPCWSTR szItem6, LPCWSTR szItem7, LPCWSTR szItem8);
AU3_API void WINAPI AU3_WinMinimizeAll();
AU3_API void WINAPI AU3_WinMinimizeAllUndo();
AU3_API int WINAPI AU3_WinMove(LPCWSTR szTitle, /*[in,defaultvalue("")]*/LPCWSTR szText, int nX, int nY, int nWidth = -1, int nHeight = -1);
AU3_API int WINAPI AU3_WinMoveByHandle(HWND hWnd, int nX, int nY, int nWidth = -1, int nHeight = -1);
AU3_API int WINAPI AU3_WinSetOnTop(LPCWSTR szTitle, /*[in,defaultvalue("")]*/LPCWSTR szText, int nFlag);
AU3_API int WINAPI AU3_WinSetOnTopByHandle(HWND hWnd, int nFlag);
AU3_API int WINAPI AU3_WinSetState(LPCWSTR szTitle, /*[in,defaultvalue("")]*/LPCWSTR szText, int nFlags);
AU3_API int WINAPI AU3_WinSetStateByHandle(HWND hWnd, int nFlags);
AU3_API int WINAPI AU3_WinSetTitle(LPCWSTR szTitle,/*[in,defaultvalue("")]*/ LPCWSTR szText, LPCWSTR szNewTitle);
AU3_API int WINAPI AU3_WinSetTitleByHandle(HWND hWnd, LPCWSTR szNewTitle);
AU3_API int WINAPI AU3_WinSetTrans(LPCWSTR szTitle, /*[in,defaultvalue("")]*/LPCWSTR szText, int nTrans);
AU3_API int WINAPI AU3_WinSetTransByHandle(HWND hWnd, int nTrans);
AU3_API int WINAPI AU3_WinWait(LPCWSTR szTitle, /*[in,defaultvalue("")]*/LPCWSTR szText, int nTimeout = 0);
AU3_API int WINAPI AU3_WinWaitByHandle(HWND hWnd, int nTimeout);
AU3_API int WINAPI AU3_WinWaitActive(LPCWSTR szTitle, /*[in,defaultvalue("")]*/LPCWSTR szText, int nTimeout = 0);
AU3_API int WINAPI AU3_WinWaitActiveByHandle(HWND hWnd, int nTimeout);
AU3_API int WINAPI AU3_WinWaitClose(LPCWSTR szTitle, /*[in,defaultvalue("")]*/LPCWSTR szText, int nTimeout = 0);
AU3_API int WINAPI AU3_WinWaitCloseByHandle(HWND hWnd, int nTimeout);
AU3_API int WINAPI AU3_WinWaitNotActive(LPCWSTR szTitle, /*[in,defaultvalue("")]*/LPCWSTR szText, int nTimeout);
AU3_API int WINAPI AU3_WinWaitNotActiveByHandle(HWND hWnd, int nTimeout = 0);

///

任何用到 AutoItX 链接库的 MetaTrader 5 程序都必须首先导入其函数。 为方便起见,我们将创建一个包含文件 autoIt.mqh,其唯一目的是导入链接库公开的所有函数原型。

AutoIt 严格来说是一款运行在 Microsoft Windows 操作系统上的 Windows API 传动工具。 这就是 AuotItX 链接库广泛采用 Win32 API 特定数据类型的原因。 为了确保与 MQL5 的兼容性,我们可以自己在 MQL5 中实现这些数据类型,但这并非必需。 取而代之,我们可以利用 windef.mqh 文件,它是 MetaQuotes 在 MQL5 中集成 Win32 API 的一部分工作成效。 该文件包含 Windows api 中用到的大多数数据类型定义。
我们将在 autoit.mqh 文件中包含 windef.mqh,其内包含从 dll 导入的所有函数原型。 autoit.mqh 代码文件现在看起来如下所示:
 

//+------------------------------------------------------------------+
//|                                                       autoIt.mqh |
//|                                  Copyright 2021, MetaQuotes Ltd. |
//|                                             https://www.mql5.com  |
//+------------------------------------------------------------------+
#include <WinAPI\windef.mqh>

#define LPPOINT POINT&
#define LPRECT  RECT&
#define WORD    ushort
#define DWORD   int
#define HWND    int

#import "AutoItX3_x64.dll"
void AU3_Init(void);
int AU3_error(void);
int AU3_AutoItSetOption(string, int);
void AU3_ClipGet(string&, int);
void AU3_ClipPut(string);
int AU3_ControlClick(string, string, string, string, int, int, int);
int AU3_ControlClickByHandle(HWND, HWND, string, int, int, int);
void AU3_ControlCommand(string, string, string, string, string, string&, int);
void AU3_ControlCommandByHandle(HWND, HWND, string, string, string&, int);
void AU3_ControlListView(string, string, string, string, string, string, string&, int);
void AU3_ControlListViewByHandle(HWND, HWND, string, string, string, string&, int);
int AU3_ControlDisable(string, string, string);
int AU3_ControlDisableByHandle(HWND, HWND);
int AU3_ControlEnable(string, string, string);
int AU3_ControlEnableByHandle(HWND, HWND);
int AU3_ControlFocus(string, string, string);
int AU3_ControlFocusByHandle(HWND, HWND);
void AU3_ControlGetFocus(string, string, string&, int);
void AU3_ControlGetFocusByHandle(HWND, string&, int);
HWND AU3_ControlGetHandle(HWND, string);
void AU3_ControlGetHandleAsText(string, string, string, string&, int);
int AU3_ControlGetPos(string, string, string, LPRECT);
int AU3_ControlGetPosByHandle(HWND, HWND, LPRECT);
void AU3_ControlGetText(string, string, string, string&, int);
void AU3_ControlGetTextByHandle(HWND, HWND, string&, int);
int AU3_ControlHide(string, string, string);
int AU3_ControlHideByHandle(HWND, HWND);
int AU3_ControlMove(string, string, string, int, int, int, int);
int AU3_ControlMoveByHandle(HWND, HWND, int, int, int, int);
int AU3_ControlSend(string, string, string, string, int);
int AU3_ControlSendByHandle(HWND, HWND, string, int);
int AU3_ControlSetText(string, string, string, string);
int AU3_ControlSetTextByHandle(HWND, HWND, string);
int AU3_ControlShow(string, string, string);
int AU3_ControlShowByHandle(HWND, HWND);
void AU3_ControlTreeView(string, string, string, string, string, string, string&, int);
void AU3_ControlTreeViewByHandle(HWND, HWND, string, string, string, string&, int);
void AU3_DriveMapAdd(string,  string, int, string, string, string&, int);
int AU3_DriveMapDel(string);
void AU3_DriveMapGet(string, string&, int);
int AU3_IsAdmin(void);
int AU3_MouseClick(string, int, int, int, int);
int AU3_MouseClickDrag(string, int, int, int, int, int);
void AU3_MouseDown(string);
int AU3_MouseGetCursor(void);
void AU3_MouseGetPos(LPPOINT);
int AU3_MouseMove(int, int, int);
void AU3_MouseUp(string);
void AU3_MouseWheel(string, int);
int AU3_Opt(string, int);
unsigned int AU3_PixelChecksum(LPRECT, int);
int AU3_PixelGetColor(int, int);
void AU3_PixelSearch(LPRECT, int, int, int, LPPOINT);
int AU3_ProcessClose(string);
int AU3_ProcessExists(string);
int AU3_ProcessSetPriority(string, int);
int AU3_ProcessWait(string, int);
int AU3_ProcessWaitClose(string, int);
int AU3_Run(string, string, int);
int AU3_RunWait(string, string, int);
int AU3_RunAs(string, string, string, int, string, string, int);
int AU3_RunAsWait(string, string, string, int, string, string, int);
void AU3_Send(string, int);
int AU3_Shutdown(int);
void AU3_Sleep(int);
int AU3_StatusbarGetText(string, string, int, string&, int);
int AU3_StatusbarGetTextByHandle(HWND, int, string&, int);
void AU3_ToolTip(string, int, int);
int AU3_WinActivate(string, string);
int AU3_WinActivateByHandle(HWND);
int AU3_WinActive(string, string);
int AU3_WinActiveByHandle(HWND);
int AU3_WinClose(string, string);
int AU3_WinCloseByHandle(HWND);
int AU3_WinExists(string, string);
int AU3_WinExistsByHandle(HWND);
int AU3_WinGetCaretPos(LPPOINT);
void AU3_WinGetClassList(string, string, string&, int);
void AU3_WinGetClassListByHandle(HWND, string&, int);
int AU3_WinGetClientSize(string, string, LPRECT);
int AU3_WinGetClientSizeByHandle(HWND, LPRECT);
HWND AU3_WinGetHandle(string, string);
void AU3_WinGetHandleAsText(string, string, string&, int);
int AU3_WinGetPos(string, string, LPRECT);
int AU3_WinGetPosByHandle(HWND, LPRECT);
DWORD AU3_WinGetProcess(string, string);
DWORD AU3_WinGetProcessByHandle(HWND);
int AU3_WinGetState(string, string);
int AU3_WinGetStateByHandle(HWND);
void AU3_WinGetText(string, string, string&, int);
void AU3_WinGetTextByHandle(HWND, string&, int);
void AU3_WinGetTitle(string, string, string&, int);
void AU3_WinGetTitleByHandle(HWND, string&, int);
int AU3_WinKill(string, string);
int AU3_WinKillByHandle(HWND);
int AU3_WinMenuSelectItem(string, string, string, string, string, string, string, string, string, string);
int AU3_WinMenuSelectItemByHandle(HWND, string, string, string, string, string, string, string, string);
void AU3_WinMinimizeAll();
void AU3_WinMinimizeAllUndo();
int AU3_WinMove(string, string, int, int, int, int);
int AU3_WinMoveByHandle(HWND, int, int, int, int);
int AU3_WinSetOnTop(string, string, int);
int AU3_WinSetOnTopByHandle(HWND, int);
int AU3_WinSetState(string, string, int);
int AU3_WinSetStateByHandle(HWND, int);
int AU3_WinSetTitle(string, string, string);
int AU3_WinSetTitleByHandle(HWND, string);
int AU3_WinSetTrans(string, string, int);
int AU3_WinSetTransByHandle(HWND, int);
int AU3_WinWait(string, string, int);
int AU3_WinWaitByHandle(HWND, int);
int AU3_WinWaitActive(string, string, int);
int AU3_WinWaitActiveByHandle(HWND, int);
int AU3_WinWaitClose(string, string, int);
int AU3_WinWaitCloseByHandle(HWND, int);
int AU3_WinWaitNotActive(string, string, int);
int AU3_WinWaitNotActiveByHandle(HWND, int);
#import


//+------------------------------------------------------------------+


用法初备
在 MQL5 中使用链接库首先需要调用 AU3_Init 函数初始化 dll。 这一步应该在调用任何其它导入函数之前完成。 函数原型签名类似于 AutoIt 脚本语言中用到的签名,这意味着它们具有相似的函数参数和返回类型。 为了理解这些函数是如何工作的,必须熟悉 AutoIt 脚本语言,所有这些信息都可以在应用程序安装的帮助文件中找到。

函数返回正数值,通常在成功时为 1,失败时为 0。 void 函数的输出既可以是字符串,亦或是结构引用。 对于这些类型的函数,可以调用 AU3_error() 函数来检测是否发生了错误。 当函数失败时,函数简单地输出带有 “0” 的字符串,亦或空结构。 函数输出的字符串引用,还指定了相应的缓冲区大小参数。 这意味着在调用函数之前,应该显式设置经由引用传递的字符串的缓冲区长度。 否则,如果未设置字符串缓冲区长度,将会产生错误标记。 如果分配的缓冲区大小不足,函数将输出与指定空间对应的字符串,舍弃其余字符,从而生成截断字符串。 尚无办法知道输出所需的空间额度,所以有必要了解这个怪癖。 为了设置字符串的缓冲区长度,我们可以调用内置的 MQL5 函数 StringInit。 有一些函数名称中带有 ...ByHandle 后缀,例如 au3_WinCloseByHandle()。 该函数与 AU3_WinClose() 的作用相同,区别在于带有 ByHandle 后缀的函数依据其句柄来识别控件或窗口。 调用这些函数有助于调试,更容易发现与窗口或控件标识相关的错误。


一个初始化示例
以下示例演示了在 MQL5 中调用 AutoItX 函数。 在下面的脚本中,我们将调用 AU3_wingthandle 函数获取终端主窗口的句柄。 终端可依据窗口标题栏中显示的活动帐号进行唯一性识别。

//+------------------------------------------------------------------+
//|                                         TerminalUIComponents.mq5 |
//|                                  Copyright 2021, MetaQuotes Ltd. |
//|                                             https://www.mql5.com  |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link      "https://www.mql5.com "
#property version   "1.00"
#include<autoIt.mqh>


string sbuffer;
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   AU3_Init();//initialize the library

   if(!StringInit(sbuffer,1000))// set buffer length for string
      Print("Failed to set string bufferlength with error - "+string(GetLastError()));

   HWND window_handle=AU3_WinGetHandle(IntegerToString(AccountInfoInteger(ACCOUNT_LOGIN)),"");// get the terminal's handle

   if(!window_handle)
      Print("Could not find main app window. Error is "+string(AU3_error()));

   AU3_WinGetClassListByHandle(window_handle,sbuffer,1000);// get classnames of all user interface componets of the terminal

   Print(sbuffer);

  }
//+------------------------------------------------------------------+



检索主窗口句柄,我们可以调用 AU3_wingtclassistbyhandle 函数来获取更多有关 gui 组件的信息。 它将返回一个字符串列表,这些字符串包含与所提供窗口句柄关联的所有用户界面组件的类名。

运行脚本后的结果如下所示

在我们继续讨论一些更健壮的示例之前,我们创建一个类来封装大多数导入的 AutoIt 函数。

CAutoit 类

CAutoit 将作为基类,其它调用 AutoItX 链接库的类将从其中派生。 它将拥有一个静态属性,指定是否调用了初始化库函数 AU3_Init()。

另一个属性 m_buffer_size 保存方法调用时检测的字符串缓冲区长度。

//+------------------------------------------------------------------+
//|                                                   autoitbase.mqh |
//|                                  Copyright 2021, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link      "https://www.mql5.com "
#include<autoIt.mqh>

enum ENUM_WINDOW_STATE
  {
   SW_HIDE=0,
   SW_SHOW,
   SW_MINIMIZE,
   SW_MAXIMIZE,
   SW_RESTORE
  };

//+------------------------------------------------------------------+
//| Class CAutoIt.                                                   |
//| Purpose:  class for working with autoit.                         |
//+------------------------------------------------------------------+

class CAutoIt
  {
private:
   int               m_buffer_size;                                     //string buffer size
   // --- static property common to all object instances
   static bool       m_initialized;                              //flag for checking initialization state



   //--- private methods
   void              ResetBuffer(string &buffer)      { StringFill(buffer,0); }

public:
   //--- constructor, destructor
                     CAutoIt(void);
                    ~CAutoIt(void);

   void              Init(void);
   //--- static method
   static bool       IsInitialized(void)             { return(m_initialized);     }
   //--- general purpose methods
   int               Error(void)                           { return (AU3_error());      }
   void              Sleep(const int milliseconds)         { AU3_Sleep(milliseconds);   }
   void              SetBufferLen(const int n_bufferlen)   { m_buffer_size=(n_bufferlen>0)?n_bufferlen:1000; }
   int               GetBufferLen(void)                    { return(m_buffer_size);     }

protected:
   int               Run(const string exefile,const string path,const ENUM_WINDOW_STATE w_state) { return(AU3_Run(exefile,path,int(w_state)));  }
   //--- system clipboard manipulation
   void              ClipGet(string & out);
   void              ClipPut(string copy);
   //---
   void              ControlPosition(HWND window_handle,HWND control_handle, LPRECT rect) { AU3_ControlGetPosByHandle(window_handle,control_handle, rect);}
   //--- methods for simulating clicks
   int               ControlRightClick(HWND window_handle, HWND control_handle,int number_of_clicks=1,int x=1,int y=1);
   int               ControlLeftClick(HWND window_handle, HWND control_handle,int number_of_clicks=1,int x=1,int y=1);
   //--- general Control Command method
   bool              ControlCommand(HWND window_handle, HWND control_handle, string command, string command_option);

   //--- methods for interacting with comboboxes, buttons,radio buttons
   string            GetCurrentComboBoxSelection(HWND window_handle, HWND control_handle);
   bool              IsControlEnabled(HWND window_handle, HWND control_handle);
   bool              IsControlVisible(HWND window_handle, HWND control_handle);
   int               EnableControl(HWND window_handle, HWND control_handle) { return(AU3_ControlEnableByHandle(window_handle,control_handle));}
   int               ShowControl(HWND window_handle, HWND control_handle)  { return(AU3_ControlShowByHandle(window_handle,control_handle));  }
   int               ControlFocus(HWND window_handle,HWND control_handle)  { return(AU3_ControlFocusByHandle(window_handle,control_handle)); }
   bool              IsButtonChecked(HWND window_handle, HWND control_handle);
   bool              CheckButton(HWND window_handle, HWND control_handle);
   bool              UnCheckButton(HWND window_handle, HWND control_handle);
   //--- methods for interacting with system32tab control
   string            GetCurrentTab(HWND window_handle, HWND control_handle);
   bool              TabRight(HWND window_handle, HWND control_handle);
   bool              TabLeft(HWND window_handle, HWND control_handle);
   long              TotalTabs(HWND window, HWND systab);
   //--- methods for interacting with syslistview32 control
   bool              ControlListView(HWND window_handle, HWND control_handle, string command, string command_option1, string command_option2);

   long              GetListViewItemCount(HWND window_handle, HWND control_handle);
   long              FindListViewItem(HWND window_handle, HWND control_handle, string find_item,string sub_item);
   string            GetSelectedListViewItem(HWND window_handle, HWND control_handle);
   long              GetSelectedListViewCount(HWND window_handle, HWND control_handle);
   long              GetListViewSubItemCount(HWND window_handle, HWND control_handle);
   string            GetListViewItemText(HWND window_handle, HWND control_handle,string item_index,string sub_item_index);
   bool              IsListViewItemSelected(HWND window_handle, HWND control_handle, string item_index);
   bool              SelectListViewItem(HWND window_handle, HWND control_handle, string from_item_index,string to_item_index);
   bool              SelectAllListViewItems(HWND window_handle, HWND control_handle);
   bool              ClearAllListViewItemSelections(HWND window_handle, HWND control_handle);
   bool              ViewChangeListView(HWND window_handle, HWND control_handle);
   //--- general methods for various types of controls
   HWND              ControlGetHandle(HWND window_handle, string control_id);
   string            ControlGetText(HWND window_handle, HWND control_handle);
   int               ControlSetText(HWND window_handle,HWND control_handle,string keys)   { return(AU3_ControlSetTextByHandle(window_handle,control_handle,keys));}
   int               ControlSend(HWND window_handle, HWND control_handle, string keys, int mode);
   bool              SetFocus(HWND window_handle,HWND control_handle) { return(AU3_ControlFocusByHandle(window_handle,control_handle)>0); }
   //--- methods for interacting with systreeview32 control
   bool              ControlTreeView(HWND window_handle, HWND control_handle, string command, string command_option1, string command_option2);
   long              GetTreeViewItemCount(HWND window_handle, HWND control_handle, string item);
   string            GetSelectedTreeViewItem(HWND window_handle, HWND control_handle);
   string            GetTreeViewItemText(HWND window_handle, HWND control_handle,string item);
   bool              SelectTreeViewItem(HWND window_handle, HWND control_handle,string item);
   //--- general methods for application windows, subwindows and dialogues
   int               WinClose(string window_title, string window_text) { return(AU3_WinClose(window_title,window_text)); }
   int               WinClose(HWND window_handle)                        { return(AU3_WinCloseByHandle(window_handle));    }
   string            WinGetText(HWND window_handle);
   int               WinMenuSelectItem(HWND window_handle, string menu_name_1, string menu_name_2, string menu_name_3, string menu_name_4, string menu_name_5, string menu_name_6, string menu_name_7, string menu_name_8);
   int               WinSetState(HWND window_handle, ENUM_WINDOW_STATE new_state);
   string            WinGetTitle(HWND window_handle);
   ENUM_WINDOW_STATE WinGetState(HWND window_handle)         { return((ENUM_WINDOW_STATE)AU3_WinGetStateByHandle(window_handle)); }
   HWND              WinGetHandle(string window_title, string window_text);
   void              WinGetPosition(HWND window_handle, LPRECT winpos)   { AU3_WinGetPosByHandle(window_handle,winpos);                       }
   void              WinClientSize(HWND window_handle, LPRECT winsize)    { AU3_WinGetClientSizeByHandle(window_handle,winsize);               }
   int               WinExists(HWND window_handle)                       { return(AU3_WinExistsByHandle(window_handle));                      }
   int               WinExists(string window_title, string window_text)   { return(AU3_WinExists(window_title,window_text));                   }
  };

bool CAutoIt::m_initialized=false;
//+------------------------------------------------------------------+
//| Constructor without parameters                                   |
//+------------------------------------------------------------------+
CAutoIt::CAutoIt(void): m_buffer_size(1000)
  {
  }
//+------------------------------------------------------------------+
//| Destructor                                                       |
//+------------------------------------------------------------------+
CAutoIt::~CAutoIt(void)
  {
  }

//+------------------------------------------------------------------+
//|Initializes AutoIt library                                        |
//+------------------------------------------------------------------+

void CAutoIt::Init(void)
  {
   if(!m_initialized)
     {
      AU3_Init();
      m_initialized=true;
     }

  }

//+------------------------------------------------------------------+
//|Reads and outputs textual contents of system clipboard            |
//+------------------------------------------------------------------+
void CAutoIt::ClipGet(string &out)
  {
   if(StringBufferLen(out)<m_buffer_size)
      StringInit(out,m_buffer_size);

   ResetBuffer(out);

   AU3_ClipGet(out,m_buffer_size);

  }
//+------------------------------------------------------------------+
//|Writes text to system clipboard                                   |
//+------------------------------------------------------------------+
void CAutoIt::ClipPut(string copy)
  {
   AU3_ClipPut(copy);
  }
//+------------------------------------------------------------------+
//|Simulates a left click                                            |
//+------------------------------------------------------------------+
int CAutoIt::ControlLeftClick(int window_handle,int control_handle,int number_of_clicks=1,int x=1,int y=1)
  {
   return(AU3_ControlClickByHandle(window_handle,control_handle,"left",number_of_clicks,x,y));
  }
//+------------------------------------------------------------------+
//|Simulates a right click                                           |
//+------------------------------------------------------------------+
int CAutoIt::ControlRightClick(int window_handle,int control_handle,int number_of_clicks=1,int x=1,int y=1)
  {
   return(AU3_ControlClickByHandle(window_handle,control_handle,"right",number_of_clicks,x,y));
  }
//+------------------------------------------------------------------+
//|Sends a command to a control                                      |
//+------------------------------------------------------------------+
bool CAutoIt::ControlCommand(int window_handle,int control_handle,string command,string command_option)
  {
   string m_buffer;
   StringInit(m_buffer,m_buffer_size);

   AU3_ControlCommandByHandle(window_handle,control_handle,command,command_option,m_buffer,m_buffer_size);

   if(StringFind(m_buffer,"0")>=0)
      return(false);

   return(true);
  }
//+------------------------------------------------------------------+
//|Retrieves text of currently selected option of a Combobox Control |
//+------------------------------------------------------------------+
string CAutoIt::GetCurrentComboBoxSelection(int window_handle,int control_handle)
  {
   string m_buffer;
   StringInit(m_buffer,m_buffer_size);

   AU3_ControlCommandByHandle(window_handle,control_handle,"GetCurrentSelection","",m_buffer,m_buffer_size);

   return(m_buffer);

  }
//+------------------------------------------------------------------+
//|Checks if a button is clickable                                   |
//+------------------------------------------------------------------+
bool CAutoIt::IsControlEnabled(int window_handle,int control_handle)
  {
   return(ControlCommand(window_handle,control_handle,"IsEnabled",""));
  }
//+------------------------------------------------------------------+
//|Checks if a control is visible                                    |
//+------------------------------------------------------------------+
bool CAutoIt::IsControlVisible(int window_handle,int control_handle)
  {
   return(ControlCommand(window_handle,control_handle,"IsVisible",""));

  }
//+------------------------------------------------------------------+
//|Checks if tickbox is ticked                                       |
//+------------------------------------------------------------------+
bool CAutoIt::IsButtonChecked(int window_handle,int control_handle)
  {

   return(ControlCommand(window_handle,control_handle,"IsChecked",""));

  }
//+------------------------------------------------------------------+
//| Ticks a tick box                                                 |
//+------------------------------------------------------------------+
bool CAutoIt::CheckButton(int window_handle,int control_handle)
  {
   return(ControlCommand(window_handle,control_handle,"Check",""));
  }
//+------------------------------------------------------------------+
//|Unticks a tick box                                                |
//+------------------------------------------------------------------+
bool CAutoIt::UnCheckButton(int window_handle,int control_handle)
  {

   return(ControlCommand(window_handle,control_handle,"UnCheck",""));
  }
//+------------------------------------------------------------------+
//|Gets text of currently enabled tab of SysTabControl32 control     |
//+------------------------------------------------------------------+
string CAutoIt::GetCurrentTab(int window_handle,int control_handle)
  {
   string m_buffer;
   StringInit(m_buffer,m_buffer_size);

   AU3_ControlCommandByHandle(window_handle,control_handle,"CurrentTab","",m_buffer,m_buffer_size);

   return(m_buffer);
  }
//+------------------------------------------------------------------+
//|Enables the tab to the left in SysTabControl32 control            |
//+------------------------------------------------------------------+
bool CAutoIt::TabLeft(int window_handle,int control_handle)
  {
   return(ControlCommand(window_handle,control_handle,"TabLeft",""));
  }
//+------------------------------------------------------------------+
//|Enables the tab to the right in SysTabControl32 control           |
//+------------------------------------------------------------------+
bool CAutoIt::TabRight(int window_handle,int control_handle)
  {
   return(ControlCommand(window_handle,control_handle,"TabRight",""));
  }
//+------------------------------------------------------------------+
//|Sends a command to a ListView32 control                           |
//+------------------------------------------------------------------+
bool CAutoIt::ControlListView(int window_handle,int control_handle,string command,string command_option1,string command_option2)
  {
   string m_buffer;
   StringInit(m_buffer,m_buffer_size);

   AU3_ControlListViewByHandle(window_handle,control_handle,command,command_option1,command_option2,m_buffer,m_buffer_size);

   if(StringFind(m_buffer,"1")>=0)
      return(true);

   return(false);
  }
//+------------------------------------------------------------------+
//|Gets number of items in ListView32 control                        |
//+------------------------------------------------------------------+
long CAutoIt::GetListViewItemCount(int window_handle,int control_handle)
  {
   string m_buffer;
   StringInit(m_buffer,m_buffer_size);

   AU3_ControlListViewByHandle(window_handle,control_handle,"GetItemCount","","",m_buffer,m_buffer_size);

   return(StringToInteger(m_buffer));
  }
//+-------------------------------------------------------------------------------------------+
//|retrievs the index of a ListView32 control item that matches find_item and sub_item strings|
//+-------------------------------------------------------------------------------------------+
long CAutoIt::FindListViewItem(int window_handle,int control_handle,string find_item,string sub_item)
  {
   string m_buffer;
   StringInit(m_buffer,m_buffer_size);

   AU3_ControlListViewByHandle(window_handle,control_handle,"FindItem",find_item,sub_item,m_buffer,m_buffer_size);

   return(StringToInteger(m_buffer));
  }
//+------------------------------------------------------------------+
//|gets the string list of all selected ListView32 control items     |
//+------------------------------------------------------------------+
string CAutoIt::GetSelectedListViewItem(int window_handle,int control_handle)
  {
   string m_buffer;
   StringInit(m_buffer,m_buffer_size);

   AU3_ControlListViewByHandle(window_handle,control_handle,"GetSelected","1","",m_buffer,m_buffer_size);

   return(m_buffer);
  }
//+------------------------------------------------------------------+
//|returns number of currently selected ListView32 control items     |
//+------------------------------------------------------------------+
long CAutoIt::GetSelectedListViewCount(int window_handle,int control_handle)
  {
   string m_buffer;
   StringInit(m_buffer,m_buffer_size);

   AU3_ControlListViewByHandle(window_handle,control_handle,"GetSelectedCount","","",m_buffer,m_buffer_size);

   return(StringToInteger(m_buffer));
  }
//+------------------------------------------------------------------+
//|gets number of sub items in ListView32 control                    |
//+------------------------------------------------------------------+
long CAutoIt::GetListViewSubItemCount(int window_handle,int control_handle)
  {
   string m_buffer;
   StringInit(m_buffer,m_buffer_size);

   AU3_ControlListViewByHandle(window_handle,control_handle,"GetSubItemCount","","",m_buffer,m_buffer_size);

   return(StringToInteger(m_buffer));
  }
//+---------------------------------------------------------------------+
//|returns text of single ListView32 control item referenced by an index|
//+---------------------------------------------------------------------+
string CAutoIt::GetListViewItemText(int window_handle,int control_handle,string item_index,string sub_item_index)
  {
   string m_buffer;
   StringInit(m_buffer,m_buffer_size);

   AU3_ControlListViewByHandle(window_handle,control_handle,"GetText",item_index,sub_item_index,m_buffer,m_buffer_size);

   return(m_buffer);
  }
//+------------------------------------------------------------------+
//|Checks if a certain ListView32 control item is selected           |
//+------------------------------------------------------------------+
bool CAutoIt::IsListViewItemSelected(int window_handle,int control_handle,string item_index)
  {
   return(ControlListView(window_handle,control_handle,"IsSelected",item_index,""));
  }
//+------------------------------------------------------------------+
//|Selects a certain ListView32 control                              |
//+------------------------------------------------------------------+
bool CAutoIt::SelectListViewItem(int window_handle,int control_handle,string from_item_index,string to_item_index)
  {
   return(ControlListView(window_handle,control_handle,"Select",from_item_index,to_item_index));
  }
//+------------------------------------------------------------------+
//|selects all listview items                                        |
//+------------------------------------------------------------------+
bool CAutoIt::SelectAllListViewItems(int window_handle,int control_handle)
  {
   return(ControlListView(window_handle,control_handle,"SelectAll","",""));
  }

//+------------------------------------------------------------------+
//|Deselects all currently selected item in a ListView32 control     |
//+------------------------------------------------------------------+
bool CAutoIt::ClearAllListViewItemSelections(int window_handle,int control_handle)
  {
   return(ControlListView(window_handle,control_handle,"SelectClear","",""));
  }
//+------------------------------------------------------------------+
//| Change listview control view to details mode                     |
//+------------------------------------------------------------------+
bool CAutoIt::ViewChangeListView(int window_handle,int control_handle)
  {
   string m_buffer;
   StringInit(m_buffer,m_buffer_size);

   AU3_ControlListViewByHandle(window_handle,control_handle,"ViewChange","list","",m_buffer,m_buffer_size);

   if(StringFind(m_buffer,"1")>=0)
      return(true);

   return(false);
  }
//+------------------------------------------------------------------+
//|returns handle for a control                                      |
//+------------------------------------------------------------------+
HWND CAutoIt::ControlGetHandle(int window_handle,string control_id)
  {
   return(AU3_ControlGetHandle(window_handle,control_id));
  }
//+------------------------------------------------------------------+
//|returns visible text from a control                               |
//+------------------------------------------------------------------+
string CAutoIt::ControlGetText(int window_handle,int control_handle)
  {
   string m_buffer;
   StringInit(m_buffer,m_buffer_size);

   AU3_ControlGetTextByHandle(window_handle,control_handle,m_buffer,m_buffer_size);

   return(m_buffer);
  }
//+------------------------------------------------------------------+
//|directs keyboard presses to a certain control                     |
//+------------------------------------------------------------------+
int CAutoIt::ControlSend(int window_handle,int control_handle,string keys,int mode)
  {
   return(AU3_ControlSendByHandle(window_handle,control_handle,keys,mode));
  }
//+------------------------------------------------------------------+
//|Sends a command to a TreeView32 control                           |
//+------------------------------------------------------------------+
bool CAutoIt::ControlTreeView(int window_handle,int control_handle,string command,string command_option1,string command_option2)
  {
   string m_buffer;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值