How to programmatically maximize a chart window - page 2

 
Not working for me. I'm using WM_COMMAND for the second parameter. But which window handle do I need, the one returned by Window.GetHandle or it's parent, or the parent of that? I've tried all three but without success.
 
GetAncestor
 
Arbu:
Not working for me. I'm using WM_COMMAND for the second parameter. But which window handle do I need, the one returned by Window.GetHandle or it's parent, or the parent of that? I've tried all three but without success.

Either GetParent(GetParent(GetParent( <windowhandle> ))) or GetAncestor(<windowhandle>, 2)

And the limitation with this is that it's the same as pressing the equivalent toolbar button. Therefore, it acts on whichever chart currently has input focus, not (necessarily) the chart running the MQL4 code which sends the message.

 
jjc:

Either GetParent(GetParent(GetParent( <windowhandle> ))) or GetAncestor(<windowhandle>, 2)

And the limitation with this is that it's the same as pressing the equivalent toolbar button. Therefore, it acts on whichever chart currently has input focus, not (necessarily) the chart running the MQL4 code which sends the message.

Thanks. Not a problem that it works on the chart that currently has focus because I'm giving the one I want focus through the steps in this thread. But anyway I'm still not getting it to work. Here's my code:

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

int GetAncestor (int hwnd, int gaFlags);

#import

#define WM_MDIACTIVATE 0x222
#define WM_MDIMAXIMIZE 0x0225
#define WM_COMMAND  0x111

#define MT4_WMCMD_PERIOD_H4       33136

int Window.activate(int hwnd) {
   int p = GetParent(hwnd);
   SendMessageA(GetParent(p), WM_MDIACTIVATE, p, 0);
}
int Window.maximize(int hwnd) {
   int p = GetParent(hwnd);
   SendMessageA(GetParent(p), WM_MDIMAXIMIZE, p, 0);
   SendMessageA(GetAncestor(hwnd,2), WM_COMMAND, MT4_WMCMD_PERIOD_H4,symbol);
}
 
Arbu:

But anyway I'm still not getting it to work. Here's my code:

It works for me if I add something like the following to your code. (I'm also replacing the undeclared "symbol" parameter for the SendMessageA call with 0.) This basically creates an EA which keeps switching itself back to H4:

void start()
{
   if (Period() != PERIOD_H4) Window.maximize(WindowHandle(Symbol(), Period()));
}

However, you really ought to use PostMessage rather than SendMessage. Otherwise, MT4 gets temporarily upset because the SendMessage call changes the timeframe; the EA is reloaded; and all this happens before the SendMessage call completes and returns to the EA... which has now been unloaded.

 
#import "user32.dll"
int PostMessageA(int hWnd,int Msg,int wParam,int lParam);
int GetAncestor (int hwnd, int gaFlags);

#import

#define WM_COMMAND                0x111
#define MT4_WMCMD_PERIOD_H4       33136


int start()
  {
//----
   int HTerminal = GetAncestor(WindowHandle(Symbol(),Period()),2);
   
   PostMessageA(HTerminal ,WM_COMMAND , MT4_WMCMD_PERIOD_H4, 0);

//----
   return(0);
  }
 
Thanks, seems to be working OK now.
 
Arbu:
Thanks, seems to be working OK now.
Although it seems I need to add in a short pause between maximising the window and setting the timeframe - "Sleep(100);". Otherwise the chart window appears at a smaller size, surrounded by black.
 
qjol:

In order to set the timeframe, all you need to do is:

string my_symbol="EURUSD"  //or you can use Symbol()
string my_period=PERIOD_H4 //or you can use Period()

ChartSetSymbolPeriod(ChartId(), my_symbol, my_period);  //sets current chart for symbol and period desired

You can also change those parameters to a different chart than the one the EA is running on, without using DLLs, as I mentioned in: https://www.mql5.com/en/forum/138882#comment_6090096

Opening and closing charts via scripts
Opening and closing charts via scripts
  • 2012.04.06
  • www.mql5.com
Hi, i have a script that can identify price action bars to give probable trade signals...
 

This is an old post. Today there are built-in functions in both Mql4 and Mql5 to maximize a chart window easily, without using DLL's:


ChartSetInteger(chart_id, CHART_BRING_TO_TOP, true);


Regards.

Reason: