• VC 打开网页


    编译环境VC UNICODE

    在VC中采用ShellExecute打开网页总是那么不保险,经常会因为某些原因打不开网页,所以做过多种尝试,我认为这个方法比较可靠。

    链接地址:/Files/pbreak/OpenHtml.rar

    主要代码:

    ////////////////////////////////////////////////////////////////
    // 说明: 利用默认浏览器打开网页
    ////////////////////////////////////////////////////////////////
    void OpenHtml::GetUrl(CString sURL)
    {
       HKEY hkRoot,hSubKey; //定义注册表根关键字及子关键字 
       TCHAR ValueName[256]; 
       CString htmlValue = _T("htmlfile");
       unsigned char DataValue[256]; 
       unsigned long cbValueName=256; 
       unsigned long cbDataValue=256; 
       TCHAR ShellChar[256]; //定义命令行 
       DWORD dwType; 
     
       if(RegOpenKey(HKEY_CLASSES_ROOT,_T(".html"),&hkRoot) == ERROR_SUCCESS) 
       { 
          TCHAR lpWstr[MAX_PATH];
          DWORD lpType = REG_SZ;
          DWORD maxBufSize = MAX_PATH;
          if(RegQueryValueEx(hkRoot, NULL, NULL, &lpType, (LPBYTE)lpWstr, &maxBufSize) == ERROR_SUCCESS)
             htmlValue.Format(_T("%s"),lpWstr);
          RegCloseKey(hkRoot);
       }

       //打开注册表根关键字 
       if(RegOpenKey(HKEY_CLASSES_ROOT,NULL,&hkRoot) == ERROR_SUCCESS) 
       { 
          //打开子关键字 
          if(RegOpenKeyEx(hkRoot, 
                 htmlValue + _T("\\shell\\open\\command"), 
                 0, 
                 KEY_ALL_ACCESS, 
                 &hSubKey)==ERROR_SUCCESS) 
          { 
             //读取注册表,获取默认浏览器的命令行  
             RegEnumValue( hSubKey,  
                      0, 
                      ValueName, 
                      &cbValueName, 
                      NULL, 
                      &dwType, 
                      DataValue, 
                      &cbDataValue); 
             // 调用参数(主页地址)赋值 
             _tcscpy(ShellChar,(TCHAR *)DataValue); 
             CString str;
             str.Format(_T("%s"), ShellChar);
             int pos = str.ReverseFind('\"');
             str = str.Left(pos + 1);
             str += sURL;
                // 启动浏览器 
            USES_CONVERSION;
             WinExec(W2A(str),SW_SHOW); 
          } 
          else 
          {
             //关闭注册表 
             RegCloseKey(hSubKey); 
             RegCloseKey(hkRoot); 
          }
       }
    }

  • 相关阅读:
    HTML <input> 标签的 maxlength 属性
    HTTP 方法:GET 对比 POST
    怎么在html页面和js里判断是否是IE浏览器
    一行神奇的javascript代码
    c# 数据库批量插入数据SqlBulkCopy 示例
    c# 多线程调用窗体上的控件 示例
    sqlserver查找使用了某个字段的所有存储过程
    SQL Server 数据库性能优化
    SQL语句的执行过程
    Sql Server- 性能优化辅助指标SET STATISTICS TIME ON和SET STATISTICS IO ON
  • 原文地址:https://www.cnblogs.com/pbreak/p/1838075.html
Copyright © 2020-2023  润新知