//+------------------------------------------------------------------+
//|                                                   SmallOrder.mq4 |
//|                                              Copyleft © 2011, LV |
//+------------------------------------------------------------------+
#property link      ""
//+------------------------------------------------------------------+
#import "user32.dll"
	int GetForegroundWindow();
	int GetTopWindow(int hWnd);
      int GetNextWindow(int hWnd, int wCmd);
	bool GetWindowRect(int hWnd, int& Pos[]);  
	int SendMessageA(int hWnd, int Msg, int  wParam, string lParam);
	int MoveWindow(int hWnd, int X, int Y, int nWidth, int nHeight, int bRepaint);
	int GetWindow(int hWnd, int uCmd);
	int ShowWindow(int hWnd, int nCmdShow);
	
#import
//+------------------------------------------------------------------+
#define WM_GETTEXT  	0x000D

#define SW_SHOWDEFAULT  10

#define GW_CHILD 		5
#define GW_HWNDFIRST	0
#define GW_HWNDNEXT 	2

#define RECT_LEFT		0
#define RECT_TOP		1
#define RECT_RIGHT 	2
#define RECT_BOTTOM	3
//+------------------------------------------------------------------+
			// x, y (top left) l, h (size), repaint (true / false)
int LayOut[] = 	{0, 0, 360, 300, 1,		// Main order window

			 0, 10, 60, 20, 1, 		// Label "Symbol"
			 70, 10, 80, 20, 1,  		// Box (Symbol)
			 
			 180, 10, 60, 20, 1, 		// Label "Volyme"
			 0, 0, 0, 0, 1, 			// unknown
			 250, 10, 80, 20, 1, 		// Box (Volyme)
			 			 
			 0, 40, 60, 20, 1,		// Label "Stop Loss"
			 70, 40, 60, 20, 1, 		// Box (Stop Loss)
			 
			 180, 40, 60, 20, 1, 		// Label "Take Profit"
			 250, 40, 60, 20, 1,		// Box (Take Profit)
			 
			 310, 40, 20, 20,	1,		// up/dn "Take Profit"
			 
			 0, 0, 0, 0, 1, 			// Label "Comment" 
			 0, 0, 0, 0, 1,			// Box (Comment) 
			 
			 0, 70, 60, 20, 1, 		// Label "Type" 
			 70, 70, 120, 20,	1,		// Box (Type)
			 
			 0, 0, 0, 0, 1, 			// unknown
			 
			 130, 40, 20, 20, 1,		// up/dn "Stop Loss"
			 
			 20, 160, 310, 100, 1, 		// tick chart
			 
			 180, 0, 70, 30, 1, 		// button (Sell)
			 20, 0, 70, 30, 1, 		// button (Buy)
			 100, 0, 70, 30, 1, 		// button (Close)
			 
			 315, 30, 12, 12, 1, 		// Slipage on/off (radio with text)
			 
			 0, 0, 0, 0, 1, 			// Label "Maximum der..."
			 270, 5, 43, 15, 1, 		// Label (text in the slipage box)
			 270, 5, 60, 15, 1, 		// Box (slipage)
			 
			 0, 0, 0, 0, 1, 			// Label "pips"
			 
			 0, 0, 0, 0, 1, 			// cosmetics
			 
			 0, 0, 0, 0, 1,			// Label "Bid / Ask"
			 
			 0, 110, 360, 40, 1, 		// buy / sell backgrond "pane"
			 
			 0, 0, 0, 0, 1,			// Unknown			 
			 0, 0, 0, 0, 1,			// Unknown
			 0, 0, 0, 0, 1,			// Unknown
			 0, 0, 0, 0, 1,			// Unknown
			 0, 0, 0, 0, 1,			// Unknown
			 0, 0, 0, 0, 1,			// Unknown
			 0, 0, 0, 0, 1,			// Unknown
			 0, 0, 0, 0, 1,			// Unknown
			 0, 0, 0, 0, 1,			// Unknown
			 0, 0, 0, 0, 1,			// Unknown
			 0, 0, 0, 0, 1,			// Unknown
			 0, 0, 0, 0, 1,			// Unknown			 
			 0, 0, 0, 0, 1,			// Unknown			 
			 0, 0, 0, 0, 1,			// Unknown
			 0, 0, 0, 0, 1,			// Unknown
			 0, 0, 0, 0, 1,			// Unknown
			 0, 0, 0, 0, 1,			// Unknown
			 0, 0, 0, 0, 1,			// Unknown
			 0, 0, 0, 0, 1,			// Unknown
			 0, 0, 0, 0, 1,			// Unknown
			 0, 0, 0, 0, 1,			// Unknown
			 0, 0, 0, 0, 1,			// Unknown
			 0, 0, 0, 0, 1,			// Unknown
			 0, 0, 0, 0, 1,			// Unknown	
			 0, 0, 0, 0, 1,			// Unknown			 
			 0, 0, 0, 0, 1,			// Unknown
			 0, 0, 0, 0, 1,			// Unknown
			 0, 0, 0, 0, 1,			// Unknown
			 0, 0, 0, 0, 1,			// Unknown
			 0, 0, 0, 0, 1,			// Unknown
			 0, 0, 0, 0, 1,			// Unknown
			 0, 0, 0, 0, 1,			// Unknown
			 0, 0, 0, 0, 1,			// Unknown
			 0, 0, 0, 0, 1,			// Unknown
			 0, 0, 0, 0, 1,			// Unknown
			 
			 0, 0, 0, 0, 1,			// cosmetics
			 0, 0, 0, 0, 1,			// Unknown
			 0, 0, 0, 0, 1,			// Unknown
			 0, 0, 0, 0, 1,			// Unknown		
			 	 			 
			 0, 00, 150, 20, 1, 		// Button (OK)
			 170, 00, 150, 20, 1, 		// Button (Print)
			 80, 00, 150, 20, 1, 		// Button (Cancel)
			 0, 30, 340, 20, 1, 		// Label (info about order procecing)
			 
			 20, 100, 340, 50, 1};		// order procecing backgrond "pane"
			 
int LayOut.i;
int LayOut.Size;
			 			
int rect[4];

//+------------------------------------------------------------------+
int ModWindow(int hwnd) {
	
	int h, i;
		
	hwnd = GetWindow(hwnd, GW_HWNDFIRST);
	
	while(hwnd != 0 && LayOut.i < LayOut.Size-4) {
	
		i = LayOut.i;
		LayOut.i += 5;		
		
		MoveWindow(hwnd, rect[RECT_LEFT] + LayOut[i], 
				     rect[RECT_TOP] + LayOut[i+1], 
				     LayOut[i+2], 
			     	     LayOut[i+3], 
			     	     LayOut[i+4]);
		
		hwnd = GetWindow(hwnd, GW_HWNDNEXT);
			
		h = GetWindow(hwnd, GW_CHILD);
		if(h != 0) ModWindow(h);
	}
	
	return(0);
}
//+------------------------------------------------------------------+
int start() {
	
	LayOut.Size = ArraySize(LayOut);
	
	while(true) {
	
		int rect[4];
	
		string str;	

		int hwnd = GetForegroundWindow();
		
		str = "                            ";
		SendMessageA(hwnd, WM_GETTEXT, 6, str);
		if(StringFind(str, "Order") != -1) {		
		
			GetWindowRect(hwnd, rect);  	
		
			MoveWindow(hwnd, rect[RECT_LEFT] + LayOut[0], 
					     rect[RECT_TOP] + LayOut[1], 
					     LayOut[2], 
					     LayOut[3], 1);
				
			LayOut.i = 5;				
			ModWindow(GetWindow(hwnd, GW_CHILD));
			
			ShowWindow(hwnd, SW_SHOWDEFAULT);				
		}
	
		Sleep(5000);
	}
	

	return(0);
}
//+------------------------------------------------------------------+