Out of the corner of my eye

Exploring HumanStateSpace

Out of the corner of my eye header image 2

Prevent user IE settings from overriding your WebObject’s font size

January 3rd, 2008 · 1 Comment

Problem

Company A’s app uses the WebBrowser control to view web pages under its own control, and wants to tightly couple the web page presentation to its app’s look and feel.

User B sets his Internet Explorer accessibility options to “Ignore font sizes specified on web pages“.

As a result, you may get issues where text overflows fixed sized containers. While it isn’t really good for accessibility to prevent the user from increasing their font size, it can also cause problems with usability due to controls falling off forms in the web pages.

Solution

Implement the IDocHostUIHandler interface and override GetOptionKeyPath as in the following example:

HRESULT FAR EXPORT  CCustomControlSite::XDocHostUIHandler::GetOptionKeyPath(BSTR* pbstrKey, DWORD)
{
// override the user's internet option settings to stop them
// making the font too big
HRESULT hr;
WCHAR* szKey = L"Software\\Company A\\App X\\IEOverrides";

//  cbLength is the length of szKey in bytes.
size_t cbLength;
hr = StringCbLengthW(szKey, 1280, &cbLength);

if (pbstrKey)
{
*pbstrKey = (LPOLESTR)CoTaskMemAlloc(cbLength + sizeof(WCHAR));
if (*pbstrKey)
hr = StringCbCopyW(*pbstrKey, cbLength + sizeof(WCHAR), szKey);
}
else
hr = E_INVALIDARG;

return hr;
}

Add keys at Software\Company A\App X\IEOverrides that correspond to HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer, for example a key called Settings with the string “Always Use My Font Size” set to DWORD 0. When the WebBrowser is initialised, it will load the defaults and any overrides in the key specified by GetOptionKeyPath().

See the MSDN documentation for more information.

Tags: C++ dev

1 response so far ↓

  • 1 John Schroedl // Jan 10, 2008 at 9:34 am

    Nice tip! Thanks for sharing…

    John

Leave a Comment