Automation with button and mouse click interception. - page 8

 

There's only a few things left to do, as they say, solve a couple of cases.

This WinAPI is not for pros. This is the first time I'm working with it.


I'm stuck on 2 things.


1. How can I get back the line number by name from the Expert Advisor in ComboBox with a list of Expert Advisors?


I do it like this


#define CB_FINDSTRING 0x014C
#define CB_SETCURSEL  0x014E

hMetaTrader = GetAncestor(WindowHandle(Symbol(),Period()),2);              // Дескриптор основного окна терминала
hTerminal = GetDlgItem( hMetaTrader,0xE81E);                                // Дескриптор окна валютной пары
hTester = GetDlgItem( hTerminal,0x53);                                      // Дескриптор окна тестера стратегий
ExpertsComboBox = GetDlgItem( GetDlgItem( hTester,0x81BF),0x468);            // Дескриптов списка экспертов

int exep = SendMessageA( ExpertsComboBox, 0x014C, 0, "Test_Expert");
Print("Строка № ", exep);

I get zero, and that's it. The same thing I do in the program InqSoft Windows Scanner, it returns the number of the row.


Then I use the function


SendMessageA(ExpertsComboBox, 0x014E, 12, 0);                              // Установка эксперта

Everything works as it should, but I don't know how to get this number 12.


2. this is a problem with inserting the date. YuraZ, you seem to have explained, but I do not understand how to approach what you have explained. I can't figure out how to do it with a clicker either.


Help me finish running automated optimizer, I promise to send me the code, then I want to attach parsing of stored HTML and substitution of the results in the Expert Advisor. No problems with the latter, and the launch of the tester is a pain in the ass. I've learned how to place checkboxes in required places, how to click buttons, but I can't master the issue I've described.


After the completion and testing I want to make it into an article, I think for many people this feature will be useful, although not the fact that the developers will miss this information.

 
HIDDEN >> :

optionally


there is no need to count how many lines there are or else to bother

it is enough to search for our expert "our hero expert" in the list

logically, if you make a counter, you can also raise the number from the list

just find the top of the list and run down or find the bottom and run up

//+------------------------------------------------------------------+
//|                                                                  |
//|                                           YURAZ Copyright © 2008 |
//|                         www.mail.ru yzh@mail.ru yyuraz@gmail.com |
//+------------------------------------------------------------------+
#property copyright "YURAZ Copyright © 2008"
#property link      "www.mail.ru yzh@mail.ru yyuraz@gmail.com"
#include <WinUser32.mqh>
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
   
#define CB_FINDSTRING 0x014C
#define CB_SETCURSEL  0x014E

int hMetaTrader = GetAncestor(WindowHandle(Symbol(),Period()),2);              // Дескриптор основного окна терминала
int hTerminal = GetDlgItem( hMetaTrader,0xE81E);                                // Дескриптор окна валютной пары
int hTester = GetDlgItem( hTerminal,0x53);                                      // Дескриптор окна тестера стратегий
int ExpertsComboBox = GetDlgItem( GetDlgItem( hTester,0x81BF),0x468);            // Дескриптов списка экспертов



/// ищем нашего героя условие мы должны стоять на первом в списке
{ 

  string p1=  "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234";

  GetWindowTextA( ExpertsComboBox , p1 , 250 );
 

   
  
   Print("Имя текущего эксперта ", p1    );
 // можно в цикле пощелкать и найти 
  if ( p1 != "имя нашего героя")
      PostMessageA (ExpertsComboBox, WM_KEYDOWN,VK_DOWN, 0); // Сместились на нужную строчку.
  esle
     // break from  
 }
 
//   если последний толчок клавиши выдает то же самое имя - тормозим цикл
//  это все на уровни идеи описал..  обрисуйте как Вам надо сами
//  ну в смысле текст оформите сами...
//  учтите что если по умолчанию вы стоите в конце списка или в середине ... то логично пробежать список вверх
// а потом вниз   


    return(0);
  }
 
 
// прощелкать объекты

// ищем объект по имени 
int FindHendlMessage( int Current  , string findname   )
{

   string p1=  "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234";
  int temp = GetWindow( Current , GW_CHILD ); // ищем
  while ( temp != NULL )
  {
     GetWindowTextA( temp , p1 , StringLen( findname )+1 ); 
     if ( p1 == findname) // проверим а не тот ли это объект ! имя которог омы знаем     {
        return( temp ); // это то что мы ищем
     }
     int r =   FindHendlKey( temp  ,   findname   ) ; // не значит не она , обойдем ее дочерние объекты
     if ( r != NULL )
     {
        return ( r); // опс нашли дочку
     }
     temp = GetWindow( temp , GW_HWNDNEXT ); // проверяем следующий объект, дочерний 
  }
  return (0);
}

// тут рекурсия - стек должен быть с запасом

//  вставить в начало - мне хватало 4048
#property stacksize   4048 // внимание это обязательно для рекурсии ( пока не замеченно косяков при стеке 4048

int FindHendlKey( int Current  , string findname   )
{
   string p1=  "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234";
  int temp = GetWindow( Current , GW_CHILD ); // ищем
  while ( temp != NULL )
  {
     GetWindowTextA( temp , p1 , StringLen( findname )+1 ); 
     if ( p1 == findname) // проверим а не  тот ли это объект
     {
        return( temp ); // это то что мы ищем
     }
     int r =   FindHendlKey( temp  ,   findname   ) ; // не значит не она , обойдем ее дочерние объекты
     if ( r != NULL )
     {
        return ( r); // опс нашли дочку
     }
     temp = GetWindow( temp , GW_HWNDNEXT ); // проверяем следующий объект, дочерний 
  }
  return (0);
}

 
YuraZ >> :


Thank you, I'll look into it further.

 
HIDDEN >> :

There's only a few things left to do, as they say, solve a couple of cases.

Help, guys, this WinAPI is not for pros. It's the first time I'm working with it.

The code is correct so it should work. I have this code works without any problems.

When an error occurs, the function usually returns -1, not zero. Maybe there is some error in the code.


Another way is to check the correct declaration of the SendMessageA() function to search for a string.

The last parameter should be declared as string. If it is left integer by default the compiler

will swallow the code without error, but the function will not work correctly.

 
Ilnur >> :

The code is correct so it should work. I have this code works without any problems.

When an error occurs, the function usually returns -1, not zero. Maybe there is some error in the code.


Alternatively, you must check the correct declaration of the SendMessageA() function to search for a string.

The last parameter should be declared as string. If it is left integer by default the compiler

will swallow the code without error but the function will work incorrectly.

Try my code in your terminal, maybe my terminal or the library is screwed up.

 

My code for selecting an expert is identical to yours:

hExpertBox = GetDlgItem(hTesterWnd, 0x468);
nPosition = SendMessageA(hExpertBox, CB_FINDSTRING, 0, sExpertName);
SendMessageA(hExpertBox, CB_SETCURSEL, nPosition, 0);

Here sExpertName is the name of the Expert Advisor as a string.


For the sake of purity of the experiment, I ran your code - everything works.

 
Ilnur >> :

My expert selection code is identical to yours:

Here sExpertName is the name of the Expert Advisor as a string.


For the sake of purity of the experiment, I ran your code - everything works.

It's a strange thing... it's not working for me.

What Windows is it and what service pack?

 

Looked at the user32.dll library file on my computer and on the net and there are a bunch of different sized files.

Maybe my problem is that the library itself is crooked.


Ilnur, if it's not hard to post your version of the library here, I'll try to test with it.

Yuraz, and you managed to find and replace the function name by Ilnur's codes or mine, if not hard to post your library too.

 
HIDDEN >> :

Looked at the user32.dll library file on my computer and on the net and there are a bunch of different sized files.

Maybe my problem is that the library itself is crooked.


Ilnur, if you don't mind posting your version of the library here, I'll try to test with it.

Yuraz, and you found and substitute the name of the function in the codes Ilnur or mine, if not difficult your library also expose.

SP2 XPPRO

If you have a lot of software installed on your machine, anything can happen.

if the target OS is either a stable, proven small set of tasks or one

i.e. a lot of programs aren't constantly being run and a lot of things aren't being installed

as a rule there is no problem

Files:
user32.zip  301 kb
Reason: