admin 管理员组文章数量: 887021
//MFC
//用默认浏览器打开网页
//如果找不到默认浏览器,则默认用IE打开
void OpenURL(const CString & openUrl)
{
if(openUrl == "")
return;
HKEY hkRoot, hSubKey; //注册表根关键字及子关键字
CString ValueName;
unsigned char DataValue[MAX_PATH];
unsigned long cbValueNAME = MAX_PATH;
unsigned long cbDataNAME = MAX_PATH;
<pre name="code" class="cpp"><pre name="code" class="cpp"> CString ShellChar;//定义命令行
DWORD dwType;
//打开注册表根关键字
if(RegOpenKey(HKEY_CLASSES_ROOT,NULL,&hkRoot) == ERROR_SUCCESS)
{
//打开子关键字
if(RegOpenKeyEx(hkRoot,L"htmlfile\\Shell\\open\\command",
0, KEY_ALL_ACCESS, &hSubKey) == ERROR_SUCCESS)
{
. RegEnumValue(hSubKey, 0, (LPWSTR)ValueName.GetBuffer(MAX_PATH), &cbValueName, NULL,
&dwType, DataValue, &cbDataValue);
ValueName.ReleaseBuffer();
//调用参数赋值
ShellChar = (char *)DataValue;
if(ShellChar == "\"")
{
ShellExecute(NULL, L"open",(LPWSTR)openUrl.GetBuffer(MAX_PATH), NULL, NULL, SW_SHOWNORMAL);
openUrl.ReleaseBuffer();
}
else
{
ShellChar = ShellChar + openUrl;
WinExec((LPCSTR)ShellChar.GetBuffer(MAX_PATH),SW_SHOW);
ShellChar.ReleaseBuffer();
}
}
else
{
RegCloseKey(hSubKey);
RegCloseKey(hRoot); <pre name="code" class="cpp"><pre name="code" class="cpp"> ShellExecute(NULL, L"open",(LPWSTR)openUrl.GetBuffer(MAX_PATH), NULL, NULL, SW_SHOWNORMAL);
<pre name="code" class="cpp"><pre name="code" class="cpp"><pre name="code" class="cpp"> openUrl.ReleaseBuffer();
}
}
}
版权声明:本文标题:MFC 用默认浏览器打开网页 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/jishu/1726856314h1040397.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论