How to get Internet Eplorer Selected Text?
-
Hi all. I need to get internet expl. selected text to process in my C# application. Any clear help will be appreciated.
Get the
IHTMLDocument2
interface from the WebBrowser control (include the Microsoft.mshtml assembly in your project and get it from theWebBrowser.Document
property, which may be null), then get theselection
property (which may be null). This gets anIHTMLSelectionObject
from which you can use thetype
property to determine the selection type (text, insertion point, control, etc.) and thecreateRange
method to create a suitable object to work with the actual selection (like aTextRange
). See the documentation forIHTMLSelectionObject
in the MSDN Library for more detailed information).-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
-
Get the
IHTMLDocument2
interface from the WebBrowser control (include the Microsoft.mshtml assembly in your project and get it from theWebBrowser.Document
property, which may be null), then get theselection
property (which may be null). This gets anIHTMLSelectionObject
from which you can use thetype
property to determine the selection type (text, insertion point, control, etc.) and thecreateRange
method to create a suitable object to work with the actual selection (like aTextRange
). See the documentation forIHTMLSelectionObject
in the MSDN Library for more detailed information).-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
Ughhh ugly and messy COM interfaces. Can't wait for Whidbey's managed web browser control. :) The graveyards are filled with indispensible men.
-
Ughhh ugly and messy COM interfaces. Can't wait for Whidbey's managed web browser control. :) The graveyards are filled with indispensible men.
I haven't had a time to look at it (or eat, or drink, or breathe) lately. Is the WebBrowser control completely managed (inside and out), or is it just a nicer CCW for the existing WebBrowser COM control (wrapping mshtml and providing IHLink and all that jazz)? I know our app would definitely benefit from that, especially when the Microsoft.mshtml.dll assembly is almost 8 MB! :eek:
-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
-
Get the
IHTMLDocument2
interface from the WebBrowser control (include the Microsoft.mshtml assembly in your project and get it from theWebBrowser.Document
property, which may be null), then get theselection
property (which may be null). This gets anIHTMLSelectionObject
from which you can use thetype
property to determine the selection type (text, insertion point, control, etc.) and thecreateRange
method to create a suitable object to work with the actual selection (like aTextRange
). See the documentation forIHTMLSelectionObject
in the MSDN Library for more detailed information).-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
-
I didnt understand what you tried to tell. What web browser? Do i have to create mine in order to get the selected text? Say there is an instance of ie open , after that my app is run , and typing a hotkey I see the selected text. I want this.
"IE" as you call it is nothing more than an application that hosts the WebBrowser control (which hosts MSHTML). Read the documentation for the Internet Explorer SDK. Read information specifically about
IHTMLDocument2
and itsselection
property. If you don't understand how to get theIHTMLDocument2
object, there are plenty of articles here on CP about it. Just search for "WebBrowser" or "IHTMLDocument2".-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----