如何隐藏显示 HTML5 标记的 Web 浏览器控件 (IE) 的滚动条和 window 边框?

How to hide scrollbars and window borders for a web browser control (IE) that is displaying HTML5 markup?

我有一个 MFC 对话框 window,我在其中添加了一个 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。)

我也是:

//'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"));

如果我将 Web 控件中显示的 HTML 定义为:

,则此方法有效
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

但如果我将其定义为 HTML5:

<!DOCTYPE HTML>

上面的代码没有做任何事情。

知道我应该更改什么以使其与 HTML5 标记一起使用吗?

我正在阅读 this 文章,其中写道:

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.

解决此问题的方法是添加

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

在HTML的<head>中,强制使用最新的IE渲染引擎,因此"compatible"有HTML5页。