给你一个函数
你可以这样调用 GotoURL("http://www.ccba.org.cn",SW_SHOW);HINSTANCE GotoURL(LPCTSTR url, int showcmd)
{
TCHAR key[MAX_PATH + MAX_PATH];
// First try ShellExecute()
HINSTANCE result = ShellExecute(NULL, _T("open"), url, NULL,NULL, showcmd); // 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,showcmd);
}
}
}
return result;
}
你可以这样调用 GotoURL("http://www.ccba.org.cn",SW_SHOW);HINSTANCE GotoURL(LPCTSTR url, int showcmd)
{
TCHAR key[MAX_PATH + MAX_PATH];
// First try ShellExecute()
HINSTANCE result = ShellExecute(NULL, _T("open"), url, NULL,NULL, showcmd); // 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,showcmd);
}
}
}
return result;
}
解决方案 »
- 请问如何将JPG文件转换为BMP文件?
- 150分这是第三贴了,如何在win2000+vc6中使用GDI+?请进!!!!帮忙!!!!!!!
- 一个对话框程序,为何当某一button处于焦点时,敲回车不执行按钮功能?
- 小弟有一个川串问题不解,请大虾帮忙
- 重複定義的問題!!應該不是這樣的!!
- 我想知道CTRL+ALT+key是如何呼叫出一个最小化的程序的?要代码示例
- 请问如何响应系统的退出按钮消息?
- 请问如何获得Edit中的字符串?
- VC/Fortran高手请看过来,有高分奉送
- 请教COM,DCOM,DLL的区别
- 高手在哪里?如何加壳呢?
- 与控制台程序放在同一个目录下,也无法脱离vc环境使用LoadLibrary找到dll?
ShellExecute(NULL, "explore", "http://www.sohu.com", NULL, NULL, SW_SHOWNORMAL);