How to create IE add-ons in VB.NET, C#, C++
for Internet Explorer: IE6, IE7 and IE8
Add-in Express™ |
|
Interop Assemblies option |
IE version installed on the development PC |
IE versions supported by the add-on |
|
IE6, IE7, or IE8 |
IE6, IE7 and IE8 |
|
IE6 |
IE6, IE7 and IE8 |
|
IE7 |
IE7 and IE8 |
|
IE8 |
IE8 |
To access properties or methods defined in a newer IE version, you use late binding (see Type.InvokeMember in MSDN). To use constants defined in a newer IE version, you must know them; we suggest using the .NET Reflector to obtain constants defined in newer versions of IE. As to events, the IE module provides all events; just use an appropriate one.
The second window of the project wizard allows choosing between using the existing .SNK file or creating a new one.
Add-in Express project structure
A newly created IE solution is shown below:
Let's walk through the files.
The files in the Loader folder (adxloader.dll, adxloader64.dll and adxloader.dll.manifest) allow your add-on to load to Internet Explorer. You use the manifest to tune this process. See Add-in Express Loader.
The files in the Resources folder are just sample icons for toolbar buttons. They are pre-added to Icons.resx (see Adding a custom button to IE toolbar). They serve as placeholders only and you need to replace them with actual icons in your add-on.
GlobalData.vb – a class that can store data available for all add-on instances within the process.
IEModule.vb – the heart of the project; provides a number of properties, methods and events that relate to the add-on and its UI.
MyIEAddon1.snk – a strong-name key file.
IEModule.vb
IEModule is a core part of your IE add-on. From some point of view, it is the add-on itself. It specifies the name of your Internet Explorer add-on. It stores components that represent toolbars, toolbar buttons, menu items, context menu items, and Explorer bars created by your add-on. In addition, it is a container for other components required for the add-on to function. Finally, it communicates with the IE application to provide you with a complete set of IE events such as BeforeNavigate2 and DownloadComplete.
You access the module's designer and code via the context menu in the Solution Explorer window.
Note. The designer surface of the IEModule provides a context menu revealing a number of commands; you use these commands to add Add-in Express components to the module.

For a newly created project, the module contains the code shown below. Pay attention to the IEApp and HTMLDocument properties; you will certainly use them in your code.
Imports System
Imports System.Runtime.InteropServices
Imports System.ComponentModel
Imports System.Windows.Forms
Imports IE = Interop.SHDocVw
'Add-in Express for Internet Explorer Module
_
Public Class IEModule
Inherits AddinExpress.IE.ADXIEModule
#Region " Component Designer generated code. "
'Required by designer
Private components As System.ComponentModel.IContainer
'Required by designer - do not modify
'the following method
Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container()
'
'IEModule
'
Me.ModuleName = "MyIEAddon1"
End Sub
#End Region
#Region " Add-in Express automatic code "
'Required by Add-in Express - do not modify
'the methods within this region
Public Overrides Function GetContainer() As _
System.ComponentModel.IContainer
If components Is Nothing Then
components = New System.ComponentModel.Container
End If
GetContainer = components
End Function
_
Public Shared Sub RegisterIEModule(ByVal t As Type)
AddinExpress.IE.ADXIEModule.RegisterIEModuleInternal(t)
End Sub
_
Public Shared Sub UnregisterIEModule(ByVal t As Type)
AddinExpress.IE.ADXIEModule.UnregisterIEModuleInternal(t)
End Sub
_
Public Class IECustomContextMenuCommands
Inherits AddinExpress.IE.ADXIEModule.ADXIEContextMenuCommandDispatcher
End Class
_
Public Class IECustomCommands
Inherits AddinExpress.IE.ADXIEModule.ADXIECommandDispatcher
End Class
#End Region
Public Sub New()
MyBase.New()
'This call is required by the Component Designer
InitializeComponent()
End Sub
Public Sub New(ByVal container As IContainer)
MyBase.New(container)
container.Add(Me)
'This call is required by the Component Designer
InitializeComponent()
End Sub
Public ReadOnly Property IEApp() As IE.WebBrowser
Get
Return CType(Me.IEObj, IE.WebBrowser)
End Get
End Property
Public ReadOnly Property HTMLDocument() As mshtml.HTMLDocument
Get
Return CType(Me.HTMLDocumentObj, mshtml.HTMLDocument)
End Get
End Property
End Class
See an example of an IE6 and IE7 add-on with source code.

