Update script that Changes all templates using UserDLL to only affect certain charts

 

Hello

I have this script which works great, and changes *all* my charts to a selected template.  But I have various fx pairs and oil and gold, and I don't want the template change to affect the oil and gold as I have different templates for them, so I have to keep changing them after running the script.
I have played at length with it, and yet find this user32 work impenetrable; I'm not from a Windows programming background.

From experience, I'm thinking there is probably only a small change to make but everything I try, fails.  Even print statements aren't always printed (I've looked in the logs, not just the terminal to check this).  And when it does print/alert, Symbol appears null.

Can anyone tell me where I might need to change this to ignore ChartSymbol() == "XAUUSD" etc please?  I'm sensitive to asking people to write code for me, and only doing this as I reckon it's a 1-liner that will be quick to comment on.  A link to a forum post will do, but I've failed to find one thus far.  Thanks IA

#property copyright "Copyright � 2011, zznbrm"
#property show_inputs

#include <WinUser32.mqh>

#import "user32.dll"
   int      PostMessageA(int hWnd,int Msg,int wParam,int lParam);
   int      GetWindow(int hWnd,int uCmd);
   int      GetParent(int hWnd);
#import

extern int tplndex = 0;

int start() {
        bool blnContinue = true;
        int intParent = GetParent( WindowHandle( Symbol(), Period() ) );
        int intChild = GetWindow( intParent, GW_HWNDFIRST );
        
        if (intChild > 0) {
                if(intChild != intParent) {
                        PostMessageA(intChild, WM_COMMAND, 34800 + tplndex, 0);
                }
        } else {
                blnContinue = false;
        }
        
        while(blnContinue) {
                intChild = GetWindow(intChild, GW_HWNDNEXT);
                if(intChild > 0) {
                        if(intChild != intParent) {
                                PostMessageA( intChild, WM_COMMAND, 34800 + tplndex, 0 );
                        }
                } else {
                         blnContinue = false;
                }
        }

        // Now do the current window
        PostMessageA( intParent, WM_COMMAND, 34800 + tplndex, 0 );
        return(0);
}
 

You'll want to be using PostMessageW (not PostMessageA) - a change from ansi to unicode came in with build 600.

 
honest_knave:

You'll want to be using PostMessageW (not PostMessageA) - a change from ansi to unicode came in with build 600.

Thanks but that is for posting messages to the thread and I want to get info from a child window. 
 
strontiumDog:
Thanks but that is for posting messages to the thread and I want to get info from a child window. 


TBH I'm a little confused why you would even be bothering with a DLL when you have ChartApplyTemplate()  

void OnStart()
  {
   long chart_id=ChartFirst();
   while(chart_id >= 0)
     {
      if(ChartSymbol(chart_id) != "XAUUSD") ChartApplyTemplate(chart_id,"ADX.tpl");
      chart_id = ChartNext(chart_id);
     }
  }

Edit:

strontiumDog:

as I reckon it's a 1-liner that will be quick to comment on.


OK, in one line then

for(long i=ChartFirst(); i>=0; i=ChartNext(i)) if(ChartSymbol(i) != "XAUUSD") ChartApplyTemplate(i,"ADX.tpl");
ChartApplyTemplate - Chart Operations - MQL4 Reference
ChartApplyTemplate - Chart Operations - MQL4 Reference
  • docs.mql4.com
ChartApplyTemplate - Chart Operations - MQL4 Reference
 
honest_knave:


TBH I'm a little confused why you would even be bothering with a DLL when you have ChartApplyTemplate()  

Edit:


OK, in one line then

Thanks! The reason I'd not done this is that I had the old script around since before ChartApplyTemplate() was available.
 
strontiumDog:
Thanks! The reason I'd not done this is that I had the old script around since before ChartApplyTemplate() was available.


I did wonder that when I saw the date on the code - I'm glad you got it sorted.

Fortunately there have been plenty of new features added over the years.

Reason: