Discussion of article "Managing the MetaTrader Terminal via DLL"

 

New article Managing the MetaTrader Terminal via DLL has been published:

The article deals with managing MetaTrader user interface elements via an auxiliary DLL library using the example of changing push notification delivery settings. The library source code and the sample script are attached to the article.

We have a MetaQuotes ID list containing more than four delivery addresses. As we know, the SendNotification function uses only the IDs set in the Notifications tab of the Options window. Thus, you can send push notifications solely to the previously specified IDs no more than four at a time by means of MQL. Let's try to fix that.

The issue can be solved in two ways – we can either develop the push notification delivery function from scratch, or change the terminal settings and use the standard function. The first option is quite time-consuming and lacks universality. Therefore, I have selected the second one. In their turn, the terminal settings can also be changed in various ways. According to my experience, this can be done via the user interface or by substituting values in the process memory. Working with memory looks much better since it allows users to avoid flashing windows. However, it can disrupt the operation of the entire terminal at the slightest mistake. The worst thing that may happen when working via the UI is a disappearance of a window or a button.

In this article, we will look at managing the terminal via the user interface using an auxiliary DLL library. In particular, we will consider changing the settings. Interaction with the terminal will be performed in usual way, which means using its windows and components. No interference with the terminal process will take place. This method can be applied to solve other issues as well.


1.3. Working with a Menu

Like all other components, working with a menu starts after a parent handle (a certain window) is found. Then, we should find corresponding menu item and sub-item and perform a selection.

Please note: the amount of the terminal menu items changes depending on whether a chart window is expanded or not (see Fig. 2). Item enumeration starts from 0.

Fig. 2. Changing the amount of the menu items

Fig. 2. Changing the amount of the menu items

If the amount of menu items is changed, the Tools item index number is changed as well. Therefore, we should consider the total amount of points using the GetMenuItemCount(Hnd:HMenu) function the menu handle is passed to.

Author: Galina Bobro

 

Nice article! I would also like to add in the section 1.2. Looking for MetaTrader Windows, instead of finding the handle using the account number, I would pass it into my DLL from MQL.

 You can use the following code in MQL to get the window handle:  int handle = WindowHandle(Symbol(), Period());

 Then in the DLL, use a function similar to the one below to find the parent handle:

HWND GetTerminalHandle(int chart_handle)

{

HWND child = (HWND)chart_handle;

HWND parent;

while (true)

{

parent = GetParent((HWND)child);

if (parent == NULL)

break;

else

child = parent;

return child;

}

Reason: