System::Windows::Forms::WebBrowser and IHTMLDocument2

  • Thread starter Thread starter A Wieser
  • Start date Start date
A

A Wieser

I'm trying to create a browser control in edit mode with VS 2005 using C++.

I've added the WebBrowser Control to my form as webBrowser1.

However, I can't seem to get to an IHTMLDocument2 so that I can switch
designMode on.
I try this, but get an exception.



mshtml::IHTMLDocument2 ^doc;
Object ^boxDoc = this->webBrowser1->Document;
doc = (mshtml::IHTMLDocument2 ^)boxDoc; // exception thrown here!
doc->designMode = "On";

An unhandled exception of type 'System.InvalidCastException' occurred in
testforms.exe

Additional information: Unable to cast object of type
'System.Windows.Forms.HtmlDocument' to type 'mshtml.IHTMLDocument2'.

Any suggestions on how to do this?

Tony
 
Hello A,

You can't really cast it as webBrowser doesn't implement mshtml.IHTMLDocument2.
You can use reflection to do that.

It should look like

Type ^type;
PropertyInfo ^propertyInfo;
type = Webbrowser.Document.DomDocument.GetType();
propertyInfo = Type.GetProperty("designMode");
propertyInfo.SetValue(base.Document.DomDocument, "On", null);
 
Hello A,

Try....

Type ^type;
PropertyInfo ^propertyInfo;
type = this->webBrowser1->Document->DomDocument->GetType();
propertyInfo = type->GetProperty("designMode"); // is null
propertyInfo->SetValue(base.Document.DomDocument, "On", null);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top