delphi强制WebBrowser控件使用指定版本显示网页

时间:2022-01-15 02:53:16

function TFrmmain.WriteAppNameToReg:Boolean; var reg:TRegistry; sPath,sAppName:String; Sver:string; lenver:Integer; begin Result:=True; reg:=TRegistry.Create; try reg.RootKey:=HKEY_LOCAL_MACHINE; sPath:=‘SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION‘; if isWin64 then sPath:=‘SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION‘; if reg.OpenKey(sPath,True) then begin sAppName:=ExtractFileName(Application.ExeName); Sver:=GetIEVersionStr; lenver:=StrToInt(leftstr(Sver, Pos(‘.‘,Sver)-1)); // if not reg.ValueExists(sAppName)then if lenver<=7 then reg.WriteInteger(sAppName,7000) else if lenver=8 then begin reg.WriteInteger(sAppName,8000) end else if lenver=9 then begin reg.WriteInteger(sAppName,9000) end else if lenver=10 then begin reg.WriteInteger(sAppName,10000) end else if lenver=11 then begin reg.WriteInteger(sAppName,11001) end; end; reg.CloseKey; finally FreeAndNil(reg); end; function TFrmmain.GetIEVersionStr: string; var Reg: TRegistry; // registry access object begin Result := ‘‘; Reg := TRegistry.Create; try Reg.RootKey := Windows.HKEY_LOCAL_MACHINE; if Reg.OpenKeyReadOnly(‘Software\Microsoft\Internet Explorer‘) then begin //这儿新版本IE的取值位置不同所以要判断
if Reg.ValueExists(‘svcVersion‘) then Result := Reg.ReadString(‘svcVersion‘) else if Reg.ValueExists(‘Version‘) then Result := Reg.ReadString(‘Version‘); end; finally Reg.Free; end; end; function TFrmmain.IsWin64:Boolean;
//这个是别人写好的,不记得原出处了,见凉 var Kernel32Handle:THandle; IsWow64Process: function(Handle:Windows.THandle;var Res:Windows.BOOL):Windows.BOOL;stdcall; GetNativeSystemInfo:procedure(var lpSystemInfo:TSystemInfo);stdcall; isWoW64: Bool; SystemInfo: TSystemInfo; const PROCESSOR_ARCHITECTURE_AMD64=9; PROCESSOR_ARCHITECTURE_IA64=6; begin Kernel32Handle:=GetModuleHandle(‘KERNEL32.DLL‘); if Kernel32Handle=0 then Kernel32Handle:=LoadLibrary(‘KERNEL32.DLL‘); if Kernel32Handle<>0 then begin IsWOW64Process:=GetProcAddress(Kernel32Handle,‘IsWow64Process‘); GetNativeSystemInfo:=GetProcAddress(Kernel32Handle,‘GetNativeSystemInfo‘); if Assigned(IsWow64Process) then begin IsWow64Process(GetCurrentProcess,isWoW64); Result:=isWoW64 and Assigned(GetNativeSystemInfo); if Result then begin GetNativeSystemInfo(SystemInfo); Result:=(SystemInfo.wProcessorArchitecture=PROCESSOR_ARCHITECTURE_AMD64)or (SystemInfo.wProcessorArchitecture=PROCESSOR_ARCHITECTURE_IA64); end; end else Result:=False; end else Result:=False; end;

  参考了这儿

参考

{

说明
10001 (0x2711)
Internet Explorer 10。网页以IE 10的标准模式展现,页面!DOCTYPE无效
10000 (0x02710)
Internet Explorer 10。在IE 10标准模式中按照网页上!DOCTYPE指令来显示网页。Internet Explorer 10 默认值。
9999 (0x270F)
Windows Internet Explorer 9. 强制IE9显示,,忽略!DOCTYPE指令
9000 (0x2328)
Internet Explorer 9. Internet Explorer 9默认值,在IE9标准模式中按照网页上!DOCTYPE指令来显示网页。
8888 (0x22B8)
Internet Explorer 8,强制IE8标准模式显示,忽略!DOCTYPE指令
8000 (0x1F40)
Internet Explorer 8默认设置,在IE8标准模式中按照网页上!DOCTYPE指令展示网页
7000 (0x1B58)
使用WebBrowser Control控件的应用程序所使用的默认值,在IE7标准模式中按照网页上!DOCTYPE指令来展示网页。
}


{
https://msdn.microsoft.com/en-us/library/ee330730(v=vs.85).aspx

Internet Feature Controls (B..C)

 

Updated: July 2012

This article describes feature controls with names that begin with the letters B or C. For links to other feature controls, see Feature Controls.

Binary Behavior Security

Microsoft Internet Explorer 6 for Windows XP Service Pack 2 (SP2). The FEATURE_BEHAVIORS allows Binary Behaviors to run more securely. When the feature is enabled, it can be set differently for each security zone by using the URL action flag URLACTION_BEHAVIOR_RUN. For more information, see About URL Security Zones.

By default, this feature is enabled for Windows Internet Explorer and for applications hosting the WebBrowser Control. To disable this feature by using the registry, add the name of your executable file to the following setting.

HKEY_LOCAL_MACHINE (or HKEY_CURRENT_USER)    SOFTWARE       Microsoft          Internet Explorer             Main                FeatureControl                   FEATURE_BEHAVIORS                      contoso.exe = (DWORD) 00000000

The feature is enabled when the value is set to (DWORD) 00000001 and disabled when the value is (DWORD) 00000000.

Browser Emulation

Windows Internet Explorer 8 and later. The FEATURE_BROWSER_EMULATION feature defines the default emulation mode for Internet Explorer and supports the following values.