55 lines
1.4 KiB
C++
55 lines
1.4 KiB
C++
#include "../../stdafx.h"
|
|||
|
|
#include "GotoURL.h"
|
||
|
|
|
||
|
|
static LONG GetRegKey(HKEY key, const char *subkey, LPTSTR retdata)
|
||
|
|
{
|
||
|
|
HKEY hkey;
|
||
|
|
LONG retval = RegOpenKeyEx(key, subkey, 0, KEY_QUERY_VALUE, &hkey);
|
||
|
|
|
||
|
|
if (retval == ERROR_SUCCESS) {
|
||
|
|
long datasize = MAX_PATH;
|
||
|
|
TCHAR data[MAX_PATH];
|
||
|
|
RegQueryValue(hkey, NULL, data, &datasize);
|
||
|
|
lstrcpy(retdata,data);
|
||
|
|
RegCloseKey(hkey);
|
||
|
|
}
|
||
|
|
|
||
|
|
return retval;
|
||
|
|
}
|
||
|
|
|
||
|
|
HINSTANCE GotoURL(const char *url)
|
||
|
|
{
|
||
|
|
TCHAR key[MAX_PATH + MAX_PATH];
|
||
|
|
|
||
|
|
// First try ShellExecute()
|
||
|
|
HINSTANCE result = ShellExecute(NULL, _T("open"), url, NULL,NULL, SW_SHOWDEFAULT);
|
||
|
|
|
||
|
|
// If it failed, get the .htm regkey and lookup the program
|
||
|
|
if ((UINT)result <= HINSTANCE_ERROR) {
|
||
|
|
|
||
|
|
if (GetRegKey(HKEY_CLASSES_ROOT, _T(".htm"), key) == ERROR_SUCCESS) {
|
||
|
|
lstrcat(key, _T("\\shell\\open\\command"));
|
||
|
|
|
||
|
|
if (GetRegKey(HKEY_CLASSES_ROOT,key,key) == ERROR_SUCCESS) {
|
||
|
|
TCHAR *pos;
|
||
|
|
pos = _tcsstr(key, _T("\"%1\""));
|
||
|
|
if (pos == NULL) { // No quotes found
|
||
|
|
pos = strstr(key, _T("%1")); // Check for %1, without quotes
|
||
|
|
if (pos == NULL) // No parameter at all...
|
||
|
|
pos = key+lstrlen(key)-1;
|
||
|
|
else
|
||
|
|
*pos = '\0'; // Remove the parameter
|
||
|
|
}
|
||
|
|
else
|
||
|
|
*pos = '\0'; // Remove the parameter
|
||
|
|
|
||
|
|
lstrcat(pos, _T(" "));
|
||
|
|
lstrcat(pos, url);
|
||
|
|
result = (HINSTANCE) WinExec(key,SW_SHOWDEFAULT);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return result;
|
||
|
|
}
|