Wenyi
The IE WebControl control provides features that display HTML, but only can display URLs or files. Many friends ask about the method of displaying HTML content in memory, I found a code on the Internet a few days ago, I have some explanations here.
Idea:
First display an empty HTML file with WebControl (for WebControl usage)
Then use the interface IID_IHTMLDocument2 to reset the InnerHTML attribute within the Body tag. (Need to know DHTML)
Implementation:
Derived CMOREHTMLVIEW from ChtmlView.
Show an empty HTML file, you can use the navigate2 method directly, you can specify a default HTML file, but WebControl can also display content defined in the resource, according to the definition of RES protocol, display the following representation when using the data in the resource Method: res: // sfile [/ stype] / SID SFILE: Indicates the file style: resource type, such as RT_HTML or your own defined resource type, omo rt_html, SID: Resource ID
Examples of code void CMoreHtmlView :: NavigateMemory () {// get application name CString sAppName = AfxGetAppName (); CString sResourseID; // get resourse ID of Empty Html sResourseID.Format ( "% d", IDR_EMPTY_HTML); CString sNavigatePath; // Compile snaviGatePath = "res: //" SAPPNAME ".exe /" SResourseId; NaviGate2 (SnaviGatePath); // Load the HTML file in the resource Implementation function // Activate Memory mode m_bmemorymode = true;}
Modify the InnerHTML property in the Body tag.
Examples of code BOOL CMoreHtmlView :: PutBodyContent (LPSTR lpstrContent) {// store body content if m_lpstrBodyContent = lpstrContent (lpstrContent); // check if HtmlDocument initialized if (m_pHtmlDoc2) // m_pHtmlDoc2 point interfaces IID_IHTMLDocument2 {HRESULT hr = S_OK; IHTMLElement * pBodyElement ; // get body element hr = m_pHtmlDoc2-> get_body (& pBodyElement); // get body tag // put content to body element _bstr_t pbBody (m_lpstrBodyContent); hr = pBodyElement-> put_innerHTML (pbBody); // set the HTML tag content
IF (hr == s_false) Return False; Else Return true;} else returnif false;
How to get IHTMLDocument2
void CMoreHtmlView :: OnDocumentComplete (LPCTSTR lpszURL) {// show html on first loading of document if (m_bMemoryMode) {LPDISPATCH lpDispatch; lpDispatch = GetHtmlDocument (); ASSERT (lpDispatch); // get html document from IDispatch HRESULT hr = lpDispatch- > Queryinterface (IID_IHTMLDocument2, (void **) & m_phtmldoc2); // This row implements function if (successmeded (hr)) showMemoryHTML ();} chtmlview :: OndocumentComplete (lpszurl);}
Demonstration code reading:
The three points mentioned above are basic methods, but to read the code I have found to do a special instructions. The gain of IHTMLDocument2 is to query this interface after the file is loaded.
Source: http://www.vchelp.net/vchelp/file2002_3/htmlmemory.zip