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:
- 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.
- 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/
- Load HTML content from Stream: http://msdn.microsoft.com/en-us/library/ie/aa752047%28v=vs.85%29.aspx
- Put your html file into temporary file on disk and then navigate to it (as your suggested I see)
如果您使用的是HTML视图控件,那么您可以使用DTM_ADDTEXT消息添加HTML字符串,然后使用DTM_ENDOFSOURCE来通知所有数据都已添加。
使用IHTMLDocument2接口中的write(),如下例所示:http://www.nuonsoft.com/blog/2010/03/24/how-to-use-the-microsoft-webbrowser-control-to-render-html -从记忆里/
从Stream加载HTML内容:http://msdn.microsoft.com/en-us/library/ie/aa752047%28v=vs.85%29.aspx
将您的html文件放入磁盘上的临时文件,然后导航到它(正如我建议的那样)
#1
5
You can:
- 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.
- 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/
- Load HTML content from Stream: http://msdn.microsoft.com/en-us/library/ie/aa752047%28v=vs.85%29.aspx
- Put your html file into temporary file on disk and then navigate to it (as your suggested I see)
如果您使用的是HTML视图控件,那么您可以使用DTM_ADDTEXT消息添加HTML字符串,然后使用DTM_ENDOFSOURCE来通知所有数据都已添加。
使用IHTMLDocument2接口中的write(),如下例所示:http://www.nuonsoft.com/blog/2010/03/24/how-to-use-the-microsoft-webbrowser-control-to-render-html -从记忆里/
从Stream加载HTML内容:http://msdn.microsoft.com/en-us/library/ie/aa752047%28v=vs.85%29.aspx
将您的html文件放入磁盘上的临时文件,然后导航到它(正如我建议的那样)