MFC C ++ WebBrowser控件从字符串加载HTML

时间:2022-11-11 23:12:17

I understand how to use the WebBrowser control to navigate to a page online:

我了解如何使用WebBrowser控件在线导航到页面:

m_browser.Navigate("www.microsoft.com", NULL, NULL, NULL, NULL);

But what if I want to load in a string of HTML to display on the web browser? Is that doable? Or do I need to make a temporary html file locally and just navigate to that?

但是,如果我想加载一串HTML以在Web浏览器上显示该怎么办?那可行吗?或者我是否需要在本地创建一个临时的html文件,然后导航到那个?

I appreciate any insight!

我很欣赏任何见解!

1 个解决方案

#1


5  

You can:

  1. If you are using HTML View Control then you might use DTM_ADDTEXT message to add HTML string, and later DTM_ENDOFSOURCE to inform that all data was added.
  2. 如果您使用的是HTML视图控件,那么您可以使用DTM_ADDTEXT消息添加HTML字符串,然后使用DTM_ENDOFSOURCE来通知所有数据都已添加。

  3. Use write() from IHTMLDocument2 interface, as in following example: http://www.nuonsoft.com/blog/2010/03/24/how-to-use-the-microsoft-webbrowser-control-to-render-html-from-memory/
  4. 使用IHTMLDocument2接口中的write(),如下例所示:http://www.nuonsoft.com/blog/2010/03/24/how-to-use-the-microsoft-webbrowser-control-to-render-html -从记忆里/

  5. Load HTML content from Stream: http://msdn.microsoft.com/en-us/library/ie/aa752047%28v=vs.85%29.aspx
  6. 从Stream加载HTML内容:http://msdn.microsoft.com/en-us/library/ie/aa752047%28v=vs.85%29.aspx

  7. Put your html file into temporary file on disk and then navigate to it (as your suggested I see)
  8. 将您的html文件放入磁盘上的临时文件,然后导航到它(正如我建议的那样)

#1


5  

You can:

  1. If you are using HTML View Control then you might use DTM_ADDTEXT message to add HTML string, and later DTM_ENDOFSOURCE to inform that all data was added.
  2. 如果您使用的是HTML视图控件,那么您可以使用DTM_ADDTEXT消息添加HTML字符串,然后使用DTM_ENDOFSOURCE来通知所有数据都已添加。

  3. Use write() from IHTMLDocument2 interface, as in following example: http://www.nuonsoft.com/blog/2010/03/24/how-to-use-the-microsoft-webbrowser-control-to-render-html-from-memory/
  4. 使用IHTMLDocument2接口中的write(),如下例所示:http://www.nuonsoft.com/blog/2010/03/24/how-to-use-the-microsoft-webbrowser-control-to-render-html -从记忆里/

  5. Load HTML content from Stream: http://msdn.microsoft.com/en-us/library/ie/aa752047%28v=vs.85%29.aspx
  6. 从Stream加载HTML内容:http://msdn.microsoft.com/en-us/library/ie/aa752047%28v=vs.85%29.aspx

  7. Put your html file into temporary file on disk and then navigate to it (as your suggested I see)
  8. 将您的html文件放入磁盘上的临时文件,然后导航到它(正如我建议的那样)