 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Daniel F Guest
|
Posted: Fri Apr 27, 2007 2:32 pm Post subject: calling default browser on windows |
|
|
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 |
|
| Back to top |
|
 |
Daniel F Guest
|
Posted: Fri Apr 27, 2007 2:45 pm Post subject: Re: calling default browser on windows |
|
|
"Daniel F" <nospam (AT) spamIsEvil (DOT) com> wrote:
| Quote: |
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); |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Fri Apr 27, 2007 9:23 pm Post subject: Re: calling default browser on windows |
|
|
"Daniel F" <nopam (AT) spamIsEvil (DOT) com> wrote in message
news:4631c649$1 (AT) newsgroups (DOT) borland.com...
| Quote: | 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 |
|
| Back to top |
|
 |
Colin B Maharaj Guest
|
Posted: Thu May 17, 2007 5:26 pm Post subject: Re: calling default browser on windows |
|
|
Daniel F wrote:
| Quote: | "Daniel F" <nospam (AT) spamIsEvil (DOT) 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;
}
//--------------------------------------------------------------------- |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|