FindWindowW() retiurning 0 when used within Indicator code

 

Hello Friends


Please help me look into this code. It works well inside EA to addach custom indicator to chart.

But when used as an indicator, it doesn't work. It Opens the indicator Dialogue, but doesn't click "OK" to add the indicator to chart.

The code is MQL4

Thanks

#import "user32.dll"
   int  RegisterWindowMessageW(string MessageName);
   int  PostMessageW(int hwnd,int msg,int wparam,uchar &Name[]);
   int  FindWindowW(string lpszClass,string lpszWindow);
#import

#define VK_RETURN 13 //ENTER key


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+  
void StartCustomIndicator(int hWnd,string IndicatorName,bool AutomaticallyAcceptDefaults=false)
{
   Sleep(200);
   uchar name2[];
   StringToCharArray(IndicatorName,name2);
   int MessageNumber=RegisterWindowMessageW("MetaTrader4_Internal_Message");
   int r=PostMessageW(hWnd,MessageNumber,15,name2);
   Sleep(200);
   if(AutomaticallyAcceptDefaults) {
      Print("Custom Indicator - "+IndicatorName);
      int ind_settings = FindWindowW(NULL, "Custom Indicator - "+IndicatorName);
      
      PostMessageW(ind_settings,0x100,VK_RETURN,name2);
     
   }
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void AddIndicator(string indicator_name)
{
 int hWnd = WindowHandle(Symbol(), 0);
 StartCustomIndicator(hWnd, indicator_name, true);
}
Step on New Rails: Custom Indicators in MQL5
Step on New Rails: Custom Indicators in MQL5
  • www.mql5.com
I will not list all of the new possibilities and features of the new terminal and language. They are numerous, and some novelties are worth the discussion in a separate article. Also there is no code here, written with object-oriented programming, it is a too serous topic to be simply mentioned in a context as additional advantages for developers. In this article we will consider the indicators, their structure, drawing, types and their programming details, as compared to MQL4. I hope that this article will be useful both for beginners and experienced developers, maybe some of them will find something new.