Cause
11-17-2006, 02:30 PM
Could someone supply a function to call the regkey and find the default brower stored there?
I've got a call to the users IE working, but want to make sure my scheme will work no matter what browser the user is using!
Thank You,
Cause :)
You can just call:
rundll32.exe SHELL32.DLL,ShellExec_RunDLL <url>
You can also call local files like that. The effect is the same as double clicking em. So, with an mp3 it could for example spawn winamp or foobar.
frozax
11-18-2006, 02:02 AM
I'm using ShellExecute:
ShellExecute( NULL, "open", url, 0, 0, SW_SHOWNORMAL );
Cause
11-18-2006, 12:28 PM
Thank you to both of you,
Cause.
To answer the original question:
class WebBrowser
{
public:
WebBrowser() { FindDefaultBrowser(); FindOpenCommand(); }
virtual ~WebBrowser();
virtual void OpenURL(const char* url);
protected:
void FindDefaultBrowser();
void FindOpenCommand();
string browser;
string command;
};
void
WebBrowser::FindDefaultBrowser()
{
HKEY hkey;
char value[256] = "";
DWORD dwSize;
ZeroMemory(value, 256);
if (RegOpenKeyEx(HKEY_CLASSES_ROOT,
".html",
0,
KEY_READ,
&hkey) == ERROR_SUCCESS) {
dwSize = 256;
RegQueryValueEx(hkey,
"",
NULL,
NULL,
(LPBYTE) value,
&dwSize);
RegCloseKey(hkey);
if (dwSize > 0) {
::Print("Default Web Browser: %s\n", value);
browser = value;
}
}
}
void
WebBrowser::FindOpenCommand()
{
HKEY hkey;
char value[256] = "";
DWORD dwSize;
ZeroMemory(value, 256);
if (RegOpenKeyEx(HKEY_CLASSES_ROOT,
browser + "\\shell\\open\\command",
0,
KEY_READ,
&hkey) == ERROR_SUCCESS) {
dwSize = 256;
RegQueryValueEx(hkey,
"",
NULL,
NULL,
(LPBYTE) value,
&dwSize);
RegCloseKey(hkey);
if (dwSize > 0) {
::Print("Browser Shell Open Command: %s\n", value);
command = value;
}
}
}
void
WebBrowser::OpenURL(const char* url)
{
if (url) {
char cmdline[256];
if (command.contains("%1")) {
strcpy(cmdline, command.replace("%1", url).data());
}
else {
strcpy(cmdline, string(command + " " + url).data());
}
STARTUPINFO s;
ZeroMemory(&s, sizeof(s));
s.cb = sizeof(s);
PROCESS_INFORMATION pi;
ZeroMemory(&pi, sizeof(pi));
if (CreateProcess(NULL, cmdline, 0, 0, 0, 0, 0, 0, &s, &pi)) {
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
else {
::Print("Unable to launch web browser for url '%s'\n", url);
}
}
}
--milo
vBulletin v3.6.0, Copyright ©2000-2008, Jelsoft Enterprises Ltd.