/*******************************************************************
* 函数名称: GetRegKey
* 功 能: 获取注册表中的数据
*******************************************************************/
LONG GetRegKey(HKEY hKey, LPCTSTR szSub, LPTSTR szData)
{
HKEY hSubKey = NULL;
LONG lVal = RegOpenKeyEx(hKey, szSub, 0, KEY_QUERY_VALUE, &hSubKey);
if (lVal == ERROR_SUCCESS)
{
long lSize = MAX_PATH;
TCHAR data[MAX_PATH];
RegQueryValue(hSubKey, NULL, data, &lSize);
_tcscpy(szData, data);
RegCloseKey(hSubKey);
}
return lVal;
}
/*******************************************************************
* 函数名称: GotoURL
* 功 能: 打开URL页面
*******************************************************************/
HINSTANCE :GotoURL(LPCTSTR szURL)
{
TCHAR *verb = _T("open");
HINSTANCE result = ShellExecute(NULL, verb, szURL, NULL,NULL, SW_SHOWNORMAL);
if ((UINT)result <= HINSTANCE_ERROR)
{
TCHAR szKey[MAX_PATH*2] = {0};
if (GetRegKey(HKEY_CLASSES_ROOT, _T(".htm"), szKey) == ERROR_SUCCESS)
{
_tcscat(szKey, _T("\\shell\\open\\command"));
if (GetRegKey(HKEY_CLASSES_ROOT, szKey, szKey) == ERROR_SUCCESS)
{
TCHAR * pos = _tcsstr(szKey, _T("\"%1\""));
if (pos == NULL)
{
pos = _tcsstr(szKey, _T("%1"));
if (pos == NULL)
pos = verb + _tcslen(szKey)-1;
else
*pos = _T('\0');
}
else
{
*pos = _T('\0');
}
_tcscat(pos, _T(" "));
_tcscat(pos, szURL);
USES_CONVERSION;
result = (HINSTANCE) WinExec(T2A(szKey), SW_SHOW);
}
}
}
return result;
}