最近用CWebBrowser2做了个网页的壳,为了美观想禁用滚动条,开始以为可以通过控件自身的方法直接设置,不过试了之后才发现简单的事情也不那么好做。
首先用m_Browser.EnableScrollBar(SB_BOTH,ESB_DISABLE_BOTH);(注:m_Browser为你CWebBrowser2实例)
结果依旧
然后利用强大的网络查啊查啊~基本上可以总结为一个,重写DocumentCompleteExplorer1,具体代码如下:
void CtestDlgDlg::DocumentCompleteExplorer1(LPDISPATCH pDisp, VARIANT* URL)
{
// TODO: 在此处添加消息处理程序代码
IHTMLDocument2 *phtmldoc2 = NULL;
IHTMLElement *phtmlElement = NULL;
IDispatch *pdisp = NULL;
pdisp = m_pListBrowser->get_Document();
if (pdisp != NULL)
{
pdisp->QueryInterface(IID_IHTMLDocument2, (void**)&phtmldoc2);
pdisp->Release();
}
if (phtmldoc2 != NULL)
{
phtmldoc2->get_body(&phtmlElement);
phtmldoc2->Release();
}
if (phtmlElement != NULL)
{
IHTMLBodyElement *phtmlbody = NULL;
phtmlElement->QueryInterface(IID_IHTMLBodyElement, (void**)&phtmlbody);
if (phtmlbody != NULL)
{
phtmlbody->put_scroll(L"no");
phtmlbody->Release();
phtmlElement->Release();
}
}
}
另外还需要:ON_EVENT(CYourDlg, IDC_EXPLORER1, 259, DocumentCompleteExplorer1, VTS_DISPATCH VTS_PVARIANT)
OK!函数重写完了,运行结果还是老样子。。。。
头大得不得了,最后不得不在页面上动手脚,把所有页面都禁用滚动条后,加载还是有那个滚动条的边框,滚动条的边框?对了,然后顺着这个思路查了下果然找一个解决方法
就是页面的头不能带
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
如果简单的
<html>
<head>
滚动条边框的问题就解决了!
不过,去掉这个头后页面上的问题又出现了,样式乱了!这个我们就得请CSS专业人员来搞定了~