问题描述 : CHtmlView 或CWebview 或 CWebBrowser 会有一下 类似与下陷的边框,很难看,怎样去除这个边框 。
对于这个问题,查了好久,最后终于发现 这个不是控件的问题 ,是 Html 的问题 。
解决办法 :
1。去除 xhtml 头 。
如 去除 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 这个头
直接 <html>
2. 加入body样式 <style>body{border:none; margin:0; width:100%;}</style> 。
然后就可以了 。
因为我的代码 是直接Load string 的 ,load string 实现的步骤:
1. 在initdialong 里面 ,加入 m_WebView.Navigate2(COleVariant(_T("")), NULL, NULL, NULL, NULL);
不然后报错 , 这个不能是 m_WebView.Navigate2(COleVariant(_T("about:blank")), NULL, NULL, NULL, NULL); 因为about:blank 也是会带有边框。
2. dialong 添加方法 , 淡然别忘了头文件 里面 添加 方法声明 void DocumentComplete(LPTSTR str);:
void CFloatWinDlg::DocumentComplete(LPTSTR str)
{
//AfxMessageBox(str);
m_cWebView.Navigate2(COleVariant(_T("")), NULL, NULL, NULL, NULL);
CComPtr<IDispatch> spDoc(m_cWebView.get_Document());
ASSERT( spDoc );
CComQIPtr<IPersistStreamInit, &IID_IPersistStreamInit > spPSI(spDoc);
ASSERT(spPSI);
LPTSTR lpMem = (LPTSTR)::GlobalAlloc( GPTR, 1024*1024 );
ASSERT( lpMem );
::lstrcpy( lpMem, str );
IStream *spStream;
::CreateStreamOnHGlobal( lpMem, TRUE, &spStream );
ASSERT( spStream );
HRESULT hr = spPSI->InitNew();
ASSERT( SUCCEEDED(hr) );
hr = spPSI->Load( spStream );
ASSERT(SUCCEEDED(hr));
spStream->Release();
}
3,想load string 直接调这个dialog 方法 把html 字符串 传进去 就行 , 别忘了 家body 样式去除边框哦 。