在 CHtmlView 的扩展类中,当显示index.html后,如何通过程序设计得到它的html代码?我不想使用OLE 的SAVE AS,想自己变个格式存网页!

解决方案 »

  1.   

    USES_CONVERSION;
    CComPtr<IDispatch> pDocDisp;
    pDocDisp = m_wndWebBrowser.GetDocument();
    CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> spHTML;
    spHTML = pDocDisp;

    if (spHTML)
    {
    // Get the BODY object
    CComQIPtr<IHTMLElement, &IID_IHTMLElement> pBody;
    HRESULT hr = spHTML->get_body(&pBody); 
    if (FAILED(hr))
    return ; // Get the HTML text
    BSTR bstrHTMLText;
    hr = pBody->get_outerHTML(&bstrHTMLText); 
    if (FAILED(hr))
    return ; // Convert the text from Unicode to ANSI
    LPTSTR psz = new TCHAR[SysStringLen(bstrHTMLText)];
    lstrcpy(psz, OLE2T(bstrHTMLText));
          
    MessageBox(psz,"data"); delete[] psz; }