open web-browser to review results

 

Hello,

Using EA, can i open an html file with a browser. If some some one know please let me know.



Thanks,

 

Sorry to request very old question.

I want a code that EA can open a default web browser with given URL.

Please help.

Thanks!

 
Untested
bool openURL(string url){
    int APPEND  = FILE_CSV|FILE_WRITE;
    string  file = WindowExpertName() + ".URL";
    int handle   = FileOpen(file, APPEND, '~');
    if (handleOPT < 1){ int GLE = GetLastError(); ... }
    FileWrite(handleOPT, "[InternetShortcut]");
    FileWrite(handleOPT, "URL="+url);
    FileClose(handleOPT);
    return ( Shell(TerminalPath()+"\\experts\\files\\"+file) );     // or "cmd.exe", "/C "+file
}
#import "shell32.dll"
   int ShellExecuteA(int hWnd, string Verb, string File, string Parameter, string Path, int ShowCmd);
#import
bool Shell(string file, string parameters=""){
    #define DEFDIRECTORY NULL
    #define OPERATION "open"    // or print
    #define SW_SHOWNORMAL 1
    int r=ShellExecuteA(0, OPERATION, file, parameters, DEFDIRECTORY, SW_SHOWNORMAL);
    if (r > 32) return(true);
    Alert("Shell failed: ",r);
    return(false);
}
Untested
 
  1. Since build 600 Feb 2014, all strings are Unicode. ShellExecuteA must be changed to ShellExecuteW. See also https://www.mql5.com/en/forum/155323
  2. open a url i n browser - MQL4 forum
 

In addition to change to ShellExecuteW as described above also change this line:

return ( Shell(TerminalPath()+"\\experts\\files\\"+file) );

to this line:

return ( Shell(TerminalInfoString(TERMINAL_DATA_PATH)+"\\MQL4\\Files\\"+file) ); 

Thanks, works perfectly!

 

What I desire is to have bindkey(s) open URL's.  This thread was a great help.  I did the various updates necessary for the latest MT4, and it almost works perfectly, with just one anomaly.

For this test, I have assigned the "Shift" key as my bindkey.  I run the script, and just before clicking on "Ok" to run the script, I hold down the Shift key.  If the code detects "Shift" is pressed, then it opens the URL as desired.  

However... if I hold the "Shift" key just a bit too long, then although the browser does open the URL, it ignores the "SW_SHOWNORMAL", and does not open on top of other windows.   I am forced to manually open the browser (Chrome in my case) to bring it on top.  It does have a tab opened to the requested URL, so it "worked", but less than ideally.


If I hold the "Shift" key when I "Ok" to run the script, but *immediately* release it, then indeed the browser opens the URL and displays on top of the other windows.    This is what I would prefer, regardless of how long I hold the "Shift" key, but holding it must be forcing the MT4 window to stay active, and it therefore ignores the SW_SHOWNORMAL for the browser.

I'll get used to releasing my bindkey(s) quickly, but if anyone has any suggestion, great.   FYI, I already know of one workaround, which would be to detect the "Shift" key, and set a boolean trigger var true that is then processed by an OnTimer() section.  In the OnTimer, when the trigger is set, AND when the "Shift" key is no longer held down, then actually do the "ShellExecuteW" to open the URL and clear the trigger var.  The drawback is this imposes a slight delay for the OnTimer to run (usually 1 second timer), but at least it will be nearly certain to always open the browser on top.  


//+------------------------------------------------------------------+
//|                                                test_open_url.mq4 |
//+------------------------------------------------------------------+

#property strict
#property script_show_inputs
//--- input parameters
input string   URL = "https://www.mql5.com/en/forum/110049";
input bool     Require_Shift_key_to_open_URL = true;
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
      if(Require_Shift_key_to_open_URL && !IsKeyShift() )return;
      openURL(URL);
      return;
  }

// Determine the Shift key status
bool IsKeyShift(void) export { return (::TerminalInfoInteger(TERMINAL_KEYSTATE_SHIFT) < 0); }
  
//+------------------------------------------------------------------+
bool openURL(string url){
    string  file = WindowExpertName() + ".URL";
    int handleOPT   = FileOpen(file,FILE_TXT|FILE_WRITE|FILE_SHARE_WRITE); //FileOpen(file, FILE_CSV|FILE_WRITE, '~');
    if (handleOPT < 1){ int GLE = GetLastError();} // ... }
    else
    {
       FileWrite(handleOPT, "[InternetShortcut]"+"\r\n");
       FileWrite(handleOPT, "URL="+url+"\r\n");
       FileClose(handleOPT);
       return ( Shell(TerminalInfoString(TERMINAL_DATA_PATH)+"\\MQL4\\Files\\"+file) );     // or "cmd.exe", "/C "+file
    }
    return(false);
}
#import "shell32.dll"
   int ShellExecuteW(int hwnd,string Operation,string File,string Parameters,string Directory,int ShowCmd);
#import

bool Shell(string file, string parameters=""){
    #define DEFDIRECTORY NULL
    #define OPERATION "open"    // or print
    #define SW_SHOWNORMAL 1
    int r=ShellExecuteW(0, OPERATION, file, parameters, DEFDIRECTORY, SW_SHOWNORMAL);
    if (r > 32) return(true);
    Alert("Shell failed: ",r);
    return(false);
}
Reason: