[英]How to load html contents from stream and then how to create style sheet to display the html file in preview pane (like HTML preview handler)
I am developing a Visual c++ application and I have to develp preview handler for HTML preview in preview pane. 我正在开发Visual c ++应用程序,并且必须在预览窗格中开发HTML预览的预览处理程序。 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.
我有为Xml文档做同样的想法(对于xml文件,他们创建样式表来完成此任务),但是我不知道如何为.html文件做同样的事情。
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- 我的意思是我知道如何为XML文件执行以下操作:
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 ? 关于如何对html文件执行相同操作的任何想法? ?I want to do same type of thing for HTML file.
我想对HTML文件执行相同类型的操作。 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;). 看到此内容以了解我实际上要做什么-我想做的是拥有包含任何html文件(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.
现在我不知道如何获取流。现在重要的是它包含html文件的内容(如果您在notepad-_FinalHTMLStream中打开任何html文件,则其中包含相同的内容)。现在您可以看到当我们在窗口浏览器中有一个html文件时,如果单击它,我们可以在Previewpane中看到html文件预览。我也想这样做。 For doing this we need to have the html file contents store some where(In my case I have in the _FinalHTMLStream) .
为此,我们需要将html文件内容存储在where(在我的情况下,我在_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.
对于使用XML文件执行相同的操作,代码如上所述,但是我不知道如何使用html文件执行此操作。 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) .. 我正在创建自己的预览处理程序hor .html文件,这就是我正在做的(简短而精确) ..
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 . 最终,我能够自己显示HTML内容(无法从Internet和stackoverflow获得任何帮助,但我想在stackoverflow上提供代码,以便将来对做相同事情的人有所帮助) IHTMLDocument2接口以及IPersistStreamInit和IMarkupContainer和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. 我希望这对某人可能非常有用。它将给出想法,但我不想提供汤匙饲料,因此评论了一部分,但提出了解决方案的80%。
You mean you want to make HTML Browser inside a window? 您是说要在窗口内制作HTML浏览器?
please take a look at this link. 请查看此链接。
http://www.codeproject.com/Articles/3365/Embed-an-HTML-control-in-your-own-window-using-pla 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" 如果这不是您想要的,请解释“ HTML预览处理程序”的意思。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.