Automation with button and mouse click interception. - page 7

 
HIDDEN >> :

Found an interesting window. It is almost impossible to catch anything in it. The window is called "Save as". Can you tell me how to press the "Save" button?

If you select the save button specifically, you have the button code 00000001

But nothing happens when calling it by this code. What is this unnamed window?

This is a popup dialog box. Its system descriptor can be obtained using the WinAPI function GetLastActivePopup(int hWnd).

Here is an example of how to use this function:

#include <WinUser32.mqh>

#import "user32.dll"
   int GetAncestor(int hWnd, int gaFlags);
   int GetDlgItem(int hDlg, int nIDDlgItem);
   int GetLastActivePopup(int hWnd);
#import

void start()
{
   int hMetaTrader, hDlg, hButtonSave, hChart = WindowHandle(Symbol(),Period());

   hMetaTrader = GetAncestor(hChart,2);          //дескриптор основного окна терминала
   PostMessageA(hMetaTrader,WM_COMMAND,57604,0); //вызываем окно сохранения
   Sleep(100);
   hDlg = GetLastActivePopup(hMetaTrader);       //получаем дескриптор всплывающего окна
   hButtonSave = GetDlgItem(hDlg,1);             //определяем дескриптор кнопки "Сохранить"
   PostMessageA(hDlg,WM_CO MMAND,1,hButtonSave);  //нажимаем на кнопку
}
 

The checkboxes can be ticked programmatically if they are not present.

What Win API functions are used to do this?

 

Found a function in the WinAPI:


CheckDlgButton function

Description:
function CheckDlgButton(Dlg: HWnd; IDButton: Integer; Check: Word);

Marks or unmark a button control or changes the state of a three-button control.

Parameters:
Dlg: The dialog box that contains the button.
IDButton: The modifiable control of the button.

Checks: deleted(0), marked(1), shaded(2).


Before executing it which function to check the state of the button. In my case it is in the checkbox.

 
Ilnur >> :



in continuation of the API theme

when saving - if this happens again the question will arise!

save as

( file exists replace )


hit YES automatically


#include <WinUser32.mqh>

#import "user32.dll"
   int GetAncestor(int hWnd, int gaFlags);
   int GetDlgItem(int hDlg, int nIDDlgItem);
   int GetLastActivePopup(int hWnd);
#import

void start()
{
   int hMetaTrader, hDlg, hButtonSave, hChart = WindowHandle(Symbol(),Period());

   hMetaTrader = GetAncestor( hChart,2);          //дескриптор основного окна терминала
   PostMessageA( hMetaTrader, WM_COMMAND,57604,0); //вызываем окно сохранения
   Sleep(100);
   hDlg = GetLastActivePopup( hMetaTrader);       //получаем дескриптор всплывающего окна
   hButtonSave = GetDlgItem( hDlg,1);             //определяем дескриптор кнопки "Сохранить"

   PostMessageA( hDlg, WM_COMMAND,1, hButtonSave);  //нажимаем на кнопку ,
   Sleep(100);

// и тут может возникнуть еще один диалог ФАЙЛ СУЩЕСТВУЕТ  - сохранять ДА НЕТ
 
   int hDlg1 = GetLastActivePopup( hMetaTrader);      //  получаем дескриптор всплывающего окна СОХРАНЯТЬ ИЛИ НЕТ
   int hButtonYES = GetDlgItem( hDlg1,6);             //  определяем дескриптор кнопки  ДА  ID кнопки ДА он равен = 6
    PostMessageA( hDlg1, WM_COMMAND,6, hButtonYES);  // мы подтверждаем ДА


}
 
HIDDEN >> :

Found a function in the WinAPI:


CheckDlgButton function

Description:
function CheckDlgButton(Dlg: HWnd; IDButton: Integer; Check: Word);

Labels or unchecks a button control or changes the state of a three-button control.

Parameters:
Dlg: The dialog box that contains the button.
IDButton: The modifiable control of the button.

Checked: deleted(0), marked(1), shaded(2).


Before executing it which function to use to check the state of the button. In my case in checkbox.


You can use the IsDlgButtonChecked function to determine the current state of the switch:

UINT WINAPI IsDlgButtonChecked(HWND hdlg, int idButton);

This function returns the state of the switch with idButton located in the hdlg dialog box. If the switch is in a disabled state, a null value is returned. A value of 1 is returned for a switch that is on. A value of 2 corresponds to an inactive switch, shown in grey. In case of an error, a negative value of -1 is returned.

---


An example of how IsDlgButtonChecked works can be seen here

http://frolov-lib.ru/books/bsp/v12/ch3_2.htm

 

Decided to get back to the subject of WinAPI study.

I'm trying to use Microsoft Spy++ v.9.00.21022 to find the identifier of the "Optimization" checkbox in order to check whether it is ticked or not.

I do the following step by step.

1. Started terminal.

2. opened tester window.


3. In Spy++ I searched for a window and pointed to the "Optimize" element.


Clicked OK button.

4. Running through the tabs of the next window


I can't figure out where my code for this button is.


Ilnur ,YuraZ and others teach me to identify this descriptor code I need.



Why do I ask to teach you, not to point specifically to the codes, because I want to learn to identify other elements. Although if you specify it may be easier for me to find them later, knowing what to look for and where to look....

 

Here I have given a code example on how to find the identifier of the "Start" button.

The same figure shows how to find the identifier of the control.

All controls located in the strategy tester window are defined in the same way.

For example, according to the picture above, the identifier of the "Optimization" checkbox (General tab) is 0x405.

 
I've got the codes sorted out. The only thing I can't find the codes for the 2 buttons is the date for testing and optimisation from "Date" to "Date". The program outputs 00000001. Ilnur tell me the codes of these buttons.
 
HIDDEN >> :
I've got it sorted out. The only thing I can't find codes of 2 buttons - date for testing and optimization from "Date" to "Date". Program outputs 00000001. Ilnur tell me the codes of these buttons.

Yes, indeed, the identifiers of these items are the same. Therefore, we cannot use GetDlgItem() in this case.

This leaves the option of identifying them using FindWindowExA(). However, the main question is whether we need to identify them.

It is not possible to manage these items, i.e. to specify the optimization or testing period, by means of the WinAPI in MQL.

Although I may be wrong.

 
Ilnur >> :

Yes, indeed, the identifiers of these items are the same. Therefore, we cannot use GetDlgItem() in this case.

This leaves the option of identifying them using FindWindowExA(). However, the main question is whether we need to identify them.

The possibility to manage these items, i.e. to specify optimization or testing period, by means of the WinAPI in MQL is missing.

I may be wrong though.



find an item with ID - 0x0577 (click on Change Expert button)

and click NextWindow 3 times just to get into the From date field: then try NextWindow twice more and we will get into the To date field:

in both cases just fill date fields

SetWindowTextA( hwndEditDATEbeg, sDateBeg);

SendMessageA(hwndEditDATEbeg, EN_UPDATE, _ID_EDIT_HEX_DATEbeg, 0);
SendMessageA(hwndEditDATEbeg, EN_CHANGE, _ID_EDIT_HEX_DATEbeg, 0);

..

In MSQL5 I'd really like to get a built-in tool for communication with the tester...

Reason: