Automation with button and mouse click interception. - page 9

 
YuraZ >> :

SP2 XPPRO

If there is a lot of software installed on the machine, anything can happen.

If your target OS runs a small stable and tested set of tasks or one

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

there's usually no problem.


I have a much smaller library. Replaced it, saw once managed to replace the expert in the line, but the terminal crashed. I tried it once again but it would not work. It displays -1, i.e. the command is incorrect. Although what is wrong is unclear, because it worked once.


Decided to play around in a virtual machine on different operating systems.

 
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 can find and replace the function name in the codes Ilnur or mine, if not difficult to expose your library too.

I have XP Pro SP3.

Library attached.

Files:
user32_1.zip  305 kb
 

Tried the libraries, the terminal always crashes when running the script.

I installed a bare, clean Windows, the same thing, the switch does not work, even if you browbeat the monitor.


I don't know what to do. I'm at a complete standstill, I'm going to put off trying to implement it again until better times.....

 
// Зайцев Ю. В. YURAZ
//
// программируем на API 
// передать данные в SysDateTimePick32 можно через ХУК ,  но хуки не люблю  
// потому проколотим дату кнопками ввода
// 
// 


#define GW_HWNDNEXT                    2

#define WM_ACTIVATE                    0x0006
#define WM_ENABLE                      0x000A
#define WM_SETFOCUS                    0x0007

#define WM_KEYDOWN                     0x0100
#define WM_KEYUP                       0x0101

#define VK_TAB                         0x09
#define VK_RIGHT                       0x27


#define GW_CHILD                       5

// ID 
#define _ID_TESTER                     0x053      // дескриптор ТЕСТЕРА     
#define _ID_TW                         0x81BF     // дескриптор окна TESTERA
#define _ID_TERMINAL                   0xE81E

#define _ID_NAV                        0xE81B     // навигатор


#import "user32.dll"
   int      SendMessageA(int hWnd,int Msg,int wParam,string lParam);
   int      PostMessageA(int hWnd,int Msg,int wParam,int lParam);
   int      GetWindowTextA(int hWnd,string lpString,int nMaxCount);
   int      GetDlgItem(int hDlg, int nIDDlgItem);
   int      GetAncestor(int hWnd, int gaFlags);
   int      GetWindow(int hWnd,int uCmd);
#import


void start()
{


   int hMetaTrader = GetAncestor(WindowHandle(Symbol(),Period()),2);              // Дескриптор основного окна терминала
   Print("hMetaTrader = ", hMetaTrader," || ", DecToHex( hMetaTrader));

   int hTerminal = GetDlgItem( hMetaTrader, _ID_TERMINAL );                                // Дескриптор окна валютной пары
   Print("hTerminal = ", hTerminal," || ", DecToHex( hTerminal));

   int hTester = GetDlgItem( hTerminal, _ID_TESTER );                                     // Дескриптор окна тестера стратегий
   Print("hTester = ", hTester," || ", DecToHex( hTester));   

// хитро вычисляем окошко объекта 
   int hOt  =  GetWindow( FindHendlKey( GetDlgItem( hTester,_ID_TW), "От:" ), GW_HWNDNEXT);
   Print("hOt = ", hOt," || ", DecToHex( hOt));  // для отладки покажем HENDL окна ввода даты

//
// тупо нажимаем дату  2001.03.27
//
    SendMessageA ( hOt, WM_ACTIVATE ,       1,  0 ); // Активизируем
    SendMessageA ( hOt, WM_ENABLE   ,       1,  0 );
    SendMessageA ( hOt, WM_SETFOCUS ,       1,  0 );

 
    PostMessageA ( hOt, WM_KEYDOWN  ,       0x032   ,  1 ); //  0x32 код '2'
    Sleep(1000);
    PostMessageA ( hOt, WM_KEYDOWN  ,       0x030   ,  1 ); //  
    Sleep(1000);
    PostMessageA ( hOt, WM_KEYDOWN  ,       0x030   ,  1 ); //
    Sleep(1000);
    PostMessageA ( hOt, WM_KEYDOWN  ,       0x031   ,  1 ); // 2001 
    Sleep(1000);
    PostMessageA ( hOt, WM_KEYDOWN  ,       VK_RIGHT,  1 ); // .
    Sleep(1000);
    PostMessageA ( hOt, WM_KEYDOWN  ,       0x030   ,  1 ); // 12
    Sleep(1000);
    PostMessageA ( hOt, WM_KEYDOWN  ,       0x033   ,  1 ); // 03
    Sleep(1000);
    PostMessageA ( hOt, WM_KEYDOWN  ,       VK_RIGHT,  1 ); // .
    Sleep(1000);
    PostMessageA ( hOt, WM_KEYDOWN  ,       0x032   ,  1 ); //  27
    Sleep(1000);
    PostMessageA ( hOt, WM_KEYDOWN  ,       0x037   ,  1 ); // 
    Sleep(1000);
    SendMessageA ( hOt, WM_KEYDOWN  ,       VK_TAB  ,  0 );
    Sleep(1000);
 
}

 
 
 
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
string DecToHex(int n)
  {
   string s = "", c;
   while( n != 0)
     {
      if( n%16 < 10)
          c = CharToStr( n % 16 + '0');
      else 
          c = CharToStr( n % 16 + 'A'-10);
      s = c + s;
      n = n / 16;
     }
   return( s);
  }

//+------------------------------------------------------------------+
//
// прощелкать объекты
// ищем объект по имени 
//
//+------------------------------------------------------------------+

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);
}

HIDDEN 04.05.2009 14:20



Further on yourselves ... in the sense of generating the right keypad codes,,,, for the input date


 


Perhaps the LVN_COLUMNCLICK function is suitable , but it doesn't work.

 

Can you tell me how to catch the window called by F9 (Order)?

Can't find it by text.

So far it has been caught as follows:

int hwnd=GetAncestor(WindowHandle(name,Period()),2);//main terminal handle

string s=""; 

hdlg=GetLastActivePopup(hwnd);//FindWindowA(0,s);

 if(hdlg!=hwnd){

         GetWindowTextA(hdlg,s,GetWindowTextLengthA(hdlg)+1);//работает, надо s=""   

         Print(s);

} 
 
//------------------------------------------------------------------    F9
void F9()
{
        int h=WindowHandle(Symbol(),Period());  // хэндл графика
        int hMetaTrader=GetAncestor(h, 2);  // хэндл МТ
        PostMessageA(h, WM_COMMAND, 35458, 0); // открываем F9
}

Warrant window handle in Russian MT

        int h=FindWindowA ("#32770", "Ордер");

--------

Use Spy++ to search for resource identifiers in windows

 

This only works if Russian is selected in the terminal, but if, for example, the client has Chinese in the terminal?

I need another way to search in chinese.

So far, the option I mentioned works.

 

DKeN:

as long as the option I mentioned works.

congratulations, what do you want then?

you can search the windows for some unique resources that are only available in this one by F9.

 

After FindWindowA you should also check the thread/process ID for the found window (function GetWindowThreadProcessId), because the found order window may belong to another metatrader copy.

Reason: