//+------------------------------------------------------------------+
//| gs_SetSmblVisibleCharts.mq4 |
//| Copyright © 2013, akaGS |
//| http://www.gustis.narod.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property show_inputs
extern string Smbl = "EURUSD";
extern bool AllCharts = FALSE;
#import "user32.dll"
int GetWindow(int hWnd, int uCmd);
int GetParent(int hWnd);
int GetDlgItem(int hDlg, int nIDDlgItem);
bool IsIconic(int hWnd);
bool IsZoomed(int hWnd);
int SendMessageA(int hWnd,int Msg,int wParam,int lParam);
int PostMessageA(int hWnd,int Msg,int wParam,int lParam);
bool SetWindowTextA(int hWnd, string lpString);
int GetWindowRect (int hwnd,int & RECT[]);
#import
//--- WINUSER.H
#define GW_HWNDNEXT 2
#define GW_CHILD 5
// message
#define WM_ACTIVATE 0x0006
#define WM_KEYDOWN 0x0100
#define WM_KEYUP 0x0101
//--- Virtual Keys, Standard Set
#define VK_RETURN 0x0D
#define VK_ESCAPE 0x1B
#define VK_SPACE 0x20
#define WM_MDIACTIVATE 0x0222
//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+
int start()
{
//---- get handle client window area
int hwnd=WindowHandle(Symbol(), Period());
//-- Activate Chart were the script was dropped
int hWnd=GetParent(hwnd); // top level ChartWin handle
int WinParent=GetParent(hWnd); // Client
SendMessageA(WinParent,WM_MDIACTIVATE,hWnd,0); // for MT5 http://www.mql5.com/en/forum/387
int RECT[4];
GetWindowRect(hwnd,RECT); // coordinates of the upper left corner
int hwnd_x_dropt=RECT[0]; // remember the left X coordinate
int cnt=0;
while(hwnd>0){
GetWindowRect(hwnd,RECT);
if((!IsIconic(GetParent(hwnd)) && RECT[0]>=hwnd_x_dropt) || AllCharts) { // if win is not minimized and X-coordinate is to the right of the dropped
SetChart(hwnd,Smbl,NULL); // Set Symbol
cnt++;
}
hwnd=GetWindow(GetParent(hwnd),GW_HWNDNEXT); // get next Chart toplevel handle
hwnd=GetWindow(hwnd,GW_CHILD); // return to client eria
}
//---------
return(0);
}
//+------------------------------------------------------------------+
void SetChart(int hwnd, string smb, int tf)
{
// int hwnd=WindowHandle(Symbol(), Period()); // curent chart client area
PostMessageA(hwnd, WM_KEYDOWN, VK_SPACE, 0); // Sleep(30); // pause for init edit box
hwnd=GetDlgItem(hwnd, 0x45A); // edit box
PostMessageA(hwnd, WM_KEYDOWN, VK_ESCAPE, 0); // exit editing
SetWindowTextA(hwnd, smb+" "+tf); // set Symbol
PostMessageA(hwnd, WM_KEYDOWN, VK_RETURN, 0); // press virtual key ENTER
}
Comments