How can I get windows handle of currently active(focused) chart?

 
Let suppose that 2 terminals are running in my system and each terminal has few opened charts. My question is that if there is any way to get the window handle of the chart which is currently active using any mql function or system DLL?
 

If you want the current chart, there is the function WindowHandle() from MQL and you may find some other, probably usefull functions in the "Chart Operations" part in the documentation. But I am confused if you want to know also which of the two terminals is active in your machine; in that case, that topic may help you to some extent https://www.mql5.com/en/forum/139341 

 

best regards 

 
I know about WindowHandle() but I asked that I want to know Handle for currently focused/Active chart. WindowHandle() returns only chart handle in which EA is running. Let suppose that I clicks on EURUSD chart window that means now EURUSD chart is focused window . Now I need a function which can tell me Handle for this EURUSD chart.
 
Go here grab "boost_2.mq4" and look at the function IsTopWindow at the bottom. The function does exactly what you are asking for. Testing for the active Window.
 
kjaved8:
I know about WindowHandle() but I asked that I want to know Handle for currently focused/Active chart. WindowHandle() returns only chart handle in which EA is running. Let suppose that I clicks on EURUSD chart window that means now EURUSD chart is focused window . Now I need a function which can tell me Handle for this EURUSD chart.

There is no function to know which chart/window is active on mql4 (unless you run a custom code on each window), so you need to use WINAPI. Check the documentation.

 
Kashif Javed:
Let suppose that 2 terminals are running in my system and each terminal has few opened charts. My question is that if there is any way to get the window handle of the chart which is currently active using any mql function or system DLL?

Hi, the following code should help you. <link removed>

   long currChart,prevChart=ChartFirst(); 
   int i=0,limit=100; 
   while(i<limit)// We have certainly not more than 100 open charts 
     { 
      currChart=ChartNext(prevChart); // Get the new chart ID by using the previous chart ID 
      if(currChart<0) break;          // Have reached the end of the chart list 
      if(ChartGetInteger(currChart,CHART_BRING_TO_TOP) == 1)
        {
         Alert ("Current active chart: ",ChartSymbol(currChart));
         break;
        }
      prevChart=currChart;// let's save the current chart ID for the ChartNext() 
      i++;// Do not forget to increase the counter 
     }   
 
Boris Armenteros:

Hi, the following code should help you. <link removed>

Link to commercial site is not allowed on this forum.

Your code is buggy and do not answer the question.

 
Alain Verleyen:

Link to commercial site is not allowed on this forum.

Your code is buggy and do not answer the question.

OK, well noted. Kindly tell us where is the bug in the code. Here it is attached. We just included it in an empty indicator and made a small addition so it shows the windows handle of the currently active (focused) chart. Was not this the initial question of Kashif? Best
Files:
 
Boris Armenteros:
OK, well noted. Kindly tell us where is the bug in the code. Here it is attached. We just included it in an empty indicator and made a small addition so it shows the windows handle of the currently active (focused) chart. Was not this the initial question of Kashif? Best

Forum on trading, automated trading systems and testing trading strategies

How can I get windows handle of currently active(focused) chart?

Boris Armenteros, 2017.08.16 17:47


Hi, the following code should help you. <link removed>

   long currChart,prevChart=ChartFirst(); 
   int i=0,limit=100; 
   while(i<limit)// We have certainly not more than 100 open charts 
     { 
      currChart=ChartNext(prevChart); // Get the new chart ID by using the previous chart ID 
      if(currChart<0) break;          // Have reached the end of the chart list 
      if(ChartGetInteger(currChart,CHART_BRING_TO_TOP) == 1)
        {
         Alert ("Current active chart: ",ChartSymbol(currChart));
         break;
        }
      prevChart=currChart;// let's save the current chart ID for the ChartNext() 
      i++;// Do not forget to increase the counter 
     }   

If the first chart is a the top, it will not be found.

CHART_BRING_TO_TOP is documented as write-only. It can not be used with ChartGetInteger().

Chart Properties - Chart Constants - Standard Constants, Enumerations and Structures - MQL4 Reference
Chart Properties - Chart Constants - Standard Constants, Enumerations and Structures - MQL4 Reference
  • docs.mql4.com
Chart Properties - Chart Constants - Standard Constants, Enumerations and Structures - MQL4 Reference
 
Alain Verleyen:

If the first chart is a the top, it will not be found.

CHART_BRING_TO_TOP is documented as write-only. It can not be used with ChartGetInteger().


Yes, we know it's documented but check in the file we attached how ChartGetInteger() uses CHART_BRING_TO_TOP with no issues.

Of course, this piece of code could be improved but this was just intended to help to find a solution to the initial question of this topic. We assume that's what it's all about, isn't it?

Chart Operations - MQL4 Reference
Chart Operations - MQL4 Reference
  • docs.mql4.com
Chart Operations - MQL4 Reference