初学者怎么在单文档CHtmlView中追加显示内容 VC6.0
菜鸟求助:如何在单文档CHtmlView中追加显示内容 VC6.0
各位高手:
最近小弟正在做的一个测试程序,基于单文档的架构,要在界面实时显示测试报告,视图部分时从CHtmlView继承的。现在可以将内存中的HTML源码显示在界面,但是无法实现追加显示。(我所谓的追加显示,是指在原有内容的基础上再显示新的内容。)之前考虑过每次都刷新整个界面,新旧内容一起显示出来,如果测试时间比较久,显示内容太多的话效率会比较低。
向大家请教一下,怎么能够将原有内容保持在界面的情况下,追加显示新的内容。
下面是我显示内存中HTML内容的代码:
void CToolView::DisplayHtmlInMemory(CString strText)
{
LPDISPATCH lpDispatch;
lpDispatch = GetHtmlDocument();
ASSERT(lpDispatch);
CComQIPtr <IHTMLDocument2, &IID_IHTMLDocument2> pDoc2;
HRESULT hr;
hr = lpDispatch-> QueryInterface(IID_IHTMLDocument2, (void**)&pDoc2);
if(SUCCEEDED(hr))
{
IHTMLElement *pBodyElement;
pDoc2-> get_body( &pBodyElement);
BSTR body;
body=::_com_util::ConvertStringToBSTR(strText);
pBodyElement-> put_innerHTML(body);
pDoc2.Release();
}
lpDispatch-> Release();
}
我的另外一种显示方法:
程序启动时调用一次InitHtmlDisplay(),每次显示的时候再调用DisplayHtmlInMemory。
void CToolView::InitHtmlDisplay()
{
HRESULT hr;
m_lpDisp = GetApplication();
if (m_lpDisp == NULL)
{
return;
}
hr = m_lpDisp->QueryInterface(IID_IWebBrowser2, (void**)&m_pBrowser);
if (!SUCCEEDED(hr))
{
return;
}
hr = m_pBrowser->QueryInterface( IID_IUnknown, (void**)&m_pUnkBrowser);
if (!SUCCEEDED(hr))
{
return;
}
hr = m_lpDisp->QueryInterface( IID_IUnknown, (void**)&m_pUnkDisp );
if (!SUCCEEDED(hr))
{
return;
}
if ( AfxMessageBox!= m_pUnkDisp )
{
return;
}
hr = m_pBrowser->get_Document(&m_pHtmlDoc);
if (!SUCCEEDED(hr))
{
return;
}
hr = m_pHtmlDoc->QueryInterface(IID_IPersistStreamInit, (void**)&m_pPersistStreamInit);
if (!SUCCEEDED(hr))
{
return;
}
// 初始化文档.
hr = m_pPersistStreamInit->InitNew();
if (!SUCCEEDED(hr))
{
return;
}
}
void CToolView::DisplayHtmlInMemory(CString strText)
{
size_t cchLength=strText.GetLength();
hHTMLText = GlobalAlloc( GPTR, cchLength+1 );
if ( hHTMLText )
{
各位高手:
最近小弟正在做的一个测试程序,基于单文档的架构,要在界面实时显示测试报告,视图部分时从CHtmlView继承的。现在可以将内存中的HTML源码显示在界面,但是无法实现追加显示。(我所谓的追加显示,是指在原有内容的基础上再显示新的内容。)之前考虑过每次都刷新整个界面,新旧内容一起显示出来,如果测试时间比较久,显示内容太多的话效率会比较低。
向大家请教一下,怎么能够将原有内容保持在界面的情况下,追加显示新的内容。
下面是我显示内存中HTML内容的代码:
void CToolView::DisplayHtmlInMemory(CString strText)
{
LPDISPATCH lpDispatch;
lpDispatch = GetHtmlDocument();
ASSERT(lpDispatch);
CComQIPtr <IHTMLDocument2, &IID_IHTMLDocument2> pDoc2;
HRESULT hr;
hr = lpDispatch-> QueryInterface(IID_IHTMLDocument2, (void**)&pDoc2);
if(SUCCEEDED(hr))
{
IHTMLElement *pBodyElement;
pDoc2-> get_body( &pBodyElement);
BSTR body;
body=::_com_util::ConvertStringToBSTR(strText);
pBodyElement-> put_innerHTML(body);
pDoc2.Release();
}
lpDispatch-> Release();
}
我的另外一种显示方法:
程序启动时调用一次InitHtmlDisplay(),每次显示的时候再调用DisplayHtmlInMemory。
void CToolView::InitHtmlDisplay()
{
HRESULT hr;
m_lpDisp = GetApplication();
if (m_lpDisp == NULL)
{
return;
}
hr = m_lpDisp->QueryInterface(IID_IWebBrowser2, (void**)&m_pBrowser);
if (!SUCCEEDED(hr))
{
return;
}
hr = m_pBrowser->QueryInterface( IID_IUnknown, (void**)&m_pUnkBrowser);
if (!SUCCEEDED(hr))
{
return;
}
hr = m_lpDisp->QueryInterface( IID_IUnknown, (void**)&m_pUnkDisp );
if (!SUCCEEDED(hr))
{
return;
}
if ( AfxMessageBox!= m_pUnkDisp )
{
return;
}
hr = m_pBrowser->get_Document(&m_pHtmlDoc);
if (!SUCCEEDED(hr))
{
return;
}
hr = m_pHtmlDoc->QueryInterface(IID_IPersistStreamInit, (void**)&m_pPersistStreamInit);
if (!SUCCEEDED(hr))
{
return;
}
// 初始化文档.
hr = m_pPersistStreamInit->InitNew();
if (!SUCCEEDED(hr))
{
return;
}
}
void CToolView::DisplayHtmlInMemory(CString strText)
{
size_t cchLength=strText.GetLength();
hHTMLText = GlobalAlloc( GPTR, cchLength+1 );
if ( hHTMLText )
{