Expand Minimize
59 out of 133 rated this helpful - Rate this topic

InternetExplorer object

Controls an instance of Windows Internet Explorer through automation.

Remarks

Windows Internet Explorer 8. On Windows Vista, to create an instance of Internet Explorer running at a medium integrity level, pass CLSID_InternetExplorerMedium (defined in exdisp.idl) to CoCreateInstance. The resulting InternetExplorerMedium object supports the same events, methods, and properties as the InternetExplorer object.

Examples

The following example uses CreateObject in Visual Basic to launch an instance of Internet Explorer.


Dim IE As SHDocVw.InternetExplorer

Set IE = CreateObject("InternetExplorer.Application")

The following C# example launches an instance of Internet Explorer and navigates to a Web page. The code also demonstrates how to create an event handler to listen for the BeforeNavigate2 event. The project requires a reference to the Microsoft Internet Controls (SHDocVw) type library.


using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class EventHandlers
    {
        public void OnBeforeNavigate2(object sender, ref object URL, 
                                      ref object Flags, ref object Target, 
                                      ref object PostData, ref object Headers, 
                                      ref bool Cancel) 
        {
            Console.WriteLine("BeforeNavigate2 fired!");
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            EventHandlers e = new EventHandlers();
            SHDocVw.InternetExplorer IE = new SHDocVw.InternetExplorer();
            object Empty = 0;
            object URL = "http://www.live.com";

            // override BeforeNavigate2 event
            IE.BeforeNavigate2 += new
                 SHDocVw.DWebBrowserEvents2_BeforeNavigate2EventHandler(
                         e.OnBeforeNavigate2);

            IE.Visible = true;
            IE.Navigate2(ref URL, ref Empty, ref Empty, ref Empty, ref Empty);

            System.Threading.Thread.Sleep(5000);

            IE.Quit();
        }
    }
} 

 

 

Send comments about this topic to Microsoft

Build date: 11/12/2012

Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.