Link to home
Start Free TrialLog in
Avatar of Mad_Angel
Mad_Angel

asked on

axWebBrowser not working properly

Hello,

I want my axWebBrowser to go to a specific url when i click on a button.

The code in the button is this:  axWebBrowser1->Navigate("http://www.google.com/", NULL, NULL, NULL, NULL);
But then it never goes to the page, it just gives out a debugging message.
The project is a "Windows Form Application .NET" and I'm using VS .NET 2003.

Also how would i get the html source from axWebBrowser1 and display it in textBox1?

Thank You
ASKER CERTIFIED SOLUTION
Avatar of drichards
drichards

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mad_Angel
Mad_Angel

ASKER

Thank you,
How would I got about getting the source code now?
To get the source of the document, you use the get_Document() method.  To do this, you need to add a reference to the "Microsoft HTML Object Library" which is mshtml.dll.  This is listed on the "COM" tab of the "Add Reference" dialog.  Then you can do something like this.

    System::Object *pObj = axWebBrowser1->get_Document();
    mshtml::HTMLDocument *pDoc = dynamic_cast<mshtml::HTMLDocument*>(pObj);
    System::Windows::Forms::MessageBox::Show(pDoc->firstChild->nodeName);

To use the HTML document, use the object browser in Vsual Studio to see what methods and properties are available.  You can there by double-clickinh the Microsoft.mshtml reference in the Solution Explorer.
Thank you again, how would I check to see if the page is still loading? I know there is a command for this in VB, but I'm not too sure about VC++.
Add a handler for the DocumentComplete event.  In the property window for the browser control, select the events window and double-click on the event to add a handler.  The document readySate will be "complete" at that pont and you can use the document.
If you want to explicitly check the readyState, you can get the doc (make sure it even exists first) and then look at the readyState property: pDoc->readyState is a String.
Thank you again, I have more questions waiting to be answered.