C++ :: IHTMLSelectionObject

Can someone explain / show me how I could use the IHTMLSelectionObject / selectionRange / IHTMLTxtRange to get the selection made to any HTML content and via the source of that selection range...

I believe it's something like this...
1
2
3
4
IHTMLDocument2 doc2 = browser.Document.DomDocument as IHTMLDocument2;
IHTMLTxtRange range = doc2.selection.createRange() as IHTMLTxtRange;

string selectionHtmlText = browser.innerHTML;


How off the path am I? lol
Is that C#? If so, try the MSDN Forums: http://social.msdn.microsoft.com/Forums.

And try to be more elaborated. Are you creating a BHO? Are you just trying to access the page through IE or the WebBrowser control?
webJose: thanks for the reply...I was beginning to think that no one was on this forum...

Anyway, I made some progress... ...here is what my code looks like now...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
mshtml::IHTMLDocument2 ^Doc;
mshtml::IHTMLSelectionObject ^ContentSelection;
mshtml::IHTMLTxtRange ^ContentRange;

... ... ...

private: System::Void viewSelectionSourceToolStripMenuItem_Click(System::Object ^sender, System::EventArgs ^e) {
			UNREALSourceViewer ^sourceViewer = gcnew UNREALSourceViewer();
			sourceViewer->Show();
			Doc = (safe_cast<WebBrowser^>(tabControl1->SelectedTab->Controls[0]))->Document->DomDocument;			
			ContentSelection = Doc->selection;
			ContentRange = safe_cast<IHTMLTxtRange>(ContentSelection->createRange());
			sourceViewer->richTextBox1->Text = ContentRange->htmlText;
	}


But I get the following errors:

c:\doctoral\unreal browser\unreal browser\Form1.h(548) : error C2440: '=' : cannot convert from 'System::Object ^' to 'mshtml::IHTMLDocument2 ^'
No user-defined-conversion operator available, or
Cast from base to derived requires safe_cast or static_cast

c:\doctoral\unreal browser\unreal browser\Form1.h(550) : error C2065: 'IHTMLTxtRange' : undeclared identifier

c:\doctoral\unreal browser\unreal browser\Form1.h(550) : error C3861: 'safe_cast': identifier not found

--------

suggestions?
I see. C++/CLI. Sorry, cannot help on this one. Try the MSDN Forums.
thanks again webJose...

I'll figure it out eventually...
Topic archived. No new replies allowed.