zoukankan      html  css  js  c++  java
  • 没啥用,更换注册表信息使webbrower选择适合的版本

     /// <summary>    
            /// 修改注册表信息来兼容当前程序    
            ///     
            /// </summary>    
            static void SetWebBrowserFeatures(int ieVersion)
            {
                if (LicenseManager.UsageMode != LicenseUsageMode.Runtime)
                    return;
                //获取程序及名称    
                var appName = System.IO.Path.GetFileName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
                //得到浏览器的模式的值    
                UInt32 ieMode = GeoEmulationModee(ieVersion);
                var featureControlRegKey = @"HKEY_CURRENT_USERSoftwareMicrosoftInternet ExplorerMainFeatureControl";
                //设置浏览器对应用程序(appName)以什么模式(ieMode)运行    
                Registry.SetValue(featureControlRegKey + "FEATURE_BROWSER_EMULATION",
                    appName, ieMode, RegistryValueKind.DWord);
                //不晓得设置有什么用    
                Registry.SetValue(featureControlRegKey + "FEATURE_ENABLE_CLIPCHILDREN_OPTIMIZATION",
                    appName, 1, RegistryValueKind.DWord);
            }
            /// <summary>    
            /// 获取浏览器的版本    
            /// </summary>    
            /// <returns></returns>    
            static int GetBrowserVersion()
            {
                int browserVersion = 0;
                using (var ieKey = Registry.LocalMachine.OpenSubKey(@"SOFTWAREMicrosoftInternet Explorer",
                    RegistryKeyPermissionCheck.ReadSubTree,
                    System.Security.AccessControl.RegistryRights.QueryValues))
                {
                    var version = ieKey.GetValue("svcVersion");
                    if (null == version)
                    {
                        version = ieKey.GetValue("Version");
                        if (null == version)
                            throw new ApplicationException("Microsoft Internet Explorer is required!");
                    }
                    int.TryParse(version.ToString().Split('.')[0], out browserVersion);
                }
                //如果小于7    
                if (browserVersion < 7)
                {
                    throw new ApplicationException("不支持的浏览器版本!");
                }
                return browserVersion;
            }
            /// <summary>    
            /// 通过版本得到浏览器模式的值    
            /// </summary>    
            /// <param name="browserVersion"></param>    
            /// <returns></returns>    
            static UInt32 GeoEmulationModee(int browserVersion)
            {
                UInt32 mode = 11000; // Internet Explorer 11. Webpages containing standards-based !DOCTYPE directives are displayed in IE11 Standards mode.     
                switch (browserVersion)
                {
                    case 7:
                        mode = 7000; // Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode.     
                        break;
                    case 8:
                        mode = 8000; // Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode.     
                        break;
                    case 9:
                        mode = 9000; // Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode.                        
                        break;
                    case 10:
                        mode = 10000; // Internet Explorer 10.    
                        break;
                    case 11:
                        mode = 11000; // Internet Explorer 11    
                        break;
                }
                return mode;
            }

  • 相关阅读:
    LCD编程_显示文字
    LCD编程_画点线圆
    LCD编程_简单测试
    LCD编程框架组织
    LCD编程_LCD控制器
    编程——抽象出重要的结构体
    LCD裸板编程_框架
    S3C2440_LCD控制器
    关于加密与解密的问题。
    [13期]mysql-root全手工注入写马实例实战
  • 原文地址:https://www.cnblogs.com/zzfstudy/p/9992513.html
Copyright © 2011-2022 走看看