MT4 programmatically resizing and positioning of current chart window

 

Goal: I usually have my charts(over 20) maximized but at certain times, for comparrison, I want to have only two charts filling the whole window: 
one to the left with 100% height and 50% width and another one to the right with the same dimensions. 
I'm aware that I can do this manually but to get it right needs a lot of fuzzing around each time. 
I would prefer to have an indicator with a button in each chart to do this manipulation. 

I added a screen shot for clarification. to charts side by side

I know how to write the indicator, button and events etc. but I'm totally stuck with the resizing and positioning. 
Built-in mql4 functions do not achieve this so I started using user32.dll but I totally suck at c++.

Through hours of google search I got something that at least compiles and runs without error but unfortunately does nothing:

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

bool SetWindowPos(
            int hWnd,
            int hWndInsertAfter,
            int  X,
            int  Y,
            int  cx,
            int  cy,
            int uFlags
);

int      UpdateWindow(int hWnd);
int      MoveWindow(int hWnd,int X,int Y,int nWidth,int nHeight,int bRepaint);
bool     EnableWindow(int hWnd,bool bEnable);

#import

// ... standard indicator code

// my lousy effort

void Update() {
  int wHnd = (int)ChartGetInteger(0, CHART_WINDOW_HANDLE, 0);
  int wHndParent = GetParent(wHnd);
  EnableWindow(wHnd, true);
  bool pos = SetWindowPos(wHnd, 
                          wHnd, // tried wHndParent as well here ... don't know what's expected



150, 300, 300, 200,
0x0040 // taken from some web example );    Print("wHnd:  ", wHnd, "   wHndParent:  ", wHndParent, "  pos:  ", pos);
  // prints: wHnd:  1249230   wHndParent:  49416798  pos:  true
}
// event handler void OnChartEvent(const int id,                   const long &lparam,                   const double &dparam,                   const string &sparam)   { //---     if (id==CHARTEVENT_CLICK) {       Update();     }      }

Maybe there's some c++ guru around here willing to help me out with this.
Thanks in advance


 
  

 
Set up your screens the way you want them. Save as a Profile. Switch profiles. done.
 

yeah, well, thanks. Of course I'm aware of this option. Still I would like to achieve this as described. 

There certainly must be a way to do this, because the menu bar contains a button that plots all open charts in a grid layout. 

This is basically what I need. Resizing and positioning of individual charts.  

 

... made some progress :) 

  MoveWindow(wHndParent, 0, 0, (int)(width*0.5), height, true);
  EnableWindow(wHndParent, true);
  UpdateWindow(wHndParent);
  SetForegroundWindow(wHndParent);

Using MoveWindow or SetWindowPos needs the parent window as first argument. 

The current chart window is resized and positioned alright now and the chart itself is functional ... 
BUT the title bar of the window remains disabled and I can neither manually resize nor move the window.  
In the title bar of the window,  to the right, the icons(minimize, maximize, close) are missing as well.
So obviously this window is somehow disabled.

resize and reposition chart window programmatically V2

... as always, any help, comment etc. highly welcome :) 
thanks
 

 

Solved :) 

  int wHnd = (int)ChartGetInteger(0, CHART_WINDOW_HANDLE, 0);
  int wHndParent = GetParent(wHnd);
  ShowWindow(wHndParent, SW_RESTORE); // value is 9 
  EnableWindow(wHndParent, true);
  MoveWindow(wHndParent, 0, 0, (int)(ScreenWidth*0.5), ScreenHeight, true);

had to add ShowWindow with 2nd argument set to 9. 

works just as desired