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)

…衆ロ難τιáo~ 提交于 2019-12-06 11:31:27

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.

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"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!