/////////////////////////////////////////////////////////////////////////////
// CHtmlView operations
BOOL CHtmlView::GetSource(CString& refString)
{
BOOL bRetVal = FALSE;
CComPtr<IDispatch> spDisp = GetHtmlDocument();
if (spDisp != NULL)
{
HGLOBAL hMemory;
hMemory = GlobalAlloc(GMEM_MOVEABLE, 0);
if (hMemory != NULL)
{
CComQIPtr<IPersistStreamInit> spPersistStream = spDisp;
if (spPersistStream != NULL)
{
CComPtr<IStream> spStream;
if (SUCCEEDED(CreateStreamOnHGlobal(hMemory, TRUE, &spStream)))
{
spPersistStream->Save(spStream, FALSE);
LPCTSTR pstr = (LPCTSTR) GlobalLock(hMemory);
if (pstr != NULL)
{
// Stream is always ANSI, but CString
// assignment operator will convert implicitly.
bRetVal = TRUE;
TRY
{
refString = pstr;
}
CATCH_ALL(e)
{
bRetVal = FALSE;
DELETE_EXCEPTION(e);
}
END_CATCH_ALL
if(bRetVal == FALSE)
GlobalFree(hMemory);
else
GlobalUnlock(hMemory);
}
}
}
}
}
return bRetVal;
}
向 IHTMLDocument2 寫入 HTML 文本
int CChildView::HqResize(void)
{
USES_CONVERSION;
CComPtr<IHTMLDocument2> pDoc;
CComPtr<IHTMLElementCollection> sphtmlAll;
CComPtr<IHTMLScriptElement> spObject;
CComPtr<IDispatch> spDisp;
CComVariant varName;
CComVariant varIndex;
if(FAILED(m_wndHq.GetDocument(&pDoc)) || pDoc==NULL)
return 0;
CString strHtml="<html><head><title>網(wǎng)頁行情</title></head>"
"<body leftmargin=0 topmargin=0>"
"<OBJECT ID=KYT CODEBASE='http://www./hq/webhq/webhq.cab#version=1,0,0,5'"
"CLASSID='clsid:C952403E-C18D-4332-9F3D-0E1D7C486145'"
"ALIGN='CENTER'"
"width='%d'"
"height='%d'>"
"</OBJECT>"
"<script language=javascript id=KYT1>"
"window.focus();"
"</script>"
"</body>"
"</html>";
CRect rc;
GetClientRect(&rc);
CString strIn;
strIn.Format(strHtml,rc.Width()-20,rc.Height()-15);
CComQIPtr<IPersistStreamInit> spPersistStream(pDoc);
if(spPersistStream==NULL)
return 0;
LPTSTR lpMem = (LPTSTR)::GlobalAlloc( GPTR,strIn.GetLength()+1);
lstrcpy(lpMem,strIn.GetBuffer());
CComPtr<IStream>spStream;
CreateStreamOnHGlobal( lpMem, TRUE, &spStream );
// 初始化后,,裝載顯示
spPersistStream->InitNew();
spPersistStream->Load(spStream );
return 0;
}