久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

VC知識庫BLOG-玻璃小屋-從 IHTMLDocument2 獲得/寫入 HTML 文本 (IPersistStreamInit)

 xiaoqdu 2008-11-28

/////////////////////////////////////////////////////////////////////////////
// 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;
}

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點,。請注意甄別內(nèi)容中的聯(lián)系方式,、誘導(dǎo)購買等信息,謹(jǐn)防詐騙,。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多