How to programatically minimize a chart window?

Back to topics list To post a new topic, please log in or register
avatar
372
mar 2016.05.01 23:31
 

Hey coders,

I found a code about how to maximize a chart window by using SendMessage but I can't find something like WM_MDIMINIMIZE. I googled it but I didn't find a command to minimize a window. Can someone help me?

This script is working fine to maximize a chart and I figured out that WM_MDIRESTORE resizes the chart to the size it was before it was maximized. But how can I check if a window is maximized?

 

#import "user32.dll"
int GetParent(int hWnd);
int SendMessageA(int hWnd, int Msg, int wParam, int lParam);
#import
#define WM_MDIMAXIMIZE 0x0225

void OnStart() {
   int hWnd = (int)ChartGetInteger(0, CHART_WINDOW_HANDLE, 0);
   ChartSetInteger(0, CHART_BRING_TO_TOP, true);
   int parent = GetParent(hWnd);
   SendMessageA(GetParent(parent), WM_MDIMAXIMIZE, parent, 0);  
}

 

 

avatar
1213
FMIC 2016.05.02 00:22 #
 

I've never used it myself, but try using the WM_SYSCOMMAND message instead with one of the following constants: SC_CLOSE, SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE (see link below).

https://msdn.microsoft.com/en-us/library/windows/desktop/ms646360%28v=vs.85%29.aspx

// int SendMessageA(int hWnd, int Msg, int wParam, int lParam);
// with Msg = WM_SYSCOMMAND, wParam = SC_MINIMIZE

SendMessageA( hWnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
avatar
372
mar 2016.05.02 00:40 #
 

Unfortunately, it doesn't work with WM_SYSCOMMAND.

I tried to maximize and minimize but no reaction.

Could it be that there is a better way than using SendMessage? I read about ShowWindow here:

https://msdn.microsoft.com/de-de/library/windows/desktop/ms633548(v=vs.85).aspx

I can do some mql4-coding but I have never used Win32 in my programming. So I am a bit lost here. 

 

avatar
372
mar 2016.05.02 00:42 #
 

This is what I tried but without success:

#import "user32.dll"
int GetParent(int hWnd);
bool ShowWindow(int hWnd, int nCmdShow);
#import

#define SW_MAXIMIZE 3
#define SW_MINIMIZE 6
#define SW_RESTORE 9

void OnStart() {
   int hWnd = (int)ChartGetInteger(0, CHART_WINDOW_HANDLE, 0);
   int parent = GetParent(hWnd);
   ShowWindow(GetParent(parent), SW_MINIMIZE);
}

 

avatar
1213
FMIC 2016.05.02 01:26 #
 
mar:

This is what I tried but without success:

Try using the standard "WinUser32.mqh" file provided by MetaQuotes instead of declaring import functions yourself:

#include <WinUser32.mqh>

In that file they have the function declared as:

int ShowWindow(int hWnd,int nCmdShow);


avatar
372
mar 2016.05.02 08:04 #
 

I tried it this way now:

#include <WinUser32.mqh>

#define SW_MAXIMIZE 3
#define SW_MINIMIZE 6
#define SW_RESTORE 9

void OnStart() {
   int hWnd = (int)ChartGetInteger(0, CHART_WINDOW_HANDLE, 0);
   int parent = GetParent(hWnd);
   ShowWindow(GetParent(parent), SW_MINIMIZE);
}

But when I drag that script to an open chart the whole MT4 freezes and I have to close MT4 and reopen it again.

I have no idea if ShowWindow() is really the correct Win32 function to do that. I have looked in different C++ forums but maybe this function can't be used in MQL4. 

But there is absolutely no command to minimize the window when using SendMessage(). Additionally I tried to find out how to get the state of a window (minimized, maximized, normal) but again without success.

GetWindowPlacement() might be a good idea but that goes way beyond my knowledge. I have absolutely no idea how to work with this WINDOWPLACEMENT structure. Examples are only given in C++ or C# and I can't get the solution there. Maybe it'snot possible with MQL4..

https://msdn.microsoft.com/de-de/library/windows/desktop/ms633518(v=vs.85).aspx 

 

avatar
2017
gooly 2016.05.02 11:41 #
 

May be this helps, it is what I have save some time ago about PostMessageW() usage and example:

//WinCommand-Defines: http://forum.mql4.com/30667
                                        /* 00000-32999 not inspected */
                                        /* 33000-33016 unknown */
#define MT4_WMCMD_AUTOSCROLL      33017
#define MT4_WMCMD_BARS            33018
#define MT4_WMCMD_CANDLES         33019
                                        /* 33020       unknown */
#define MT4_WMCMD_GRID            33021
#define MT4_WMCMD_LINE            33022
#define MT4_WMCMD_SHIFT           33023
#define MT4_WMCMD_VOLUMES         33024
#define MT4_WMCMD_ZOOM_IN         33025
#define MT4_WMCMD_ZOOM_OUT        33026
                                        /* 33027-33047 unknown */
#define MT4_WMCMD_EXPERT_INPUTS   33048 /* Open expert Inputs dialog */
                                        /* 33049       unknown */
#define MT4_WMCMD_REMOVE_EXPERT   33050 /* Remove expert advisor from chart */
                                        /* 33051-33053 unknown */
#define MT4_WMCMD_SAVE_AS_PICTURE 33054
#define MT4_WMCMD_3_MONTHS        33057
#define MT4_WMCMD_ALL_HISTORY     33058
#define MT4_WMCMD_LAST_MONTH      33063
#define MT4_WMCMD_SAVE_Statement  33064 
                                        /* 33055-33133 unknown */
#define MT4_WMCMD_PERIOD_D1       33134
                                        /* 33135       unknown */
#define MT4_WMCMD_PERIOD_H4       33136
#define MT4_WMCMD_PERIOD_M1       33137
#define MT4_WMCMD_PERIOD_M5       33138
#define MT4_WMCMD_PERIOD_M15      33139
#define MT4_WMCMD_PERIOD_M30      33140
#define MT4_WMCMD_PERIOD_W1       33141
                                        /* 33142-33156 unknown */
#define MT4_WMCMD_PROPERTIES      33157 /* Chart Properties (F8) */
                                        /* 33158-33176 apparently unused */
#define MT4_WMCMD_PERIOD_SEPARATE 33177 /* Show/hide period separators */
                                        /* 33178-33196 unknown */
#define MT4_WMCMD_MOVE_RIGHT      33197 /* Move right (right/down arrow) */
#define MT4_WMCMD_MOVE_LEFT       33198 /* Move left (left/up arrow) */
                                        /* 33199-33219 unknown */
#define MT4_WMCMD_SAVE_TEMPLATE   33220 /* Save template... */
                                        /* 33221-33229 unknown */
#define MT4_WMCMD_33230           33230 /* Arrow Down */
#define MT4_WMCMD_33231           33231 /* Arrow Up */
#define MT4_WMCMD_33232           33232 /* icons-ticks */
#define MT4_WMCMD_MOUSE_CROSS     33233 /* crosshair */
#define MT4_WMCMD_MOUSE_CURSOR    33234 /* the cursor */
#define MT4_WMCMD_33235           33235 /* Box-cyclical Line */
#define MT4_WMCMD_33236           33236 /* equidistant channel */
#define MT4_WMCMD_33237           33237 /* Fibonacci lines */
#define MT4_WMCMD_33238           33238 /* Box-Fibonacci-arc */
#define MT4_WMCMD_33239           33239 /* Box-Fibonacci-fan */
#define MT4_WMCMD_33240           33240 /* Box Channels, Fibonacci */
#define MT4_WMCMD_33241           33241 /* Box-Gann-grid Hanna */
#define MT4_WMCMD_33242           33242 /* Box-Gann-line Hanna */
#define MT4_WMCMD_33243           33243 /* Box-Gann-fan Hanna */
#define MT4_WMCMD_HLINE           33244 /* horizontal line */
                                        /* 33245       unknown */
#define MT4_WMCMD_33246           33246 /* Box Andrews pitchfork */
#define MT4_WMCMD_33247           33247 /* Box-shape-rectangle */
#define MT4_WMCMD_33248           33248 /* Box-channels-linear regression */
                                        /* 33249-33250 apparently unused */
#define MT4_WMCMD_33251           33251 /* Box-icons-stop */
                                        /* 33252       unknown */
#define MT4_WMCMD_33253           33253 /* text */
#define MT4_WMCMD_33254           33254 /* Box-icons-bad */
#define MT4_WMCMD_33255           33255 /* Box-icons-well */
#define MT4_WMCMD_33256           33256 /* Box-Fibonacci-time-zone */
#define MT4_WMCMD_TRENDLINE       33257 /* trend line */
#define MT4_WMCMD_33258           33258 /* Box-Line-trend line for the corner */
#define MT4_WMCMD_33259           33259 /* Box-figure-triangle */
#define MT4_WMCMD_VLINE           33260 /* Vertical Line */
#define MT4_WMCMD_LABEL           33261 /* text label */
                                        /* 33262-33323 unknown */
#define MT4_WMCMD_UPDATE_DATA     33324 /* This doesn't cause experts start() to run */
                                        /* 33325-33333 unknown */
#define MT4_WMCMD_PERIOD_MN1      33334 /* timeframe MN */
                                        /* 33335-34299 unknown */
#define MT4_WMCMD_34300           34300 /* 34300-34699 custom indicators in alphabetical order */
#define MT4_WMCMD_34700           34700 /* Indicators-moving average of oscillator */
#define MT4_WMCMD_34701           34701 /* Indicators-accelerator oscillator */
#define MT4_WMCMD_34702           34702 /* Indicators-accumulation/distribution */
#define MT4_WMCMD_34703           34703 /* Indicators-alligator */
#define MT4_WMCMD_34704           34704 /* indicators-average directional movement index */
#define MT4_WMCMD_34705           34705 /* indicators-average true range */
#define MT4_WMCMD_34706           34706 /* Indicators-awesome oscillator */
#define MT4_WMCMD_34707           34707 /* Indicators-bears power */
#define MT4_WMCMD_34708           34708 /* indicator-bollinger bands */
#define MT4_WMCMD_34709           34709 /* Indicators-bulls power */
#define MT4_WMCMD_34710           34710 /* Indicators-commodity channel index */
#define MT4_WMCMD_34711           34711 /* Indicators-demarker */
#define MT4_WMCMD_34712           34712 /* Indicators-envelopes */
#define MT4_WMCMD_34713           34713 /* Indicators-force index */
#define MT4_WMCMD_34714           34714 /* Indicators-fractals */
#define MT4_WMCMD_34715           34715 /* Indicators-gator oscillator */
#define MT4_WMCMD_34716           34716 /* Indicators-ichimoku kinko hyo */
#define MT4_WMCMD_34717           34717 /* Indicators-macd */
#define MT4_WMCMD_34718           34718 /* indicators-market facilitation index */
#define MT4_WMCMD_34719           34719 /* Indicators-momentum */
#define MT4_WMCMD_34720           34720 /* indicators-money flow index */
#define MT4_WMCMD_34721           34721 /* indicators-moving averages */
#define MT4_WMCMD_34722           34722 /* Indicators-on balance volume */
#define MT4_WMCMD_34723           34723 /* Indicators-parabolic sar */
#define MT4_WMCMD_34724           34724 /* indicators-relative strength index */
#define MT4_WMCMD_34725           34725 /* indicators-relative vigor index */
#define MT4_WMCMD_34726           34726 /* Indicators-standard deviation */
#define MT4_WMCMD_34727           34727 /* Indicators-stochastic oscillator */
#define MT4_WMCMD_34728           34728 /* Indicators-volumes */
#define MT4_WMCMD_34729           34729 /* Indicators-william's percent range */
                                        /* 34730-34799 unknown */
#define MT4_WMCMD_LOAD_TEMPLATE   34800 /* 34800-34899 load template in alphabetical order */
#define MT4_WMCMD_REMOVE_TEMPLATE 34900 /* 34900-34998 Remove Template in alph. order (conf. dialog) */
#define MT4_WMCMD_KILL_TEMPLATES  34999 /* remove *.tpl (confirmation dialog) */ 
                                        /* 35000-35399 unknown */
#define MT4_WMCMD_PERIOD_H1       35400 /* timeframe H1 */
#define MT4_WMCMD_OBJECTS_LIST    35402 /* open objects list window */
#define MT4_WMCMD_ORDER_BUYLIMIT  35454 /* order buy limit */
#define MT4_WMCMD_ORDER_BUYSTOP   35455 /* order buy stop */
#define MT4_WMCMD_ORDER_SELLLIMIT 35456 /* order sell limit */
#define MT4_WMCMD_ORDER_SELLSTOP  35457 /* order sell stop */
#define MT4_WMCMD_ORDER_MARKET    35458 /* new order (F9) */
#define MT4_WMCMD_35464           35464 /* right price tag */
#define MT4_WMCMD_35511           35511 /* Graphic template-download template */
                                        /* 35512-37011 unknown */
                                        /* 37012-40000 not inspected */
#define MT4_WMCMD_57602           57602 /* close the current chart */
#define MT4_WMCMD_57603           57603 /* Save as (ascii/csv) */
#define MT4_WMCMD_57604           57604 /* Save as (ascii/csv) - apparently same */
#define MT4_WMCMD_PRINT_DIALOG    57607 /* Open Print... Dialog */
#define MT4_WMCMD_PRINT_DIRECT    57608 /* Print immediately */
#define MT4_WMCMD_PRINT_PREVIEW   57609 /* Open Print Preview dialog */
                                        /* 57610-59675 unknown (re-checked up to 58011) */
                                        /* 59675-...   not inspected */

void EnableOrdersHistoryAll(){
   //WinCommand-Defines: http://forum.mql4.com/30667
   // http://forum.mql4.com/ru/14463/page5#401551
   // http://forum.mql4.com/46407#596672
   // 33058 - All History, 33057 - Last 3 Months, 33063 - Last Month
   //#define MT4_WMCMD_ALL_HISTORY 33058
   //#define MT4_WMCMD_3_MONTHS 33057
   //#define MT4_WMCMD_LAST_MONTH 33063
   //int main = GetAncestor(WindowHandle(NULL, _Period), GA_ROOT);
   int main = GetAncestor(WindowHandle(_Symbol, _Period), GA_ROOT);// WindowHandle= mt4 function!!
   //PostMessageW(main, WM_COMMAND, MT4_WMCMD_ALL_HISTORY, 0);
   PostMessageW(main, WM_COMMAND, 33058, 0);
   //Alert("Function EnableAllHistory() disabled");
   Sleep(5000);
}



avatar
372
mar 2016.05.02 12:04 #
 

This is indeed useful Thanks for that. But unfortunately it doesn't help me with minimizing/restoring a chart window.

Maybe it's a good idea to explain what I want to do. I want to make s script which checks the timeframe of all open charts. Then -for example- all charts with timeframes > H4 should be minimized. That has a special reason. I have 30 charts opened on my screen which are set to the D1 timeframe. If the D1 chart shows me something interesting according to my definitions I switch down to H4 or H1. But mostly only 5-6 charts are interesting on the D1 timeframe and so I would like to minimize the rest of the D1 charts which are not interesting for me. So only the ones I want to have a closer look at are opened. That gives me more focus to watch only 5-6 charts instead of seeing them all.

At the end of a trading day I would use another script which restores all minimzed chart windows again so that I can do my EOD analysis.

But to do so I must know how to minimize and restore a chart. Additionally I have to know the state of a window if it's minimized or normal.

Seems to be really hard in MQL4... 

avatar
2017
gooly 2016.05.02 14:37 #
 
mar:

This is indeed useful Thanks for that. But unfortunately it doesn't help me with minimizing/restoring a chart window.

...

Then -for example- all charts with timeframes > H4 should be minimized.

...

My guess: if you couldn't find it in my post it is most probably impossible. :(
avatar
372
mar 2016.05.02 23:10 #
 

I always thought that all functions from Win32 could be used in MQL4. And it is defintely possible to minimize and restore a window programmatically in other languages like C, C++, C#.

 

Back to topics list  

To add comments, please log in or register