问题
I am developing a Visual c++ application and I have to develp preview handler for HTML preview in preview pane. I have idea of doing the same for Xml documents(for xml files they create style sheet to accomplish this task) but I don't know how to do that for .html file.
If I am right then I have to do something like this-
IHTMLDocument * pDomDoc;
HRESULT hr = CoCreateInstance(CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER,
IID_IHTMLDocument2, (void**)&pDomDoc);
I don't know what after that ??
Any ideas ??
I mean I know how to do this for XML files for them it is as follows-
IXMLDOMDocument *pDomDoc;
IStream *m_FinalXMLStream;
HRESULT hr = CoCreateInstance(__uuidof(DOMDocument60), NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pDomDoc));
if (SUCCEEDED(hr))
{
VARIANT_BOOL vfSuccess = VARIANT_FALSE;
VARIANT vtXmlSource = {0};
V_VT(&vtXmlSource) = VT_UNKNOWN;
V_UNKNOWN(&vtXmlSource) = static_cast<IUnknown *>(m_FinalXMLStream);
//here m_FinalXMLStream is the stream cpntaining the contents of XML file
hr = pDomDoc->load(vtXmlSource, &vfSuccess);
if (vfSuccess != VARIANT_TRUE)
{
hr = FAILED(hr) ? hr : E_FAIL; // keep failed hr
}
if (SUCCEEDED(hr))
{
if ((m_pStyleSheetNode) == NULL)
{
hr = CreateStyleSheetNode();
//This function creates the stylesheet and defined somewhere in my code.
}
if (SUCCEEDED(hr))
{
BSTR bstrRtf;
hr = pDomDoc->transformNode((m_pStyleSheetNode), &bstrRtf);
if (SUCCEEDED(hr))
{
hr = CreatePreviewWindowForXml(bstrRtf);
//This function call creates the window dimension where to preview the Xml contents
SysFreeString(bstrRtf);
}
}
}
pDomDoc->Release();
}
Any idea of how to do the same for html files ? ?I want to do same type of thing for HTML file. Understood ??? if not please ask me again ??
see this to understand what actually I want to do- what I want to do is that I have stream which has contents of any html file(IStream *m_FinalHTMLStream;). how I got the stream is not a matter for now.what is important now is that it contains the contents of a html file(if you open any html file in notepad-_FinalHTMLStream contains the same contents inside it).now as you can see that when we have a html file in window exploror and if we single click on it we can see the html file preview in previewpane.I want to do the same. For doing this we need to have the html file contents store some where(In my case I have in the _FinalHTMLStream) . for doing the same with XML files the code is as above but I don't know how to do that with html files. So thats what I want. Understood now ??if not then please let me know ??
i am creating my own preview handler hor .html file this is what I am doing(in short and precise)..
回答1:
Finally I have been able to display the Html contents myself (couldn't get any help from internet and stackoverflow but i wanted to give the code on stackoverflow so that it would be helpful for someone doing same thing in future) I have done it using IHTMLDocument2 interface and IPersistStreamInit and IMarkupContainer and IMarkupPointer .
The code is as follows-
IHTMLDocument2 * pDoc=NULL;
HRESULT hr = CoCreateInstance(CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER,
IID_IHTMLDocument2, (LPVOID *) &pDoc);
if (pDoc)
{
IPersistStreamInit *pPersist = NULL;
pDoc->QueryInterface(IID_IPersistStreamInit,(LPVOID *) &pPersist);
if (pPersist)
{
IMarkupServices *pMS = NULL;
pPersist->InitNew();
pPersist->Release();
pDoc->QueryInterface(IID_IMarkupServices,(LPVOID *) &pMS);
if (pMS)
{
IMarkupContainer *pMC = NULL;
IMarkupPointer *pMkStart = NULL;
IMarkupPointer *pMkFinish = NULL;
pMS->CreateMarkupPointer(&pMkStart);
pMS->CreateMarkupPointer(&pMkFinish);
pMS->ParseString("you can see the syntax on msdn i don't want to give a spoon feed");
if (pMC)
{
IHTMLDocument2 *pNewDoc = NULL;
pMC->QueryInterface(IID_IHTMLDocument,(LPVOID *) &pNewDoc);
if (pNewDoc)
{
IHTMLElement *pBody;
pNewDoc->get_body(&pBody);
if (pBody)
{
BSTR strText;
pBody->get_innerText(&strText);
hr = instance->CreatePreviewWindowForHtml(strText);
//this function is responsible for creating the preview at preview pane i have created it
// myself and passed the html contents which are converted to strText and is of the type BSTR .
SysFreeString(strText);
pBody->Release();
}
pNewDoc->Release();
}
pMC->Release();
}
if (pMkStart)
pMkStart->Release();
if (pMkFinish)
pMkFinish->Release();
pMS->Release();
pMS->Release();
}
}
pDoc->Release();
}
return true;
}
I hope that could be very useful to someone .It will give the idea to do but i don't want to give a spoon feed so commented some part but its 80% of the solution.
回答2:
You mean you want to make HTML Browser inside a window?
please take a look at this link.
http://www.codeproject.com/Articles/3365/Embed-an-HTML-control-in-your-own-window-using-pla
if this isnt what you want, please explain what you mean by "preview handler for HTML"
来源:https://stackoverflow.com/questions/17909747/how-to-load-html-contents-from-stream-and-then-how-to-create-style-sheet-to-disp