Automation with button and mouse click interception. - page 10

 
DKeN:

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:

This does not seem to me to be a reliable method at all. Try to open some other window when the order window is open, for example chart properties, or terminal settings, or global variables, etc. What window will GetLastActivePopup show you?
 

Hello!

Can you tell me how to determine the MT descriptor from an EA running in the tester?

The construct:

int hMetaTrader = GetAncestor(WindowHandle(Symbol(),Period()),2);              // Дескриптор основного окна терминала
does not work, because
WindowHandle(Symbol(),Period())

Returns 0.

 

Is a graph like this open at this point? (with the specified symbol and period)

 
Meat:

Is a graph like this open at this point? (with specified symbol and period)

Yes, of course.

Tried it both ways.

Or is it a feature of WindowHandle function (although there is no word about it in help...)

Or maybe I'm dumb...

 
lasso:

Yes, of course.

Tried it both ways.

Or it's peculiarity of WindowHandle function (though help doesn't say anything about it...)

Or maybe I'm dumb...

In visualisation mode, the handle is working without any problems. And you are probably testing NOT in visual mode. Then it makes sense: no window, no handle. As for the other open windows, as I understand it, they are not accessible from the tester.
In that case, the only way out is to search for a Metatrader window in the list of all windows using FindWindowExA(...)
 
Meat:

In visualization mode, the handle is obtained without any problems. But you must be testing NOT in visual mode. Then it makes sense: no window, no handle. As for the other open windows, I understand that they are not accessible from the tester.
In that case, the only way out is to search for the required window in the list of all windows using FindWindowExA(...).

Yes, I tried to apply Ilnur's code from page 5:


Ilnur:

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

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

But from tester this trick didn't work. (I'm launching another terminal for optimization from tester and want to track completion of this process.)

If it's not too difficult, can you give me an example for FindWindowExA(...) or a link?

 

Here I have such a function for finding a window:

#import "user32.dll"
  int FindWindowExA(int hwndParent,int hwndChildAfter, string lpClassName, string lpWindowName);       
  int GetWindowThreadProcessId(int hWnd,int lpdwProcessId);
  int GetWindowTextA(int hWnd,string lpString,int nMaxCount);
#import

//инициализируем текстовый буффер длиной 128 байт. Вообще должен быть 255 байт! Но он не влезает на экран, из-за чего окно форума сильно растягивается :)
string textbuf="АбвгдежзийклмнопрстуфхцчшщъыьэюяАбвгдежзийклмнопрстуфхцчшщъыьэюяАбвгдежзийклмнопрстуфхцчшщъыьэюяАбвгдежзийклмнопрстуфхцчшщъыьэюя";

int FindWindow(string class, string caption, bool captionexactly=false)
{    
  //int CurrentThreadID=GetWindowThreadProcessId(WindowHandle(Symbol(),Period()),0);
  string null_string;
  int h=0;
  while(true)
  {    
    if (captionexactly)
      h=FindWindowExA(0,h,class,caption);
     else
      h=FindWindowExA(0,h,class,null_string);
    if (h==0) return(0);
    //if (GetWindowThreadProcessId(h,0)!=CurrentThreadID) continue;
    if (captionexactly) return(h);
    int len=StringLen(caption);
    if (GetWindowTextA(h,textbuf,128)<len) continue;
    if (StringSubstr(textbuf,0,len)==caption) return(h);  
  }
  return(0);
}
 

Look up the class name and title of the required window in SPY++.

I commented out the thread ID check because it is not needed in this case (there is no source window to compare).

In general, I advise you to handle WinAPI functions, if you're going to use them. Please refer to MSDN(http://msdn.microsoft.com/en-us/library/ff818516.aspx) for detailed description of the functions.

 
cm=GetDlgItem(hdlg,ID_SYMBOL);
int pos=SendMessageA(cm,CB_GETCOUNT,0,0);//get number in the list
//find the pair
string fs=";
for(int l=0;l<pos;l++){
int ll=SendMessageA(cm,CB_GETLBTEXT,l,fs);
Print(ll," ",fs);
}

please advise how to correctly get a list of tools in the Order window (F9)?

I get the number of elements, but can not get exactly the rows by number, returns -1.

#define ID_SYMBOL 0x053E //character name to select

cmhandle ComboBox


 
Meat:

Here I have such function for window search:


Alexey, thanks, the function works, but...
Meat:

I've commented out the flow ID check because it's not needed in this case (we don't have a source window to compare).


Just the thread ID is needed, as I have two terminals involved.

I got out of it through header identification, but I would still like to know how to determine flow ID from under the tester?