Hi,
I have the following program from the net modified to open an offline chart. But all it does it
open the offline chart-list. The key down and selecting the chart-list entry does not work.
If someone who is familiar with windows programming please let me know what am I doing wrong ?
Here you have the function for opening the offline chart using the chart list popup (without dependencies, I explain why later). The trick is to force the US keyboard (users have different layouts, different sorting) and fill in the input buffer with proper key strokes. Because the offline list opens with significant delay, you have to use a timer to release the US layout with some delay (900 ms in the code).
void openOffline745() { TRACEIN_; // message to open menu File -> Open Offline PostMessageW(GetAncestor((HWND)ChartGetInteger(0,CHART_WINDOW_HANDLE),2), WM_COMMAND, 33053, 0); // keep current locale HKL origH = GetKeyboardLayout(0); // set US English locale string uslayout = "00000409"; HKL h = LoadKeyboardLayoutW(uslayout, 0x00000001); // ctrl up keybd_event(0xA0, 0x2A, KEYEVENTF_KEYUP,0); // ‘left ctrl’ Release keybd_event(0xA1, 0x36, KEYEVENTF_KEYUP,0); // ‘righ ctrl’ Release // fill keyboard buffer with the offline list item, append TAB and RETURN to press the Open button sendStringToKeyboard(offscope.getSymbol().name() + "," + OfflineUtil::getTfString(offscope.getTimeframe()*60)+"\t"+"\r", h); class DelayedKeyboardSwitch: public MT4TimerSingleListener { // locale HKL handle; public: DelayedKeyboardSwitch(HKL aHandle) :MT4TimerSingleListener(NULL, 900), handle(aHandle) {} // timer event handler void run() { TRACEIN("ActivateKeyboardLayout"); ActivateKeyboardLayout(handle,0); TRACEOUT_; } }; // return recent locale after short delay manager.add(new DelayedKeyboardSwitch(origH)); TRACEOUT_; } /** For codes see http://www.codeproject.com/Articles/7305/Keyboard-Events-Simulation-using-keybd-event-funct */ void sendStringToKeyboard(string keyboardString, HKL h) { TRACEIN_; ushort charArray[]; StringToShortArray(keyboardString, charArray); for(int i = 0; i < ArraySize(charArray); i++) { switch (charArray[i]) { case 0: //if(charArray[i] == NULL) continue; continue; break; case '_': { keybd_event(0xA0,0x2A, 0 , 0); // shift down sendStringToKeyboard("-",h); keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release } break; case '#': { keybd_event(0xA0,0x2A, 0 , 0); // shift down sendStringToKeyboard("3",h); keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release } break; case '!': { keybd_event(0xA0,0x2A, 0 , 0); // shift down sendStringToKeyboard("1",h); keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release } break; case '%': { keybd_event(0xA0,0x2A, 0 , 0); // shift down sendStringToKeyboard("5",h); keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release } break; case '&': { keybd_event(0xA0,0x2A, 0 , 0); // shift down sendStringToKeyboard("7",h); keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release } break; case '$': { keybd_event(0xA0,0x2A, 0 , 0); // shift down sendStringToKeyboard("4",h); keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release } break; case '@': { keybd_event(0xA0,0x2A, 0 , 0); // shift down sendStringToKeyboard("2",h); keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release } break; case '^': { keybd_event(0xA0,0x2A, 0 , 0); // shift down sendStringToKeyboard("6",h); keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release } break; case '*': { keybd_event(0xA0,0x2A, 0 , 0); // shift down sendStringToKeyboard("8",h); keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release } break; case '(': { keybd_event(0xA0,0x2A, 0 , 0); // shift down sendStringToKeyboard("9",h); keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release } break; case ')': { keybd_event(0xA0,0x2A, 0 , 0); // shift down sendStringToKeyboard("0",h); keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release } break; case '?': { keybd_event(0xA0,0x2A, 0 , 0); // shift down sendStringToKeyboard("/",h); keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release } break; case '<': { keybd_event(0xA0,0x2A, 0 , 0); // shift down sendStringToKeyboard(",",h); keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release } break; case '>': { keybd_event(0xA0,0x2A, 0 , 0); // shift down sendStringToKeyboard(".",h); keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release } break; case '~': { keybd_event(0xA0,0x2A, 0 , 0); // shift down sendStringToKeyboard("`",h); keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release } break; case '+': { keybd_event(0xA0,0x2A, 0 , 0); // shift down sendStringToKeyboard("=",h); keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release } break; case ':': { keybd_event(0xA0,0x2A, 0 , 0); // shift down sendStringToKeyboard(";",h); keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release } break; case '"': { keybd_event(0xA0,0x2A, 0 , 0); // shift down sendStringToKeyboard("\'",h); keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release } break; case '|': { keybd_event(0xA0,0x2A, 0 , 0); // shift down sendStringToKeyboard("\\",h); keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release } break; case '}': { keybd_event(0xA0,0x2A, 0 , 0); // shift down sendStringToKeyboard("]",h); keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release } break; case '{': { keybd_event(0xA0,0x2A, 0 , 0); // shift down sendStringToKeyboard("[",h); keybd_event(0xA0,0x2A, KEYEVENTF_KEYUP,0); // shift release } break; default: { TRACE("VkKeyScanExW " + charArray[i]); uchar vkey = (uchar)VkKeyScanExW(charArray[i], h); TRACE("MapVirtualKeyW " + vkey); uchar skey = (uchar)MapVirtualKeyW(vkey, 0); TRACE("skey " + skey); MT4String d; d + "letter, char: "+ ShortToString(charArray[i])+ ", "+ charArray[i] //+ ", "+ vkey + ", "+ skey ; DEBUG(d.toString()); keybd_event(vkey,skey,0 , 0); // ‘A’ Press keybd_event(vkey,skey, KEYEVENTF_KEYUP,0); // ‘A’ Release } break; } } TRACEOUT_; }
Fortunately, the public builds following the build 745 have implemented ChartOpen(symbol, timeframe) command even for the offline charts, so if you are above the 745, you may ignore the inserted code.
Thank you very much for that information stranger.
I got misled by this information: https://forum.mql4.com/65762#1000456
BTW, how do you get such updated information where as all I get is this: https://docs.mql4.com/chart_operations/chartopen ?
BTW, how do we open time shifted offline charts using chartopen ? I am using a build above 75.
Time shifted charts of the format AUDCAD-75M480.hst
Thank you very much for that information stranger.
I got misled by this information: https://forum.mql4.com/65762#1000456
BTW, how do you get such updated information where as all I get is this: https://docs.mql4.com/chart_operations/chartopen ?
The information was correct at that time.
The change's been listed under the paragraph 17: https://forum.mql4.com/65974
BTW, how do we open time shifted offline charts using chartopen ? I am using a build above 75.
Time shifted charts of the format AUDCAD-75M480.hst
I did not test such artificial symbols (not listed in the symbol.sel), so it could be your turn. If you find out, I am eager to hear the statement.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I have the following program from the net modified to open an offline chart. But all it does it
open the offline chart-list. The key down and selecting the chart-list entry does not work.
If someone who is familiar with windows programming please let me know what am I doing wrong ?