Creating Band Object Using ATL HTML Control ++

Environment: VC6 SP4, Windows 2000 SP2, IE55 Header files

There have been quite a few articles about Band Object already. However, when I was building my own band object, it sometimes took days just to search for the solution to a minor problem in creating a band object. Some of the articles provide the information about how to do this, but skips other steps; some show how to do this one thing, but it assumes that you know how to do all the steps prior to doing that. For this reason, I decided to put what I have done with band object together as a sample. I hope this article would be of help in saving some of you from being frustrated.

The Basics

Band objects are essentially COM objects that exist within a container. The container of a band object depends on the type to which the band object belongs. If the band object is a tool band, it will be contained by the Rebar Control that holds Internet Explorer's toolbars; if it is an Explorer Bar, it will be contained by Internet Explorer. Despite the difference between their functionalities, their basic implementations are similar. What really makes the difference is how the band object is registered, which in turn controls the type of the object and its container.

Since a band object is a COM object, it must implement IUnknown interface. In additional to IUnknown interface, all the band objects must implement IDeskBand, IObjectWithSite, and IPersistStream interfaces. A band object must also implement IInputObject interface, if it is to accept user input. To add items to the context menu, it must implement IContextMenu interface. Because band objects implement a child window, they must also implement a window procedure to handle Windows messaging. The window procedure can be implemented by using ATL message map (see sample code for more detail).

Registration

In addition to having their CLSIDs registered, the Explorer Bar and desk band objects must be registered for the appropriate component category. As previously mentioned, registering the component category determines the object type and its container. Tool bands do not have a CATID. The CATIDs for the three band objects that require them are:

Please reference to sample code for more detail (CGBand.cpp).

Frequently Asked Questions

When I am poking around CodeGuru and some other websites dedicated for developers, I often see people asking questions about band objects. Some of those questions that are frequently asked are:

  • Installed Explorer Bar not displayed in taskbar shortcut menu
  • How to automate Internet Explorer from a band object?
  • How to extract the HTML documents?
  • How to handle events fired by Internet Explorer?
  • How to solve 'window.external' problem?

The cause to the first problem is due to the Windows 2000 shell caches the available desktop band objects and only updates this cache if it senses that an installation application is run or if the cache location in the registry is not present. To solution proposed by Microsoft is to install your band object from an application that has the name Setup.exe or Install.exe. If the proposed solution is not feasible, you need to delete the following keys in Windows Registry before or after you install your band object:

HKEY_CLASSES_ROOT\\Component Categories\\{00021492-0000-
0000-C000-000000000046}\\Enum

HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Current
Version\\Explorer\\Discardable\\PostSetup\\Component
Categories\\{00021493-0000-0000-C000-000000000046}\\Enum

HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Current
Version\\Explorer\\Discardable\\PostSetup\\Component
Categories\\{00021494-0000-0000-C000-000000000046}\\Enum

I have included the solutions to other problems in the sample code. The solution to the 'window.external' problem is based on the resolution proposed in Q202009, in which Microsoft confirmed the problem to be a bug.

A Sample Implementation

In additional to demonstrating how to implement an Explorer Bar, this sample implementation also shows:

  • How to automate a Internet Explorer from a band object
  • How to extract HTML documents
  • How to handle the events fired by Internet Explorer from a band object
  • How to fix a bug that causes an error when accessing 'window.external' in an ATL DHTML control

For changing the title of the band object (Explorer Bar), look for CCGBandObj::GetBandInfo. For changing the title shown in taskbar shortcut menu, look for CGBandObj.rgs. For registration, look in CGBand::DllRegisterServer. For event handling, look in CCGBandObj::SetSite.

References

Downloads

Download demo project - 54.6 Kb
Download source - 50.1 Kb