🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.web
4 messages
4 total messages Started by Daniel F Fri, 27 Apr 2007 09:32
calling default browser on windows
#86
Author: Daniel F
Date: Fri, 27 Apr 2007 09:32
16 lines
1239 bytes
Hi all,
i need to call the default browser on windows and open a 
web page.
i need to create an exe without any library file dependent 
other from the ones existing on windows xp.

Example on windows if we go start>run then 
type http://www.newsgroups.borland.com.

I tried looking for was to call "run" on MS SDK Help Files,
but no luck..

can anyone help?!

thx in advanced
Re: calling default browser on windows
#87
Author: Daniel F
Date: Fri, 27 Apr 2007 09:45
23 lines
1396 bytes
"Daniel F" <nospam@spamIsEvil.com> wrote:
>
>Hi all,
>i need to call the default browser on windows and open a 
>web page.
>i need to create an exe without any library file dependent 
>other from the ones existing on windows xp.
>
>Example on windows if we go start>run then 
>type http://www.newsgroups.borland.com.
>
>I tried looking for was to call "run" on MS SDK Help Files,
>but no luck..
>
>can anyone help?!
>
>thx in advanced

Should have searched the newsgroups before posted hehe.. sry

   char *msg = " start http://www.cnn.com";
   system(msg);
Re: calling default browser on windows
#89
Author: Remy Lebeau (TeamB)
Date: Fri, 27 Apr 2007 16:23
16 lines
1244 bytes
"Daniel F" <nopam@spamIsEvil.com> wrote in message
news:4631c649$1@newsgroups.borland.com...

> Should have searched the newsgroups before posted hehe.. sry
>
>    char *msg = " start http://www.cnn.com";
>    system(msg);

Use the Win32 API ShellExecute() function instead:

    ShellExecute(NULL, "open", "http://www.cnn.com", NULL, NULL,
SW_SHOWNORMAL);


Gambit
Re: calling default browser on windows
#94
Author: Colin B Maharaj
Date: Thu, 17 May 2007 12:26
152 lines
5736 bytes
Daniel F wrote:
> "Daniel F" <nospam@spamIsEvil.com> wrote:
>> Hi all,
>> i need to call the default browser on windows and open a 
>> web page.
>
Because we live in a democracy, another thing you can do with two 
browsers is find a way to launch either.  Place two Speed buttons on a 
form and prototype these two functions (source way below).

bool HKCRRegKeyExists(char *reg, AnsiString & DefaultValue);
bool HKLM_CurrentVersion(char *reg, char *key, AnsiString & Value);


//---------------------------------------------------------------------
// Setup the buttons if firefox or IE exists and show them.
//---------------------------------------------------------------------
void __fastcall TForm1::FormShow(TObject *Sender)
{
    AnsiString VER;
    SpeedButton1->Visible =
    HKLM_CurrentVersion("SOFTWARE\\Mozilla\\Mozilla Firefox", 
"CurrentVersion", VER);
    SpeedButton1->Hint = (AnsiString) "Launch firefox : v" + VER;

    SpeedButton2->Visible =
    HKLM_CurrentVersion("SOFTWARE\\Microsoft\\Internet Explorer", 
"Version", VER);
    SpeedButton2->Hint = (AnsiString) "Launch IE : v" + VER;

}

//---------------------------------------------------------------------------
// Firefox launch.
//---------------------------------------------------------------------------
void __fastcall TForm1::SpeedButton1Click(TObject *Sender)
{
   AnsiString A, C;
   A = "SOFTWARE\\Mozilla\\Mozilla Firefox";
   if (HKLM_CurrentVersion(A.c_str(), "CurrentVersion", C)==true)
   {
     A = A + "\\" + C + "\\Main";
     if (HKLM_CurrentVersion(A.c_str(), "PathToExe", C)==true)
     {
       AnsiString B = "http://www.google.com";
       ShellExecute(this->Handle, "open", C.c_str(), B.c_str(),
       NULL, SW_SHOWNORMAL);
     }
   }
}

//---------------------------------------------------------------------------
// IE Launch.
//---------------------------------------------------------------------------
void __fastcall TForm1::SpeedButton2Click(TObject *Sender)
{
  AnsiString A;
  if 
(HKCRRegKeyExists("Applications\\iexplore.exe\\shell\\open\\command", 
A)==true)
  {
    int p = A.Pos("%1");
    if (p)
    {
      A.SetLength(p-1);
      A = Trim(A);
    }
    AnsiString B = "http://www.google.com";
    B =  (AnsiString) "\"" + B + "\"";
    ShellExecute(this->Handle, "open", A.c_str(), B.c_str(),
    NULL, SW_SHOWNORMAL);
  }
}



//---------------------------------------------------------------------
// This code was meant to query the versions of the browsers.
// This is placed in Value. Returns false if not found.
//---------------------------------------------------------------------

bool HKLM_CurrentVersion(char *reg, char *key, AnsiString & Value)
{
    HKEY hKey;
    DWORD keyType;
    DWORD retValue;
    DWORD keyLength;
    retValue = RegOpenKeyEx(HKEY_LOCAL_MACHINE, reg, NULL, KEY_READ, &hKey);
    if (retValue != ERROR_SUCCESS)
    {
      return false;
    }

    char *t = new char [MAX_PATH];
               RegQueryValueEx(hKey, key, NULL, &keyType, NULL, 
&keyLength);
    retValue = RegQueryValueEx(hKey, key, NULL, &keyType, (UCHAR *)t, 
&keyLength);
    RegCloseKey(hKey);

    if (retValue != ERROR_SUCCESS)
    {
       delete t;
       return false;
    }
    if (keyLength < MAX_PATH) t[keyLength]    = '\0';
    else                      t[MAX_PATH - 1] = '\0';
    Value = t;
    delete t;
    return true;
}

//---------------------------------------------------------------------
// This code was used to get the path of the EXEs.
// Who knows it might break in later versions of the
// respective browsers. Returns false if not found.
//---------------------------------------------------------------------

bool HKCRRegKeyExists(char *reg, AnsiString & DefaultValue)
{
    HKEY hKey;
    DWORD keyType;
    DWORD retValue;
    DWORD keyLength;
    retValue = RegOpenKeyEx(HKEY_CLASSES_ROOT, reg, NULL, 
KEY_QUERY_VALUE, &hKey);
    if (retValue != ERROR_SUCCESS)
    {
      return false;
    }

    char *t = new char [MAX_PATH];

    RegQueryValueEx(hKey, NULL, NULL, &keyType, NULL, &keyLength);
    retValue = RegQueryValueEx(hKey, NULL, NULL, &keyType, (UCHAR *)t, 
&keyLength);

    RegCloseKey(hKey);

    if (retValue != ERROR_SUCCESS)
    {
       delete t;
       return false;
    }
    if (keyLength < MAX_PATH) t[keyLength]    = '\0';
    else                      t[MAX_PATH - 1] = '\0';
    DefaultValue = t;
    delete t;
    return true;
}

//---------------------------------------------------------------------
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads