<p>Here's what I am trying to do:</p>

<p>Select text from a webpage I pulled up using my web browser control.After clicking a button while this text is still selected I would like a message box to pop-up displaying the text that was highlighted by the user. How do I get this functionality to work in my wpf application?</p>

<p>I think I'm on the right track using mshtml but I get an error that says:</p>

<blockquote>
  <p>Error HRESULT E_FAIL has been returned from a call to a COM component.</p>
</blockquote>

<p>This error will happen even when I try something small on the document like changing the title.</p>

<p>The code is below:</p>

<pre><code>IHTMLDocument2 doc = (IHTMLDocument2)this.webBookText.Document;
doc.title = "l";
</code></pre>

Well, for starters it would be a lot simpler to use
```
WebBrowser
```
than mshtml (note that you can still host
```
WebBrowser
```
in WPF) - this will certainly let you do simple things a lot easier:
```
```
webBook.Document.Title = "foo";
```
```
However, I can't see anything there that would let you work with selections very easily...
You can get the selected
element
with
```
.Document.ActiveElement
```
, but this is the entire element - not the selected portion.