I have an MFC dialog window where I added a web browser control (which encapsulates Internet Explorer
engine.) The goal of the following code is to (temporarily) remove scrollbars and window borders from that control (to call IViewObject::Draw.)
So I do:
//'m_browser' = is a web browser control of type `CExplorer1`
IDispatch* pHtmlDoc = m_browser.get_Document();
CComPtr<IHTMLDocument2> pHtmlDocument2;
pHtmlDoc->QueryInterface(IID_IHTMLDocument2, (void**)&pHtmlDocument2);
CComPtr<IHTMLElement> pBody;
pHtmlDocument2->get_body(&pBody);
CComPtr<IHTMLStyle> pStyle;
pBody->get_style(&pStyle);
//Remove borders
pStyle->put_borderStyle(CComBSTR("none"));
//Remove scrollbars
pBody->setAttribute(CComBSTR(L"scroll"), CComVariant(L"no"));
This approach works if I define the HTML that is shown in the web control as:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
but if I define it as HTML5:
<!DOCTYPE HTML>
the code above does not do anything.
Any idea what shall I change to make it work with HTML5 markup?
I was reading this article, where it says:
The Web Browser Control is - by default - perpetually stuck in IE 7 rendering mode. Even though we're now up to IE 11 and a reasonably HTML5 compatible browser, the Web Browser Control always uses the IE 7 rendering engine by default. This is because the original versions of the ActiveX control used this mode and for backwards compatibility the Control continues this outdated and very HTML5 unfriendly default.
A workaround for this is to add
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
in the <head>
of the HTML, forcing the latest IE rendering engine to be used, and thus making it "compatible" with HTML5 pages.