修改WebBrowser控件的内核解决方案

news/2024/5/15 2:56:19/文章来源:https://www.cnblogs.com/tang-delphi/p/16709711.html

首先说一下原理

当下很大浏览器他们都是用了IE的core, 这个core只提供HTML/JS的执行和渲染,并没有给出关于界面和一些特性上的事,所以开发自己浏览器如果基于IE core需要自己完成这些内容。 一张图很好的说明了这个情况,IE浏览器的架构:http://msdn.microsoft.com/en-us/library/aa741312(VS.85).aspx

ShDocVw 及以下就是WebBrowser的内容,而Browser UI和IE自己的一些特有的功能不属于WebBrowser所有。 当然,不是说要做自己的基于IE的浏览器就非得用WebBrowser, 我们完全可以直接使用 MSHTML 去控制和绘制DOM,跳过WebBrowser。

那么可不可以修改它绑定的内核呢?

这是可以的:

 

IE8 在渲染引擎做了很大的改动,新增加一个标准模式 (Standard Mode)。 不少软件都内嵌了IE的WebBrowser控件(也就是MSHTML.dll)来显示网页, 当用户机器升级到IE8, WebBrowser控件也会随之升级到IE8的渲染引擎。

为了保证这些使用WebBrowser控件的应用软件能够工作起来和原来一样,IE8的WebBrowser控件在默认情况下使用了IE7 的渲染模式(也就是IE8中的Compatible View (兼容视图)模式)。

方法一

加入你想让WebBrowser控件的渲染模式编程IE8的标准模式, 你可以通过设置注册表FEATURE_BROWSER_EMULATION 来实现。

示例:

注册表中注明当前本机装的IE版本
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer
下面有名称为Version的项,其值为IE的版本.
svcVersion =10.0.9200.16618
Version =9.10.9200.16618

[(HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE)\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION] 
"MyApplication.exe" = dword 8000 (Hex: 0x1F40)

这里MyApplicaiton.exe 是你的应用程序的EXE文件名。 8000 表示8.0的渲染模式,请对照下表:

IE8 Standards Mode   8000 (0x1F40)  -- IE8 标准模式 (Standard Mode), IE8默认的模式

IE7 Standards Mode   7000 (0x1B58)  -- IE7 兼容视图模式 (Compatible View), IE8的WebBrowser控件默认模式

IE8 Standards Mode (Forced)  8888 (0x22B8) -- IE8 强制标准模式,在渲染失败的情况下不尝试用兼容视图模式

 方法二

 

在html头 加标签 强制使用最新的ie渲染 <meta http-equiv="X-UA-Compatible" content="IE=edge">
强制使用最新的ie8渲染<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8"/>

 

修改案例:

void WINAPI WriteWebBrowserRegKey(LPCTSTR lpKey,DWORD dwValue)
{
    HKEY hk;
    CString str = "Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\";
    str += lpKey;
    if (RegCreateKey(HKEY_LOCAL_MACHINE,str,&hk)!=0)
    {
        MessageBox(NULL,"打开注册表失败!","Error",0);
        ExitProcess(-1);
    }
    if (RegSetValueEx(hk,"你的exe名称.exe",NULL,REG_DWORD,(const byte*)&dwValue,4)!=0)
    {
        RegCloseKey(hk);
        MessageBox(NULL,"写注册表失败!","Error",0);
        ExitProcess(-1);
    }
    RegCloseKey(hk);
}

 

WriteWebBrowserRegKey("FEATURE_BROWSER_EMULATION",9000);
    //    WriteWebBrowserRegKey("FEATURE_ACTIVEX_REPURPOSEDETECTION",1);
        WriteWebBrowserRegKey("FEATURE_BLOCK_LMZ_IMG",1);
        WriteWebBrowserRegKey("FEATURE_BLOCK_LMZ_OBJECT",1);
        WriteWebBrowserRegKey("FEATURE_BLOCK_LMZ_SCRIPT",1);
        WriteWebBrowserRegKey("FEATURE_Cross_Domain_Redirect_Mitigation",1);
        WriteWebBrowserRegKey("FEATURE_ENABLE_SCRIPT_PASTE_URLACTION_IF_PROMPT",1);
        WriteWebBrowserRegKey("FEATURE_LOCALMACHINE_LOCKDOWN",1);
        WriteWebBrowserRegKey("FEATURE_GPU_RENDERING",1);

 

 

参考资料

现在就去仔细查一下权威资料,核实一下两个问题: 
1.Webbrowser与IE到底是什么关系?是否确实用ie内核, 是否本质上和360安全浏览器,傲游浏览器和腾讯TT等IE内核浏览器相同。 
2.Webbrowser是否使用兼容浏览模式,以及这个模式是否能改?

二.查询结果

1.webbrowser调用的就是本机IE9,并且webbrowser默认就是运行在IE7 mode下,除非你改变它.

发现一个msdn的帖子,明确表示webbrowser调用的就是本机IE9,并且webbrowser默认就是运行在IE7 mode下,除非你改变它。 
How to make c# WebBrowser equivalent to IE browser  
http://social.msdn.microsoft.com/Forums/en/winforms/thread/2ed65b9d-c601-4ca8-bde1-64584fc87515

摘几句: 
Wow first post with such bold claim without any source backing up. You probably should read the IE SDK (the manual you need to read if you want to use the webbrowser control) or dig through the IE programming forums (that's the place others often go when they are stuck on IE programming) if you want to use the webbrowser control.

Webbrowser is a wrapper around IE APIs. There is no such thing as multiple versions of IE coexisting on the same computer. You will always get the one and only version of IE installed on the computer from webbrowser control.

There are many, many documented setting differences between default IE and webbrowser. Basically you don't have to opt out new features in webbrowser that may break your app (the Visual Studio team learned a hard lesson here, when IE8 breaks Visual Studio's wizards) , you have to write code to opt in, unless the improvement is security related. That means the webbrowser will run in IE7 mode unless you change the mode in feature control.

Note some web site declare their requirement of IE7 or IE8 mode. It may not be wise to force the IE9 mode. 

2.微软新闻组的一个帖子,Webbrowser Control without IE,里面明确提到,不装IE,无法用webbrowser. 
http://groups.google.com/group/microsoft.public.vb.controls/browse_thread/thread/7575bd25e0730ded/aa40f3dfc799407d?lnk=gst&q=WebBrowser+ie#aa40f3dfc799407d

IE must be installed on the machine for you to use Webbrowser Control.

Internet Explorer MUST be installed to use the WebBrowser control.  There are simply no ifs, ands, or buts about it.  How can you expect to use IE functionality if IE is not installed?

3.如何设置WebBrowser在IE9 mode下工作呢? 
答曰:需要修改注册表,具体看下面4,5,6,尤其6最全面,可以光看6。

4.WPF webbrowser control using IE7 instead of IE9 
http://social.msdn.microsoft.com/Forums/en-US/iewebdevelopment/thread/4431908e-1869-4435-bcea-a3ec0820edfb

摘抄几句: 
How do I make it so the WPF WebBrowser control will use IE9 as the browser engine instead of IE7? 
I have some HTML that is rendering differently in the WebBrowser control than in the IE9 browser. When I run the following javascript in the WebBrowser, the result is "7". as in IE7.

I found an article by Rick Strahl that describes registry settings that will get the WebBrowser to use IE9. But I would like to avoid that. And I am interested to know how IE7 comes about being used.http://www.west-wind.com/weblog/posts/2011/May/21/Web-Browser-Control-Specifying-the-IE-Version 
回答:You want to avoid the only documented way to set document compatibility mode for webbrowser hosts? Why?

5.WebBrowser and CSS3 ? 
http://social.msdn.microsoft.com/Forums/en-AU/winforms/thread/1b656af7-bda9-47d9-8f9a-1d886d3688ca 
Web browser control by default runs in compatibility mode unless you set the feature browser emulation registry key. The fact that IE9 is able to render CSS3 correctly and browser control is not seems to suggest browser control is not running in IE9 standards mode.

You'll need to set Browser emulation feature key (FEATURE_BROWSER_EMULATION) described at this link http://msdn.microsoft.com/en-us/library/ee330730%28v=vs.85%29.aspx

You can use 9000 value, unless you want to force IE 9 standards mode for all pages. In case of later, you need to use 9999.

hklm

If hklm and 64bit machine used, you need to check is Wow6432Node needs to be changed.

And finally you need to add process name hosting browser control as value name in the registry key.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION] 
"prevhost.exe"=dword:00001f40 
"sllauncher.exe"=dword:00001f40 
"WindowsFormsApplication1.exe"=dword:0000270f

6.Web Browser Control – Specifying the IE Version 
http://www.west-wind.com/weblog/posts/2011/May/21/Web-Browser-Control-Specifying-the-IE-Version

I use the Internet Explorer Web Browser Control in a lot of my applications to display document type layout. HTML happens to be one of the most common document formats and displaying data in this format – even in desktop applications, is often way easier than using normal desktop technologies.

One issue the Web Browser Control has that it’s perpetually stuck in IE 7 rendering mode by default. Even though IE 8 and now 9 have significantly upgraded the IE rendering engine to be more CSS and HTML compliant by default the Web Browser control will have none of it. IE 9 in particular – with its much improved CSS support and basic HTML 5 support is a big improvement and even though the IE control uses some of IE’s internal rendering technology it’s still stuck in the old IE 7 rendering by default.

This applies whether you’re using the Web Browser control in a WPF application, a WinForms app, a FoxPro or VB classic application using the ActiveX control. Behind the scenes all these UI platforms use the COM interfaces and so you’re stuck by those same rules.

Feature Delegation via Registry Hacks 
Fortunately starting with Internet Explore 8 and later there’s a fix for this problem via a registry setting. You can specify a registry key to specify which rendering mode and version of IE should be used by that application. These are not global mind you – they have to be enabled for each application individually.

There are two different sets of keys for 32 bit and 64 bit applications.

32 bit:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION

Value Key: yourapplication.exe

64 bit:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION

Value Key: yourapplication.exe

The value to set this key to is (taken from MSDN here) as decimal values:

9999 (0x270F) 
Internet Explorer 9. Webpages are displayed in IE9 Standards mode, regardless of the !DOCTYPE directive.

9000 (0x2328) 
Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode.

8888 (0x22B8) 
Webpages are displayed in IE8 Standards mode, regardless of the !DOCTYPE directive.

8000 (0x1F40) 
Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode.

7000 (0x1B58) 
Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_10440.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

nginx - 负载均衡配置-负载均衡策略

目录 知识点1&#xff1a;网站流量分析指标 什么是pv&#xff1f; 什么是uv&#xff1f; 什么是IP&#xff1f; 知识点2&#xff1a;正向代理和反向代理 知识点3&#xff1a;负载均衡实验 IP地址规划&#xff1a; 实验拓扑图 知识点4&#xff1a;负载均衡策略 1、请求…

Spring5.3学习——from 官网 day1-1

Spring5.3学习——from 官网day1-1Spring5.3学习——from 官网day1-1前言概述Spring的设计理念Spring核心&#xff1a;IOC什么是IOC解释IOC容器的包什么是BeanBeanFactory接口简述ApplicationContext接口简述BeanFactory源码描述以下是Bean工厂创建和销毁bean的完整生命周期流程…

Matlab论文插图绘制模板第48期—平行坐标图(Parallelplot)

​上一期文章中&#xff0c;分享了Matlab帕累托图的绘制模板&#xff1a; 这一次&#xff0c;再来分享一种特殊的线图&#xff1a;平行坐标图。 ‘平行坐标图是一种通常的可视化方法&#xff0c;用于对高维几何和多元数据的可视化……为了克服传统的笛卡尔直角坐标系容易耗尽空…

好心情精神心理科:80%双相情感障碍被误诊,千万注意鉴别

双相情感障碍又称躁郁症&#xff0c;其表现复杂&#xff0c;容易与其他精神疾病&#xff08;包括边缘型人格障碍&#xff09;相混淆&#xff0c;超过80%的患者未能得到正确诊断。 具体如何区分双相情感障碍与边缘型人格障碍&#xff1f;在回答这个问题之前&#xff0c;好心情精…

从规模走向规模经济,锅圈食汇回归餐饮初心

预制菜源自美国&#xff0c;在日本因冷链技术发展而普及。后疫情时代&#xff0c;预制菜在中国餐饮市场加速渗透&#xff0c;成为行业的新风向。 9月&#xff0c;第一财经与CBNData发布“Growth502022中国新消费品牌年度增长力榜单”&#xff0c;预制菜品牌锅圈食汇入选。 锅…

设计模式学习笔记--责任链模式

责任链模式 责任链模式是一种对象的行为模式。在责任链模式里&#xff0c;很多对象由每一个对象对其下家的引用而连接起来形成一条链。请求在这个链上传递&#xff0c;直到链上的某一个对象决定处理此请求。发出这个请求的客户端并不知道链上的哪一个对象最终处理这个请求&…

Tuxera NTFS21Mac苹果电脑读取硬盘磁盘软件

我们经常会使用移动硬盘或 U 盘进行大体积文件的分享、携带。但有时候别人提供的NTFS移动硬盘或者U 盘在 Mac 电脑中只能读取&#xff0c;无法将文件导入到其中。这是因为常见的 NTFS 硬盘格式在 Mac 中不能兼容。 当你从 Windows 转到了 Mac 平台&#xff0c;可能会发现之前用…

RocketMQ-流程图-概念

文章目录RocketMq的角色消息发送的流程RocketMq的角色 Producer&#xff1a;消息的发送者&#xff0c;生产者&#xff1b;举例&#xff1a;发件人Consumer&#xff1a;消息接收者&#xff0c;消费者&#xff1b;举例&#xff1a;收件人Broker&#xff1a;暂存和传输消息的通道…

Python数据分析教程(一):Numpy

数据的纬度 一维数据:列表和集合类型二维数据:列表类型多维数据:列表类型高维数据:字典类型或数据表示格式,如json、xml、yaml维度:一组数据的组织形式列表和数组:一组数据的有序结构Numpy Numpy介绍NumPy是一个开源的Python科学计算基础库,包含:一个强大的N维数组对象…

渗透测试神器Nmap使用教程

渗透测试神器Nmap使用教程1.nmap简介2.常用参数3.nmap实战命令1.nmap简介 Nmap &#xff08;网络映射器&#xff09;是Gordon Lyon最初编写的一种安全扫描器&#xff0c;用于发现计算机网络上的主机和服务&#xff0c;从而创建网络的“映射”。为了实现其目标&#xff0c;Nmap…

java计算机毕业设计基于安卓Android的金融保险app(源码+系统+mysql数据库+Lw文档)

项目介绍 计算机信息技术的发展&#xff0c;推动了金融保险信息化管理的进程&#xff0c;并随着互联网概念的提出&#xff0c;各种互联网软件也应运而生。在传统的管理中&#xff0c;各种信息管理难&#xff0c;传播速度慢&#xff0c;需要耗费很长时间统计核查&#xff0c;不…

Oracel中视图相关概念和操作(一)

目录 1.视图概念&#xff08;有必要&#xff09; &#xff08;1&#xff09;视图基本概念 &#xff08;2&#xff09;视图和定义的表的联系 &#xff08;3&#xff09;视图的优点 2.创建视图 &#xff08;1&#xff09;使用SQL DEVELOPER创建视图&#xff08;可视化&#x…

如何正确的审核交易商牌照?这些雷区你不得不防

对于外汇平台来说&#xff0c;交易牌照可以说是重中之重&#xff0c;一个交易没有牌照&#xff0c;可以说是没有任何约束&#xff0c;属于监管裸奔状态&#xff0c;这种平台10个有10个就是黑平台。但也正因如此&#xff0c;无数黑平台也会在牌照上面做手脚&#xff0c;这些人手…

基于stm32单片机甲醛烟雾温湿度检测仪设计

目录 第1章 绪论 1.1 引言 1.1.1甲醛的特性及危害 1.1.2甲醛的来源 1.2甲醛检测仪的种类 第&#xff12;章 概述 2.1系统总概述 2.2总体方案设计 2.3硬件设计 2.4软件设计 第3章 硬件设计 3.1 硬件设计主电路图 3.2 硬件选择 3.2.1 MCU的选择与简介 3.2.3 …

Gimbal Lock欧拉角死锁问题

技术背景 在前面几篇跟SETTLE约束算法相关的文章(1, 2, 3)中&#xff0c;都涉及到了大量的向量旋转的问题--通过一个旋转矩阵&#xff0c;给定三个空间上的欧拉角\(\alpha, \beta, \gamma\)&#xff0c;将指定的向量绕对应轴进行旋转操作。而本文主要就阐述这些旋转操作中&…

复习十二:广义表

一、广义表的定义及其重要特性 广义表简称表&#xff0c;它是线性表的推广。一个广义表是n(n>0)个元素的一个序列&#xff0c;若n0时&#xff0c;则称为空表&#xff1b; 广义表中有两种数据元素&#xff0c;即有两种结构的结点&#xff1a;表结点和原子结点&#xff1b;广义…

大数据ClickHouse进阶(十一):ClickHouse的Join子句

文章目录 ClickHouse的Join子句 一、连接精度

Springcloud的学习笔记(二)

Springcloud学习笔记(一) 目录8 消费者订单模块9 重构10 Eureka服务注册与发现10.1 Eureka基础知识10.2 EurekaServer服务端安装10.3 支付微服务8001入驻进EurekaServer10.4 订单微服务81入驻进EurekaServer10.5 Eureka集群原理说明10.6 Eureka集群环境构建10.7 订单支付两微服…

ASR6500S SIP模块与SX1262系列集成替代SX1278 SX1262内核+RF前端

ASR6500S是一系列LoRa SIP模块,集成了RF前端和LoRa无线电收发器SX1262系列,支持LoRa 和FSK调制。LoRa技术是一种针对LPWAN应用的低数据速率、超远程、超低功耗通信进行优化的 广谱协议。 ASR6500S设计为电池寿命长,有功接收电流消耗4.2 mA,最大发射功率可达+22dBm。该模块实…

Shell之练习题

目录 一、练习一 1.1、分析 1.2、编辑脚本文件 1.3、测试 二、练习二 2.1、分析 2.2、编辑脚本文件 ​2.3、测试 三、练习三 3.1、分析 3.2、编辑脚本文件 ​3.3、测试 四、练习四 4.1、分析 4.2、编辑脚本文件 4.3、测试​ 一、练习一 需求&#xff1a;给定一…