在CWEBBROWSER中只能Navigate("http://www.csdn.net",NULL,NULL,NULL,NULL);
现在我有个CString变量,里面就是HTML的源代码如
CString html="<html>
<body>
<br>CSDN</br>
<//body>
</html>";
我要怎么将它用HTNL方式在CWEBBROWSER控件中显示出来(声明,不通过创建零时HTML文件的方式)各位大侠有什么方法么?
还有我有MP3的二进制代码,能不能不创建MP3文件就当做MP3文件使用呢?
谢谢!

解决方案 »

  1.   

    #include "Mshtml.h"
    #include "atlconv.h"
    #include "atlbase.h"//打开一个网页等到它执行完成后执行下面代码:
    CString strHtml="<html><head><title>网页行情</title></head"
      "<body leftmargin=0 topmargin=0>"
      "<div> 你好 </div>" "<br>""<div>你好</div>"
      "</body>"
      "</html>"; USES_CONVERSION;
    CComPtr<IHTMLDocument2> pDoc;


    CComPtr<IHTMLElementCollection> sphtmlAll;
    CComPtr<IHTMLScriptElement> spObject;
    CComPtr<IDispatch> spDisp;
    CComVariant varName;
    CComVariant varIndex;
    pDoc=(IHTMLDocument2*)m_webbrowser.GetDocument();
    //if(FAILED(m_wndHq.GetDocument(&pDoc)) || pDoc==NULL)
    // return 0;

    try{

    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(0));


    CComPtr<IStream>spStream;
    CreateStreamOnHGlobal( lpMem, TRUE, &spStream );
    // 初始化后,装载显示
    spPersistStream->InitNew();
    spPersistStream->Load(spStream );
    }
    catch(...){}
      

  2.   

    我敲进去了WEBBROWSER控件没有反应啊?.
      

  3.   

    笨方法是写个分析网页字符串的函数,传进包含源码的Html字符串, 返回要显示的内容就可以!
      

  4.   

    第一个问题
    这里有代码
    Loading HTML content from a Stream
    http://msdn.microsoft.com/en-us/library/aa752047(VS.85).aspx第二个问题,你把mp3作为一个自定义类型资源添加到你的exe中,然后在html中引用时使用"res://IDR_MYMP3"的方式进行引用.(估计可行,没有验证过哈!)
      

  5.   

    原理在于取得IPersistStreamInit接口指针,然后把网页写到IStream流中去。 
    关键代码: #include "mshtml.h" 
    //在SourceView中填写HtmlView中网页的源程序 
    void CMainFrame::OnMethod2() 

    IHTMLDocument2 *pHTMLDocument=NULL; 
    IPersistStreamInit *pPSI=NULL; IStream *pStream=NULL; 
    HGLOBAL hHTMLText; if (!(pHTMLDocument = (IHTMLDocument2*)m_pHtmlView->m_browser.GetDocument())) 
    return; if (FAILED(pHTMLDocument->QueryInterface(&pPSI))) 

    // pHTMLDocument->Release(); 
    return; 
    } hHTMLText = GlobalAlloc(GMEM_FIXED, MAX_SIZE); 
    CreateStreamOnHGlobal(hHTMLText, TRUE, &pStream); 
    pPSI->Save(pStream, FALSE); // m_pSourceView->SetWindowText((char*)hHTMLText); long nEditLength = m_pSourceView->GetEditCtrl().GetWindowTextLength(); 
    m_pSourceView->GetEditCtrl().SetSel(0, nEditLength); 
    m_pSourceView->GetEditCtrl().ReplaceSel(""); 
    char *pText = (char*)hHTMLText; 
    long lHtmlLength = strlen(pText); 
    CString str(""); 
    long n = 0; 
    for (long i=0; i < lHtmlLength; i++) 

    if (*pText != 0x0d && *pText != 0x0a) 

    str += *pText; 
    pText++; 

    else 

    pText++; 
    if (*pText == 0x0a) 
    pText++; 
    str += "\r\n"; 
    nEditLength = m_pSourceView->GetEditCtrl().GetWindowTextLength(); 
    m_pSourceView->GetEditCtrl().SetSel(nEditLength, nEditLength); 
    m_pSourceView->GetEditCtrl().ReplaceSel(str); 
    str.Empty(); 

    } pStream->Release(); 
    pPSI->Release(); 
    // pHTMLDocument->Release();