Removing Toolbars programatically

 

Is there a way to remove (or toggle) the toolbar on an undocked chart in MQL5? AFAIK there is no chart operation function or chart property directly accessing this feature.

Do I need to do this through the win API?

This toolbar is a minor annoyance when creating user interfaces since it has to be turned off manually, and it would be nice to suppress an unnecessary real-estate expense uglying up my nice interface :)

 
el_looto:

Is there a way to remove (or toggle) the toolbar on an undocked chart in MQL5? AFAIK there is no chart operation function or chart property directly accessing this feature.

Do I need to do this through the win API?

This toolbar is a minor annoyance when creating user interfaces since it has to be turned off manually, and it would be nice to suppress an unnecessary real-estate expense uglying up my nice interface :)

first, the return value of ChartGetInteger(chartID,CHART_WINDOW_HANDLE)  is a HWND of a child window, not of the main window created by ChartOpen() function.

This HWND can be found by GetParent() function in winuser.h.

we know this is the main windows HWND because resizing this via SetWindowPos() works properly, unlike when we try to SetWindowPos() on the return value of ChartGetInteger(chartID,CHART_WINDOW_HANDLE), which only resizes the chart canvas.

GetMenu() for this returns 0 (no menu attached) for the parent window, but does return a menu for the chart window.

Neither of the usual methods of SetMenu(hwnd,NULL) or Destroy(hmenu) get rid of the toolbar.

It seems likely to my limited ability, that the toolbar is a child of the main window (like the chart is).

To be proper we should use EnumChildWindows, but I cant get it to work probably by sheer lack of coding talent.

so we are reduced to using GetWindow() and a bit of trial and error.

----------------------------------------

After some play we see that the first child window is the chart, and the next one is the toolbar. there is no third window which simplifies things a bit and we dont need a loop. It would be easy to do if necessary later, but it probably wont be.

So heres how to eliminate the toolbar, programatically, from an undocked chart:

//can we assume that the code below goes in sensible places and should not be used "as-is"?
//and that defined constants are already done....

//we are going to need the winuser headers

#include <WinAPI\winuser.mqh>

//assuming we need to open a chart first and undock the chart

   long chartID = ChartOpen(pair,tf);
   ChartSetInteger(chartID,CHART_IS_DOCKED,false);

//get the hwnd of the chart

   long chartHWND = ChartGetInteger(chartID,CHART_WINDOW_HANDLE);

//but we need the HWND of the main window for further processing

   long parentHWND = GetParent(chartHWND);

//then we can find the HWND of the toolbar
//first we get the HWND of the highest zorder child window

   long child = GetWindow(parentHWND,GW_CHILD);

// child is actually equal to chartHWND at this point. we could use an if or a while loop to proceed if they were not the same
//but we dont need to so.....
//we recycle the child var as we would if we used a while loop to wrap this

   child = GetWindow(child,GW_HWNDNEXT);

//since this child is not equal to the chartHWND we can then kill it... but...
//DestroyWindow() cant be used since the window was created in a different thread
//so we go back to the old days of "MQL4 ugly kludge just to make simple things happen" and...
//just hide the window.

   ShowWindow(child,SW_HIDE);

//then we can force a redraw by resizing the undocked window. in this case to 800x600.
//if we dont do this then it will look like the title bar is fat and ugly...

   uint flags = SWP_NOMOVE + SWP_NOZORDER;
   SetWindowPos(parentHWND,HWND_TOP, 0 ,0, 800, 600, flags);

//NOTE: YOU WILL NOT BE ABLE TO MANUALLY TURN THE TOOLBAR BACK ON :D


Someone can let me know if theres a simpler way....


Chur,

el Looto

 

Hi, sorry for undigging this old thread but maybe someone could complete the code to make it into a script? Sorry, I don't know MQL but need it. Any help is much appreciated.

 

Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
          No free help (2017)

Or pay someone. Top of every page is the link Freelance.
          Hiring to write script - General - MQL5 programming forum (2018)

We're not going to code it for you (although it could happen if you are lucky or the problem is interesting).
          No free help (2017)

 
You didn't say hello. I did exactly state what the problem was. Your tone suggests you are missing a sense of self-importance outside this forum.
 
Jay Kay # I did exactly state what the problem was.

You did not; you stated a want. The problem is you are too lazy to learn to code; you want it done for you. Sorry, snowflake, no slaves here just waiting to code for you.

 
Nearly every forum has its own idiot (or a few) who has often no value added in his posts but gets off while sheriffing and patronizing others. I guess on mql5.com this will be you. I didn't ask for your advice so go on and do something useful.
 
ha 
Files:
 

Trinh Dat, this is so much appreciated! Thank you!

Have a great day.

 
use ALT + D
to restore/switch?
 
Thank you Michael for this tip. Yes, this short cut works but it doesn't hide the toolbars. This code does, however I was initially hoping it will also remove the top title bar as well, which unfortunately it doesn't.
Reason: