如何从流中加载html内容,然后如何创建样式表以在预览窗格中显示html文件(如HTML预览处理程序) [英] 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)

查看:171
本文介绍了如何从流中加载html内容,然后如何创建样式表以在预览窗格中显示html文件(如HTML预览处理程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Visual c ++应用程序,并且必须在预览窗格中为预览处理预览处理程序。我对Xml文档(对于创建样式表来完成此任务的xml文件)有同样的想法,但我不知道如何为.html文件做这件事。



如果我是对的,那么我必须这样做 -

  IHTMLDocument * pDomDoc; 
HRESULT hr = CoCreateInstance(CLSID_HTMLDocument,NULL,CLSCTX_INPROC_SERVER,
IID_IHTMLDocument2,(void **)& pDomDoc);
我不知道之后呢?

任何想法??

我的意思是我知道如何为他们的XML文件做到这一点,如下所示 - $ / $>
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);
//此处m_FinalXMLStream是指示XML文件内容的流
hr = pDomDoc-> load(vtXmlSource,& vfSuccess);
if(vfSuccess!= VARIANT_TRUE)
{
hr = FAILED(hr)? hr:E_FAIL; (保留失败hr


if(SUCCEEDED(hr))
{
if((m_pStyleSheetNode)== NULL)
{
hr = CreateStyleSheetNode();
//这个函数创建样式表并在我的代码中定义。


if(SUCCEEDED(hr))
{
BSTR bstrRtf;
hr = pDomDoc-> transformNode((m_pStyleSheetNode),& bstrRtf);
if(SUCCEEDED(hr))
{
hr = CreatePreviewWindowForXml(bstrRtf);
//此函数调用创建预览Xml内容的窗口维度
SysFreeString(bstrRtf);
}
}
}
pDomDoc-> Release();
}

有关如何对html文件执行相同操作的任何想法? ?我想为HTML文件做同样的事情。明白了吗?如果不是,请再问我一次?



看看这个来理解我真正想做什么 -
我想要做的是我有流任何html文件的内容(IStream * m_FinalHTMLStream;)。如何获得流不是现在的问题。现在重要的是它包含一个html文件的内容(如果您在记事本中打开任何html文件 - _FinalHTMLStream包含其中的相同内容)。现在您可以看到当我们在window exploror中有一个html文件时,如果我们单击它,我们可以在previewpane中看到html文件预览。我想要做同样的事情。为此,我们需要将html文件内容存储在某处(在我的案例中,我已经在_FinalHTMLStream中)。为了做到这一点与XML文件的代码是如上,但我不知道如何做到这一点与HTML文件。这就是我想要的。现在理解??如果没有,请让我知道??
$ b

我正在创建我自己的预览处理程序hor .html文件这就是我正在做的(在简短而精确) ..

解决方案

最后,我已经能够自己显示Html内容(不能从internet和stackoverflow获得任何帮助,但我想给的代码在stackoverflow,这将有助于未来有人做同样的事情)我已经完成了它使用IHTMLDocument2接口和IPersistStreamInit和IMarkupContainer和IMarkupPointer。



代码如下 -

  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(你可以在msdn上看到我不想给勺子提供的语法);
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);
//这个函数负责在预览窗格中创建预览,我已经创建了
//我自己并传递了html内容,这些内容被转换为strText并且类型为BSTR。
SysFreeString(strText);
pBody-> Release();

}
pNewDoc-> Release();
}
pMC-> Release();
}
if(pMkStart)
pMkStart-> Release();
if(pMkFinish)
pMkFinish-> Release();
pMS-> Release();
pMS-> Release();
}
}
pDoc-> Release();
}


返回true;


}

我希望这对于有人。它会给出这个想法,但我不想给汤匙饲料,所以评论了一些部分,但它的解决方案的80%。


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)..

解决方案

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.

这篇关于如何从流中加载html内容,然后如何创建样式表以在预览窗格中显示html文件(如HTML预览处理程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆