Automation with button and mouse click interception. - page 5

 
xeon >> :

It was a good terminal : -)))

We all have one of those terminals. And it has a red button in it in a certain sense.

Only you have to bang on your own head with a baton. :))

 

Ilnur, the text of the button can also be read somehow. The program Spy++ reads it.



i.e. the logic is that as long as the button is set to "Stop" we wait for further action to be taken.

Give me a function from User32.dll that pulls the text of the button correctly.



GetDlgItemText function

Description:
function GetDlgItemText(Dlg: HWnd; IDDlgItem: Integer; Str: PChar; MaxCount: Integer): Integer;
Reads the text of the control.
Parameters:
Dlg: Identifier of the dialog box.
IDDlgItem: The ID of the item.
Str: Buffer to receive text.
MaxCount: The size of the buffer.
Returned value:
The actual number of characters copied.


#import "user32.dll"

string GetDlgItemText (int hWnd, int IDDlgItem, string PChar, int MaxCount);

#import


Am I connecting the function correctly.


Because the terminal shows me in the logs

2008.11.15 21:03:41 tester EURUSD,H1: cannot call function 'GetDlgItemText' from dll 'user32.dll' (error 127)

 
xeon >> :

That was a good terminal : -)))

Xeon, you're the one who started it all....

I wouldn't have gone into that step myself... but I don't need to....

 
HIDDEN >> :

. . .

#import "user32.dll"

string GetDlgItemText (int hWnd, int IDDlgItem, string PChar, int MaxCount);

#import


Am I connecting the function correctly.


Because the terminal shows me in the logs

2008.11.15 21:03:41 tester EURUSD,H1: cannot call function 'GetDlgItemText' from dll 'user32.dll' (error 127)

It's more like this . . .
#import "user32.dll"
   int GetDlgItemTextA(int hWnd, int IDDlgItem, string PChar, int MaxCount);
#import
 
Ilnur >> :
>> it's more like this. . .

This will return an integer number, but you need the text of the button.

 
HIDDEN >> :

This will return an integer number, but you need the text of the button.

The text is returned in the PChar string buffer.

The function itself returns the actual number of characters read.

 
HIDDEN >> :

Ilnur, the text of the button can also be read somehow. The program Spy++ reads it.


Here is an example of a script that starts a strategy tester and waits for it to complete. The text of the button is read using GetWindowTextA().

Interestingly, the tester window does not necessarily have to be visible in this case.


#include <WinUser32.mqh>

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

void start()
{
   int hMetaTrader, hTerminal, hTester, hButtonStart;
      
   hMetaTrader = GetAncestor(WindowHandle(Symbol(),Period()),2); //дескриптор основного окна терминала
	
   hTerminal = GetDlgItem(hMetaTrader,0xE81E);
   hTester = GetDlgItem(hTerminal,0x53);
   hButtonStart = GetDlgItem(GetDlgItem(hTester,0x81BF),0x40A);  //дескриптор кнопки "Старт"
	
   PostMessageA(GetDlgItem(hTester,0x81BF),WM_COMMAND,0x40A,hButtonStart); //нажимаем кнопку старт
   
   Print("Запуск тестера стратегий");
   string sButtonStartName = "";
   while(!IsStopped()) 
   {
      Sleep(3000);
      GetWindowTextA(hButtonStart,sButtonStartName,6); //считываем текст кнопки запуска тестера
      if(sButtonStartName=="Старт")                    
      {
         Print("Работа тестера завершена");
         break;
      }
   }
}
 
Ilnur >> :

Here is an example of a script that starts a strategy tester and waits for it to complete. The text of the button is read using GetWindowTextA().

Interestingly, the tester window does not have to be visible.


Thank you very much. Where can I at least read about all these functions and look at examples of their use? I've been poking around all over the Internet looking for it, but it's not very helpful. Maybe there is a good book on Win API? A bare description of what the function does is still not enough.

 
HIDDEN >> :

Thank you very much. Where can I at least read about all of these functions, and look at examples of how to use them? I've been poking around all over the Internet looking for it, but it's not very helpful. Maybe there is a good book on Win API? A bare description of what this function does may be insufficient.

All information about WinAPI functions I get from MSDN. I'm used to it this way.

P.S. I've never seen a good book on WinAPI, unfortunately.

 
Ilnur >> :

I get all the information on WinAPI functions from MSDN. I'm more accustomed to ....


P.S. Unfortunately, I've never seen a good book on WinAPI.

How do the menus that open on the first button of the mouse get intercepted? When you switch to another program from the terminal, the menu disappears and you just can't catch it. Is there any way to stop the program?

Reason: