The IE extensions presented thus far offer limited access to good real estate in the browser frame. Developers looking for greater acreage at a low price can find solace in band objects. Band objects were introduced as a way for developers to extend the Windows shell and the IE browser frame. These UI areas are very prominent, and are shown no matter which tab or page is displayed in the browser. If you want this kind of access to a user, band objects are right for you.
In this chapter I present a logical approach to creating three types of band objects: toolbars, Vertical Explorer bars, and Horizontal Explorer bars. I begin with a basic overview of these extensions, how they are the same, and where they differ and fit into the IE UI. I follow by creating a base class called BandObject
, a foundation for creating each type of band object simply and easily. After reviewing the internal architecture and registration process of this library, I create an example of each type of band object and show the result in a real IE window. Now you can create your own toolbar in a few lines of managed code!
Band objects were added to IE 4.0 as a means for developers to extend the browser frame. In the context of the IE browser frame, these objects are more commonly referred to as tool bands and Explorer bars. The Explorer shell uses band objects as well, a usage referred to as desk bands. Whether used inside or outside the browser, band objects provide the ability for a developer to extend the frame of a window using panes attached to the sides or top of a window.
IE offers three main areas where band objects can be displayed: the toolbar area, the left side of the window (Vertical Explorer bar region), and the bottom of the window (Horizontal Explorer bar region) (see Figure 14-1).
The toolbar band object, shown at the top of this figure, is a generic toolbar that can be inserted into IE's toolbar band. The Vertical Explorer bar is a docked child window that is placed on the left-hand side of the browser window. The Horizontal Explorer bar, like the vertical one, is also a docked child window, but docked to the bottom of the browser window directly above the status bar.
Band objects are exposed in the IE Tools menu. These menu entries are used for basic management, and for showing or hiding the objects. Figure 14-2 shows this management experience.
Management of these items is not limited to the Tools menu. Each band object is a registered IE extension, thus subject to management through the Manage Add-Ons window. Figure 14-3 shows a toolbar, Vertical Explorer bar, and Horizontal Explorer bar displayed in this dialog.
All band objects can also be closed using the close X on each. For toolbars, this is found on the left side of each item. Vertical and Horizontal Explorer bars have their Xs exposed in the title bar on each. Like objects disabled by the Manage Add-Ons dialog, those closed with the X remain loaded in memory until the browser is restarted.
Every type of band object available to IE developers—toolbars, Vertical Explorer bars, and Horizontal Explorer bars—is built on the same building blocks. Each type consists of a user interface that is placed on sites within the browser, and interfaces used to link the object to the browser, the Windows shell, and COM.
In managed .NET code (which this chapter focuses on), the first block is a generic UserControl.UserControl
s provide the UI block that can be placed into each of the three main UI areas provided by IE. Unmanaged interfaces make up the rest of the implementation. The implemented interfaces are shown in Listing 14-1.
Example 14.1. Basic Architecture for the BandObject Class
public class BandObject : UserControl, IObjectWithSite, IDeskBand, IDockingWindow, IOleWindow { #region Static Members ... #region Instance Members ... #region Virtual Methods ... #region IObjectWithSite Interface Implementation ...
#region IOleWindow Interface Implementation ... #region IDockingWindow Interface Implementation ... #region IOLECommandTarget Interface Implementation ... #region COM Registration Methods ... }
After implementing the UserControl
object and a myriad of interfaces, the generic band object is broken down into several areas (also shown in Listing 14-1). The static members are used by objects implementing this generic base object; they define metadata such as size and title. The instance members represent sites handed to the objects when loaded into IE. The virtual methods (in this case, one) represent calls made by objects implementing this base class to register static metadata. A set of interface implementations follow, each defining functions required by the interfaces implemented by this object. Last are the COM registration methods, called during the COM registration and unregistration processes for a library implementing this base class.
The static members define a variety of metadata that can be used by either a toolbar, Vertical Explorer bar, or Horizontal Explorer bar created from this base class. The ClassId
and ProgId
are a GUID and unique string, respectively, used to access one of these objects through COM. The ObjectTitle, ObjectName
, and HelpText
are descriptors used by IE to show the object in its menu structure and through the Manage Add-Ons dialog. The InitialSize
is the initial size of the band object when first loaded; the MinSize, MaxSize
, and IntegralSize
are size constraints applied as the band object is moved and resized during its lifetime (Listing 14-2).
Example 14.2. Static Members of the BandObject Class
#region Static Members public static string ClassId; public static string ProgId; public static string ObjectTitle; public static string ObjectName; public static string HelpText; public static new Size InitialSize; public static Size MinSize; public static Size MaxSize; public static Size IntegralSize; public static BandObjectTypes Style = BandObjectTypes.HorizontalExplorerBar; #endregion Static Members
The last static variable in Listing 14-2 is the Style variable. This member of type BandObjectStyle
is used by classes descending from BandObject
to define the type of band object that they wish to be. The enumeration shown in Listing 14-3 defines flags for a toolbar, Vertical Explorer bar, and Horizontal Explorer bar.
Example 14.3. Band Object Types Enumeration
public enum BandObjectTypes { VerticalExplorerBar = 1, Toolbar = 2, HorizontalExplorerBar = 4 }
The instance members of Listing 14-4 are used by this class to store references to the IWebBrowser
and IE application sites to which this BandObject
is related.
Example 14.4. Instance Members for the BandObject Class
#region Instance Members public SHDocVw.WebBrowserClass WebBrowser; public SHDocVw.InternetExplorer BandObjectSite; #endregion Instance Members
The DefineMetadata()
method defined in Listing 14-5 must be by a toolbar, Vertical Explorer bar, or Horizontal Explorer bar descending from BandObject
. The method is called to set metadata values onto the static variables of this class, allowing such metadata to be passed along to the base class.
Example 14.5. Required Methods for the BandObject Class
#region Virtual Methods public void DefineMetadata() { } #endregion Virtual Methods
Interface implementations are up next after the class-specific members are defined. The first major interface is IObjectWithSite
. This interface is used to get and set the "site" (COM object) where this object is loaded—the IE browser object. Listing 14-6 shows the two functions defined in this interface: SetSite(...)
and GetSite(...)
.
Example 14.6. IObjectWithSite Implementation for the BandObject Class
#region IObjectWithSite Interface Implementation public void SetSite(object pUnkSite) { // If this object is null, SetSite is being called // to handle the unload process if (!(pUnkSite is SHDocVw.InternetExplorer)) { // If the BandObjectSite is a valid object, release // the COM object being managed by the marshaller if (BandObjectSite != null) {
Marshal.ReleaseComObject(BandObjectSite); BandObjectSite = null; } return; } try { // Set the band object site to be a reference to the current // site passed to this function BandObjectSite = (SHDocVw.InternetExplorer)pUnkSite; // Grab an IServiceProvider instance from the band object site ProIeDev.BandObjectDemo.Interop.Interfaces.IServiceProvider serviceProvider = (ProIeDev.BandObjectDemo.Interop.Interfaces.IServiceProvider) BandObjectSite; // Create variables to be referenced in a call to QueryService object pUnknown = null; Guid guid = new Guid(IID.IID_IWebBrowserApp); Guid riid = new Guid(IID.IID_IUnknown); // Query the service provider for the IWebBrowser instance serviceProvider.QueryService(ref guid, ref riid, out pUnknown); // Cast the returned site to an IWebBrowser instance and save // it to an instance variable WebBrowser = (SHDocVw.WebBrowserClass)Marshal.CreateWrapperOfType( pUnknown as IWebBrowser, typeof(SHDocVw.WebBrowserClass)); // Create variables to be used in a call to the ShowBrowserBar // function on the new IWebBrowser instance object pvaClsid = (object)ClassId; object pvarSize = null; object pvarShowTrue = (object)true; // Call the ShowBrowserBar function on the retrieved IWebBrowser // instance to display the current band object WebBrowser.ShowBrowserBar(ref pvaClsid, ref pvarShowTrue, ref pvarSize); } catch (Exception) { } } public void GetSite(ref Guid riid, out object ppvSite) { // Return the current band object site ppvSite = BandObjectSite; } #endregion IObjectWithSite Interface Implementation
The SetSite
function is called to pass the IUnknown
pointer of the IE site to a class descending from the BandObject
class. IE calls SetSite
whenever loading a band object into its process. GetSite
simply returns this site if called to do so.
The next major interface is IDeskBand
. This interface is used to obtain information about a band object that is to be loaded into the Windows shell or, in this case, IE. There is only one function in this interface: GetBandInfo
. This function, shown in Listing 14-7, is called by IE to get information about this band object instance. This class implements the function in a way that sets the title, size, and other metadata to the DESKBAND
structure (the object used for information exchange in this instance) and passes that structure back to the caller.
Example 14.7. IDeskBand Implementation for the BandObject Class
#region IDeskBand Interface Implementation public void GetBandInfo(uint dwBandID, uint dwViewMode, ref DESKBANDINFO pdbi) { try { // Specify title for the DeskBand object if requested if ((pdbi.dwMask & DBIM.TITLE) == DBIM.TITLE) pdbi.wszTitle = ObjectTitle; // Specify width and height to the object if ((pdbi.dwMask & DBIM.ACTUAL) == DBIM.ACTUAL) { pdbi.ptActual.X = InitialSize.Width; pdbi.ptActual.Y = InitialSize.Height; } // Indicate maximum width and height for the object if ((pdbi.dwMask & DBIM.MAXSIZE) == DBIM.MAXSIZE) { pdbi.ptMaxSize.X = MaxSize.Width; pdbi.ptMaxSize.Y = MaxSize.Height; } // Indicate minimum width and height for the object if ((pdbi.dwMask & DBIM.MINSIZE) == DBIM.MINSIZE) { pdbi.ptMinSize.X = MinSize.Width; pdbi.ptMinSize.Y = MinSize.Height; } // Indicate integral width and height for the object; integral height // is the step value used when the object is resized (for instance, // an X value of 5 will ensure that the object will be resized in // increments of 5 pixels at a time (rather than the default of 1) if ((pdbi.dwMask & DBIM.INTEGRAL) == DBIM.INTEGRAL) { pdbi.ptIntegral.X = IntegralSize.Width; pdbi.ptIntegral.Y = IntegralSize.Height; }
// Add a backcolor by removing the mask flag // if a specific backcolor is defined if ((pdbi.dwMask & DBIM.BKCOLOR) == DBIM.BKCOLOR) pdbi.dwMask &= ~DBIM.BKCOLOR; // Apply object mode flags to the toolbar // Apply general mode flags if ((pdbi.dwMask & DBIM.MODEFLAGS) == DBIM.MODEFLAGS) { pdbi.dwModeFlags = DBIMF.VARIABLEHEIGHT | DBIMF.NORMAL; if (Style == BandObjectTypes.Toolbar) pdbi.dwModeFlags |= DBIMF.BREAK | DBIMF.ALWAYSGRIPPER; } } catch (Exception) { } } #endregion IDeskBand Interface Implementation
The IOleWindow
interface allows this class to handle OLE window calls made by an owner COM object. The BandObject
class uses only one of these for all practical purposes. The GetWindow
function is called by an owner object in order to retrieve the main window handle of an OLE site. In this case, the BandObject
class returns the window handle to the UserControl instance, and IE in turn takes ownership of this window and places it within itself as a child object (Listing 14-8).
Example 14.8. IOleWindow Implementation for the BandObject Class
#region IOleWindow Interface Implementation public void GetWindow(out IntPtr phwnd) { // Return the current window handle phwnd = Handle; } public void ContextSensitiveHelp(bool fEnterMode) { // Perform no action and return return; } #endregion IOleWindow Interface Implementation
This class also implements the ContextSensitiveHelp()
function. It does not provide any useful functionality for this example, so it is not used. For developers looking to use it, the function helps to determine whether context-sensitive help mode should be entered during an in-place activation session.
The BandObject
class's user interface (an implementation of the .NET UserControl
) is placed and docked to the IE site. In order to react to window placement and docking changes, this class implements the IDockingWindow
interface. This interface defines a number of functions that are called by the owner when important docking window events occur. Listing 14-9 defines the implementation of the IDockingWindow
interface.
Example 14.9. IDockingWindow Implementation for the BandObject Class
#region IDockingWindow Interface Implementation public void CloseDW(uint dwReserved) { // Dispose of the current object Dispose(true); } public void ResizeBorderDW(IntPtr prcBorder, object punkToolbarSite, bool fReserved) { // Perform no action and return return; } public void ShowDW(bool bShow) { // If bShow is true, show the user control; otherwise hide it if (bShow) Show(); else Hide(); } #endregion IDockingWindow Interface Implementation
The CloseDW
function is used to notify the docking window that it is about to be closed. For many applications, this call can be used as an opportunity to persist information before an exit. This function is used here to dispose of the managed object in a proper way. The ResizeBorderDW
function notifies a docking window that a resize event had occurred; the BandObject
class does not perform any special action in this implementation. The final function is ShowDW
. This is used to notify the docking window of the visibility state, telling it whether it should be shown. In this case, the BandObject
class shows or hides itself based on the Boolean state value passed into the function.
With the base class building off the UserControl
object and implementing the base interfaces for creating a BandObject
, the next step is registering instances of this class with both COM and IE.
Once a band object is implemented, it must be registered with both COM and IE in order for it to be loaded into the browser. Listing 14-10 shows the COM registration methods where this takes place. When classes implementing the BandObject
class are registered or unregistered, the .NET registration process calls the Register
or Unregister
functions, respectively.
Example 14.10. COM Registration Methods for the BandObject Class
#region COM Registration Methods [ComRegisterFunction] public static void Register(Type t) { ... } [ComUnregisterFunction] public static void Unregister() { ... } #endregion COM Registration Methods
The registration process grabs metadata defined by an extension deriving from the BandObject
base class and registers it both with COM and IE. This data is retrieved by a call to the method DefineMetadata()
implemented by a superclass (Listing 14-11).
Example 14.11. Registration Function Definition for the BandObject Class
[ComRegisterFunction] public static void Register(Type t) { // Call the define metadata function for the class instance // implementing this base class ((BandObject)Activator.CreateInstance(t)).DefineMetadata(); try { // Open the HKEY_CLASSES_ROOTCLSID key and create the subkey // for the extension's GUID RegistryKey classIdKey = Registry.ClassesRoot.CreateSubKey(@"CLSID" + ClassId); { // Set the default value to be the object name classIdKey.SetValue(String.Empty, ObjectName); // Set the menu text to be the object name classIdKey.SetValue("MenuText", ObjectName); // Set the help text to the help text value classIdKey.SetValue("HelpText", HelpText); ...
Once the required information about the extension is loaded, a number of registry entries are written to the HKEY_CLASSES_ROOT
(for COM registration) and the IE key in either HKEY_LOCAL_MACHINE
or HKEY_CURRENT_USER
(for IE registration).
Listing 14-12 shows the common data written to HKEY_CLASSES_ROOT
to register this extension with COM. Toolbars, Vertical Explorer bars, and Horizontal Explorer bars are registered in the same way, with the exception of additional component categories for Explorer bar objects. A sample registry entry can be found in Listing 14-12.
Example 14.12. Sample COM Registration Registry Values for a Band Object
HKEY_CLASSES_ROOT CLSID {0A7D6D96-7822-4389-B07E-494E5E25A83A} (Default) = "TodoBar" (REG_SZ) HelpText = "Example Toolbar for IE" (REG_SZ) MenuText = "TodoBar" (REG_SZ) Implemented Categories {62C8FE65-4EBB-45e7-B440-6E39B2CDBF29} InprocServer32 (Default) = "mscoree.dll" (REG_SZ) Assembly = "Toolbar, Version=1.0.0.0..." (REG_SZ) Class = "ProIeDev.BandObjectDemo.Toolbar.Toolbar" (REG_SZ) CodeBase = "file:///..." (REG_SZ) RuntimeVersion = "v2.0.50727" (REG_SZ) ThreadingModel = "Apartment" (REG_SZ) 1.0.0.0 Assembly = "Toolbar, Version=1.0.0.0..." (REG_SZ) Class = "ProIeDev.BandObjectDemo.Toolbar.Toolbar" (REG_SZ) CodeBase = "file:///..." (REG_SZ) RuntimeVersion = "v2.0.50727" (REG_SZ) Instance CLSID = "{E31EAE3B-65E1-4D56-A3D0-9E653D978A9A}" (REG_SZ) InitPropertyBag Url = "" (REG_SZ) ProgId (Default) = "ProIeDev.BandObjectDemo.Toolbar" (REG_SZ)
The GUID for the extension is added as a key under HKEY_CLASSES_ROOTCLSID
. The name, Help menu text, and extension menu item text are added as string values in this key. The Implemented Categories
key is created next. This key tells Windows what type of object this is; all band objects register as implementing a common category, and vertical and Horizontal Explorer bars register as implementing an additional one. The InprocServer32
key contains a variety of data about the extension (e.g., control, entry point, threading style, required libraries, etc.). The Instance
key defines initial properties of the instance (in this case, there are none provided). Last, the ProgId
key defines the ProgId
for this extension (used for access by other COM objects).
Toolbars must register themselves with IE in order for them to load inside the browser and expose themselves to users. Listing 14-13 shows an example registration of a toolbar. These values can only be placed in the HKEY_LOCAL_MACHINE
hive, and are surfaced as string values in the SoftwareMicrosoftInternet ExplorerToolbar
subkey. Toolbars are listed as string values whose data is the name of the extension.
Example 14.13. Sample IE Registry Values for a Toolbar Band Object
HKEY_LOCAL_MACHINE Software Microsoft Internet Explorer Toolbar {0A7D6D96-7822-4389-B07E-494E5E25A83A} = "TodoBar" (REG_SZ)
Explorer bars must be exposed to IE through a listing in the IE Explorer Bar registry key. Values may be placed in either HKEY_LOCAL_MACHINE
or HKEY_CURRENT_USER
, and individual extensions are defined as keys whose name is the GUID of the extension in question. Keys are placed under the subkey SoftwareMicrosoftInternet ExplorerExplorer Bars
. There is no special key or value used to differentiate between vertical and Horizontal Explorer bars; this is done through the component categories chosen during the COM registration process (Listing 14-14).
Example 14.14. Sample Registry Values for Vertical and Horizontal Explorer Bar Band Objects
HKEY_LOCAL_MACHINE or HKEY_CURRENT_USER Software Microsoft Internet Explorer Explorer Bars {FBAC3BF8-5210-4B61-879D-715396839846} BarSize = 00 00 00 00 (REG_BINARY)
Each entry can optionally contain a binary value element BarSize
. This value indicates to IE the default width (for Vertical Explorer bars) or height (for Horizontal Explorer bars) that should be used when showing the Explorer bar for the first time. This value is used to persist the user's custom width or height setting for an Explorer bar.
The Unregister
function is used to remove the registry entries created by the Register
function. Listing 14-15 shows the contents. The key representing the CLSID subkey of HKEY_CLASSES_ROOT
is opened, and the key associated with the extension's GUID is deleted.
Example 14.15. Unregistration Function Definition for the BandObject Class
[ComUnregisterFunction] public static void Unregister() { try { // Access the CLSID key in the registry RegistryKey clsidKey = Registry.ClassesRoot.OpenSubKey("CLSID", true); { // Delete the subkey containing the ClassID if possible clsidKey.DeleteSubKey(ClassId); } } catch (Exception) { } }
This function does not bother to delete the values created in IE's registry nodes. It doesn't need to—once the COM object entry is deleted, IE no longer recognizes the extension in question as valid. It is no longer included in the browser, nor in the list of add-ons. In practice, add-ons such as these should perform a full cleanup of keys dropped into IE's registry keys. If an add-on is present within these keys but not present on the box, IE will simply waste time (oftentimes slowing down the load process) trying to find a missing add-on.
A toolbar extension can easily be created through a new .NET project containing a class whose base is the BandObject
library defined in the last sections. The first step is to define a class that implements BandObject
and implements the virtual DefineMetadata()
function declared in the base class. Listing 14-16 shows such a class with three main parts: a constructor, a definition of DefineMetadata()
, and .NET form designer methods used to create the UI for this object.
Example 14.16. Basic Architecture for a Toolbar Using the BandObject Base Class
[ComVisible(true)] public class Toolbar : BandObject.BandObject { public Toolbar() ... public override void DefineMetadata() ... #region Form Designer ... }
The metadata for this toolbar first outlines the ClassId
and the ProgId
identifying the extension (Listing 14-17). Following this is the name and title of the extension, TodoBar
, and the initial size and size constraints for the toolbar. The last item of metadata is an indication of the extension type of BandObjectTypes.Toolbar
; this tells the base class to register the band object as a toolbar.
Example 14.17. Metadata for This Extension Defined Using the DefineMetadata() Function
public override void DefineMetadata() { ClassId = "{0A7D6D96-7822-4389-B07E-494E5E25A83A}"; ProgId = "ProIeDev.BandObjectDemo.Toolbar"; ObjectName = "TodoBar"; ObjectTitle = "TodoBar"; HelpText = "Example Toolbar for IE."; InitialSize = new System.Drawing.Size(500, 30); IntegralSize = new System.Drawing.Size(0, 0); MinSize = new System.Drawing.Size(500, 30); MaxSize = new System.Drawing.Size(500, 500); Style = BandObjectTypes.Toolbar; }
The last step is to place UI elements into the user control. Listing 14-18 shows a button, label, and text box added to this UI and drawn to the control instance during the initialization process.
Example 14.18. Form Designer for This Extension Creating the UI for the Toolbar
#region Form Designer private System.Windows.Forms.Label TodoLabel; private System.Windows.Forms.Button GoButton; private System.Windows.Forms.TextBox TodoTextBox; private void InitializeComponent() { this.TodoLabel = new System.Windows.Forms.Label(); this.TodoTextBox = new System.Windows.Forms.TextBox(); this.GoButton = new System.Windows.Forms.Button(); this.SuspendLayout(); ...
Registration of this control adds this extension to the Windows registry as a new COM object. Listing 14-19 shows the registration values for this new object.
Example 14.19. COM Registration Registry Data for This Extension
HKEY_CLASSES_ROOT CLSID {0A7D6D96-7822-4389-B07E-494E5E25A83A} (Default) = "TodoBar" (REG_SZ) HelpText = "Example Toolbar for IE" (REG_SZ) MenuText = "TodoBar" (REG_SZ) Implemented Categories {62C8FE65-4EBB-45e7-B440-6E39B2CDBF29} InprocServer32 (Default) = "mscoree.dll" (REG_SZ) Assembly = "Toolbar, Version=1.0.0.0..." (REG_SZ) Class = "ProIeDev.BandObjectDemo.Toolbar.Toolbar" (REG_SZ) CodeBase = "file:///..." (REG_SZ) RuntimeVersion = "v2.0.50727" (REG_SZ) ThreadingModel = "Apartment" (REG_SZ) 1.0.0.0 Assembly = "Toolbar, Version=1.0.0.0..." (REG_SZ) Class = "ProIeDev.BandObjectDemo.Toolbar.Toolbar" (REG_SZ) CodeBase = "file:///..." (REG_SZ) RuntimeVersion = "v2.0.50727" (REG_SZ) Instance CLSID = "{E31EAE3B-65E1-4D56-A3D0-9E653D978A9A}" (REG_SZ) InitPropertyBag Url = "" (REG_SZ) ProgId (Default) = "ProIeDev.BandObjectDemo.Toolbar" (REG_SZ)
The extension is also registered with IE. Listing 14-20 shows the registry values added to the HKEY_LOCAL_MACHINESoftwareMicrosoftInternet ExplorerToolbar
node. Once added, IE can open, load, and display the toolbar.
Example 14.20. Toolbar Registration in the IE Toolbar Registry Key
HKEY_LOCAL_MACHINE Software Microsoft Internet Explorer Toolbar {0A7D6D96-7822-4389-B07E-494E5E25A83A} = "TodoBar" (REG_SZ)
That's it! Figure 14-4 shows the final product of this example, loaded into IE as a new toolbar object.
A Vertical Explorer bar extension, just as a toolbar, can easily be created through a new .NET project containing a class whose base is the BandObject
library defined in the last sections. Again, the first step is to define a class that implements BandObject
and implements the virtual DefineMetadata()
function declared in the base class. Listing 14-21 shows such a class with three main parts: a constructor, a definition of DefineMetadata()
, and .NET form designer methods used to create the UI for this object.
Example 14.21. Basic Architecture for a Vertical Explorer Bar Using the BandObject Base Class
[ComVisible(true)] public class VerticalExplorerBar : BandObject.BandObject { public VerticalExplorerBar () ... public override void DefineMetadata() ... #region Form Designer ... }
The metadata for this Vertical Explorer bar first outlines the ClassId
and the ProgId
identifying the extension (Listing 14-22). Following this is the name and title of the extension, TodoBar Vertical
, and the initial size and size constrains for the object. The last item of metadata is an indication of the extension type of BandObjectTypes.VerticalExplorerBar
; this tells the base class to register the band object as a Vertical Explorer bar.
Example 14.22. Metadata for This Extension Defined Using the DefineMetadata() Function
public override void DefineMetadata() { ClassId = "{FBAC3BF8-5210-4B61-879D-715396839846}"; ProgId = "ProIeDev.BandObjectDemo.VerticalExplorerBar"; ObjectName = "TodoBar Vertical"; ObjectTitle = "TodoBar Vertical"; HelpText = "TodoBar Vertical"; Style = BandObjectTypes.VerticalExplorerBar; }
The last step is to place UI elements into the user control. Listing 14-23 shows a button, label, and text box added to this UI and drawn to the control instance during the initialization process.
Example 14.23. Form Designer for This Extension Creating the UI for the Explorer Bar
#region Form Designer private System.Windows.Forms.TextBox TodoTextbox; private System.Windows.Forms.Label TodoLabel; private System.Windows.Forms.Button GoButton; private void InitializeComponent() { this.TodoTextbox = new System.Windows.Forms.TextBox(); this.TodoLabel = new System.Windows.Forms.Label(); this.GoButton = new System.Windows.Forms.Button(); this.SuspendLayout(); ...
Registration of this control adds this extension to the Windows registry as a new COM object. Listing 14-24 shows the registration values for this new object.
Example 14.24. COM Registration Registry Data for This Extension
HKEY_CLASSES_ROOT CLSID {FBAC3BF8-5210-4B61-879D-715396839846} (Default) = "TodoBar Vertical" (REG_SZ) HelpText = "Example Vertical Explorer Bar for IE" (REG_SZ) MenuText = "TodoBar Vertical" (REG_SZ) Implemented Categories {62C8FE65-4EBB-45e7-B440-6E39B2CDBF29} {00021493-0000-0000-C000-000000000046} InprocServer32 (Default) = "mscoree.dll" (REG_SZ) Assembly = "VerticalExplorerBar, Version=1.0.0.0..." (REG_SZ) Class = "ProIeDev.BandObjectDemo. VerticalExplorerBar... " (REG_SZ) CodeBase = "file:///..." (REG_SZ)
RuntimeVersion = "v2.0.50727" (REG_SZ) ThreadingModel = "Apartment" (REG_SZ) 1.0.0.0 Assembly = "VerticalExplorerBar, Version=1.0.0.0..." (REG_SZ) Class = "ProIeDev.BandObjectDemo.VerticalExplorerBar... " (REG_SZ) CodeBase = "file:///..." (REG_SZ) RuntimeVersion = "v2.0.50727" (REG_SZ) Instance CLSID = "{E31EAE3B-65E1-4D56-A3D0-9E653D978A9A}" (REG_SZ) InitPropertyBag Url = "" (REG_SZ) ProgId (Default) = "ProIeDev.BandObjectDemo. VerticalExplorerBar" (REG_SZ)
The extension is also registered with IE. Listing 14-25 shows the registry values added to the SoftwareMicrosoftInternet ExplorerExplorer Bars
node. Once added, IE can open, load, and display the Vertical Explorer bar.
Example 14.25. Vertical Explorer Bar Registration in the IE Explorer Bars Registry Key
HKEY_LOCAL_MACHINE or HKEY_CURRENT_USER Software Microsoft Internet Explorer Explorer Bars {FBAC3BF8-5210-4B61-879D-715396839846} BarSize = 00 00 00 00 (REG_BINARY)
Figure 14-5 shows the result of this new extension project. A Vertical Explorer bar is added to the IE frame and shown on the left side of the browser frame.
A Horizontal Explorer bar extension, just as a toolbar, can easily be created through a new .NET project containing a class whose base is the BandObject
library defined in the last sections. The first step in creating this is to define a class that implements BandObject
and implements the virtual DefineMetadata()
function of the base class. Listing 14-26 shows such a class with three main parts: a constructor, a definition of DefineMetadata()
, and .NET form designer methods used to create the UI for this object.
Example 14.26. Basic Architecture for a Horizontal Explorer Bar Using the BandObject Base Class
[ComVisible(true)] public class HorizontalExplorerBar : BandObject.BandObject { public HorizontalExplorerBar () ... public override void DefineMetadata() ... #region Form Designer ... }
The metadata for this Horizontal Explorer bar first outlines the ClassId
and the ProgId
identifying the extension (Listing 14-27). Following this is the name and title of the extension, TodoBar Horizontal
, and the initial size and size constrains for the object. The last item of metadata is an indication of the extension type of BandObjectTypes.HorizontalExplorerBar
; this tells the base class to register the band object as a Horizontal Explorer bar.
Example 14.27. Metadata for This Extension Defined Using the DefineMetadata() Function
public override void DefineMetadata() { ClassId = "{B028EA5C-B226-4E4B-88C6-8842A152BC5B}"; ProgId = "ProIeDev.BandObjectDemo.HorizontalExplorerBar"; ObjectName = "TodoBar Horizontal"; ObjectTitle = "TodoBar Horizontal"; HelpText = "TodoBar Horizontal"; Style = BandObjectTypes.HorizontalExplorerBar; }
The last step is to place UI elements into the user control. Listing 14-28 shows a button, label, and text box added to this UI and drawn to the control instance during the initialization process.
Example 14.28. Form Designer for This Extension Creating the UI for the Explorer Bar
#region Form Designer private System.Windows.Forms.Label TodoLabel; private System.Windows.Forms.TextBox TodoTextbox; private System.Windows.Forms.Button GoButton;
private void InitializeComponent() { this.GoButton = new System.Windows.Forms.Button(); this.TodoLabel = new System.Windows.Forms.Label(); this.TodoTextbox = new System.Windows.Forms.TextBox(); this.SuspendLayout(); ...
Registration of this control adds this extension to the Windows registry as a new COM object. Listing 14-29 shows the registration values for this new object.
Example 14.29. COM Registration Registry Data for This Extension
HKEY_CLASSES_ROOT CLSID {B028EA5C-B226-4E4B-88C6-8842A152BC5B} (Default) = "TodoBar Horizontal" (REG_SZ) HelpText = "Example Horizontal Explorer Bar for IE" (REG_SZ) MenuText = "TodoBar Horizontal" (REG_SZ) Implemented Categories {62C8FE65-4EBB-45e7-B440-6E39B2CDBF29} {00021493-0000-0000-C000-000000000046} InprocServer32 (Default) = "mscoree.dll" (REG_SZ) Assembly = "HorizontalExplorerBar, Version=1.0.0.0..." (REG_SZ) Class = "ProIeDev.BandObjectDemo.HorizontalExplorerBar... " (REG_SZ) CodeBase = "file:///..." (REG_SZ) RuntimeVersion = "v2.0.50727" (REG_SZ) ThreadingModel = "Apartment" (REG_SZ) 1.0.0.0 Assembly = "HorizontalExplorerBar, Version=1.0.0.0..." (REG_SZ) Class = "ProIeDev.BandObjectDemo.HorizontalExplorer... " (REG_SZ) CodeBase = "file:///..." (REG_SZ) RuntimeVersion = "v2.0.50727" (REG_SZ) Instance CLSID = "{E31EAE3B-65E1-4D56-A3D0-9E653D978A9A}" (REG_SZ) InitPropertyBag Url = "" (REG_SZ) ProgId (Default) = "ProIeDev.BandObjectDemo.HorizontalExplorerBar" (REG_SZ)
The extension is also registered with IE. Listing 14-30 shows the registry values added to the SoftwareMicrosoftInternet ExplorerExplorer Bars
node. Once added, IE can open, load, and display the Horizontal Explorer bar.
Example 14.30. Horizontal Explorer Bar Registration in the IE Explorer Bars Registry Key
HKEY_LOCAL_MACHINE or HKEY_CURRENT_USER Software Microsoft Internet Explorer Explorer Bars {B028EA5C-B226-4E4B-88C6-8842A152BC5B} BarSize = 00 00 00 00 (REG_BINARY)
Figure 14-6 shows the result of this new extension project. A Horizontal Explorer bar is added to the IE frame and shown in the bottom of the browser frame.
This chapter presented band objects, an effective way to obtain a piece of UI real estate in the IE browser that persists across pages and browser sessions. I began the chapter explaining the origins of band objects, their basic architecture, and their management experience within the IE ecosystem. I then took this basic knowledge and created a base BandObject
library, an effective way to consolidate the similar pieces of each type of band object (toolbars, Vertical Explorer bars, and Horizontal Explorer bars). I went deep into this base class, talking about the architecture and the registration process for both COM and IE. The final pages of this chapter were used to create a real example of each band object type using this library.
18.219.236.62