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

方法一

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

示例:

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

[(HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE)SoftwareMicrosoftInternet ExplorerMainFeatureControlFEATURE_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)IE8WebBrowser控件默认模式

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);

 

原文地址:https://www.cnblogs.com/guyun/p/4137398.html