Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

open a URL in a NEW browser window

Hello,
I want to open a URL from code, I found this

ShellExecute(Handle, "open", "http://www.something.com",NULL,NULL,SW_SHOWDEFAULT);

but when the browser is already running, this opens the URL in
an active browser window, I want it to open the URL in a NEW Browser
Window... how can I do that?
THNX

AlgoMan
____________________________

AlgorithMan
www.AlgorithMan.de

Comments

  • AlgorithManAlgorithMan Posts: 14Member
    Okay, after searching the web for hours I think,
    NOBODY knows an answer to this question, so I wrote
    my own code, here it is (only tested on WinXP using
    IE6)

    first a function, that finds the default app for any File extension:
    [code]
    #include
    AnsiString GetDefaultApp(AnsiString ext)
    {
    TRegistry* reg = new(TRegistry);
    reg->RootKey = HKEY_CURRENT_USER;
    if(!reg->OpenKeyReadOnly("Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\."+ext+"\OpenWithList"))
    return(NULL);
    try
    {
    AnsiString MRUList = reg->ReadString("MRUList");
    AnsiString ret = reg->ReadString(AnsiString(char(MRUList[1])));
    return(ret);
    }
    catch(...)
    {
    return(NULL);
    }
    }
    [/code]
    I also wrote a code that finds the whole OpenWithList (the first
    item in the List is the default app...)
    [code]
    #include
    TStringList* OpenWithList(AnsiString ext)
    {
    TRegistry* reg = new(TRegistry);
    TStringList* ret = new(TStringList);
    reg->RootKey = HKEY_CURRENT_USER;
    if(!reg->OpenKeyReadOnly("Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\."+ext+"\OpenWithList"))
    return(NULL);
    try{
    AnsiString MRUList = reg->ReadString("MRUList");
    for(int i = MRUList.Length(); i > 0; i--)
    ret->Insert(0,reg->ReadString(AnsiString(char(MRUList[i]))));
    return(ret);
    }
    catch(...)
    {
    return(NULL);
    }
    }
    [/code]
    now the code to launch the default app for html files and giving
    the URL as parameter:
    [code]
    #include
    void OpenURL(AnsiString URL)
    {
    AnsiString app = GetDefaultApp("html");
    if(app == NULL)
    return;
    ShellExecute(NULL,"open",app.c_str(),URL.c_str(),NULL,SW_SHOWDEFAULT);
    }
    [/code]
    Now you can open a URL in a new Browser using this command:
    [code]
    OpenURL("http://www.AlgorithMan.de/");
    [/code]
    CU

    AlgorithMan
  • AlgorithManAlgorithMan Posts: 14Member
    Okay, I've tested this code on
    -WinXP using IE6
    -WinME using IE5.5
    can somebody test the code with other browsers or
    on other Operating Systems? I think Win95 & Win98
    should not be able to do this, because if I remember
    correct, these Systems had no OpenWithList, only
    ONE OpenWith Prog...
    THNX & CU

    AlgoMan
Sign In or Register to comment.