Tuesday, January 18, 2011

Changing HTMLViewer rendering mode on Windows

I was recently tasked to look into an issue a customer reported about our HTMLViewer rendering using IE7 instead of IE8 (which the user had installed on his computer). Sorry folks, we haven't implemented a way to switch to using WebKit yet. Anyway, knowing how ActiveX controls worked I automatically assumed that we were using a version dependent ProgramID instead of the version independent ProgramID.

What typically happens when a new version of an ActiveX component is installed is that it will register a new dependent ProgramID but also inherit an independent ProgramID so that existing apps that have the ActiveX control embedded in it can automatically use the new one without the need to modify or recompile anything.

After spending a bit of time looking at our code I found that we are indeed just using the independent ProgramID so I was baffled as to why our HTMLViewer isn't rendering using the latest IE that's installed (in this case IE8). As it turns out, IE8 can render using the IE7 engine, and is the default for apps that have the embedded WebBrowser ActiveX control (like our HTMLViewer). Great, so all I need to do is tell the ActiveX control to render using the IE8 rendering engine right? Er, no, unfortunately there is no API to switch modes (that I'm aware of). There is however a sanctioned way to get your HTMLViewer to render using IE8, through the Registry.

To do this you need to run 'regedit' and add the name of your app to the list in
[(HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE)\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION]
"MyWebBrowser.exe" = dword 8000 (Hex: 0x1F40)



Note: the key FEATURE_BROWSER_EMULATION probably doesn't exist yet so you will need to add that too. As far as I've tested, the absolute path to your application is not required, just the full name.

The registry "hack" and more details about this problem can be found here on Microsoft's blog.

No comments: