The Microsoft Web Browser control, the tried and true built-in HTML viewer of Windows, does not have a ready made method for loading an HTML document from a text string. Yet its managed wrappers (e. g. System.Windows.Controls.WebBrowser do.
Once the Web browser loads a URL - any URL, even about:blank would do - it has a Document object. And the document supports IPersistStreamInit. So call Navigate("about:blank"), catch the NavigateComplete2 event (or give it a bit of message pumping time), grab the document, and feed it a stream with the HTML via Load() - in single byte encoding, e. g. UTF-8. Note that NavigateComplete2 will fire again. To make sure the control recognizes the charset, pass the <meta> element.Before the first navigation, the Document property of the browser control is NULL. Once the document is initialized, you don't have to navigate every time before resetting its contents to another document.
Internally, that's exactly what WPF's WebBrowser.NavigateToString() does.
CreateStreamOnHGlobal is your friend there.
If there is a way to feed a UTF-16 data block to the browser, I haven't found it.
No comments:
Post a Comment