Implementing Shell Desk Band and Internet Explorer Bars



Click here for a larger image.



Click here for a larger image.

Introduction

The Internet Explorer Bars are child windows within the main Explorer window, and Desk Band is a dockable window on the desktop/taskbar. Both can be used to display information or interact with the user. This article deals with the implementation of these Band objects.

Design

Creating an IE Bar or Desk Band requires you to implement several interfaces and a special registration procedure. To make life easier for you, I developed an ATL class, CDeskBand, which encapsulates all these boring things needed by COM and Windows Shell runtime. In addition, there is also a CShellModule class that serves to register/unregister COM objects.

New macros

BEGIN_TYPE_MAP(x)
Marks the beginning of the type map of Band ATL objects. The parameter x is an array holding _ATL_TYPEMAP_ENTRY structures that describe the objects' type.

END_TYPE_MAP()
Marks the end of the type map of Band ATL objects. When CShellModule::RegisterServer is called, it updates the system Registry for each object in the type map.

TYPE_ENTRY(clsid, type)
Enters the type of the Band object into the type map. Parameter clsid is a CLSID of the object to be entered into the map and type can be one of the following values:

  • DeskBand
  • VerticalExplorerBar
  • HorizontalExplorerBar

Using these macros is similar to the standard ATL BEGIN_OBJECT_MAP/OBJECT_ENTRY/END_OBJECT_MAP macros.

DECLARE_MENU_MAP(x)
Forward declaration of the menu map. Parameter x is the name of the map specific to one or more Band objects.

BEGIN_MENU_MAP(x)
Marks the beginning of the menu map. Parameter x is an array holding the _ATL_MENUMAP_ENTRY structures that describe menu items and must be the same as used in the previous macro.

END_MENU_MAP()
Marks the end of the menu map.

MENU_ENTRY(id,flags,item,help,verb)
Enters an item into the menu map. Parameter id should be unique within the map; for flags' parameter values you should look into the MSDN documentation for the InsertMenu function. Item parameter is a label displayed for a menu item; help parameter is a help string for an item; and verb a is language-independent command name (like open, save, ...).

MENU_ENTRY_SEPARATOR()
Enters a separator menu item into the menu map.

You should create the menu map only if you need special commands for your Band object (a typical usage may be the "Settings..." command). You can use one menu map for more Band objects.

CShellModule

class CShellModule : public CComModule

CShellModule implements a COM server module with extensions in the registration/unregistration procedure needed by Windows Shell.

HRESULT Init( _ATL_TYPEMAP_ENTRY *pdt, _ATL_OBJMAP_ENTRY *p, HINSTANCE h )
Initializes all data members. Parameter pdt is a pointer to the type map array; the other ones are the same as in the CComModule::Init method.

HRESULT RegisterServer( const CLSID *pCLSID = NULL )
Depending on the pCLSID parameter, updates the system Registry for a single class object or for all objects in the object map.

HRESULT UnregisterServer( const CLSID *pCLSID = NULL )
Depending on the pCLSID parameter, unregisters either a single class object or all objects in the object map.

CDeskBand

template < const CLSID *pclsid,const _ATL_MENUMAP_ENTRY *pMenu = NULL >
class ATL_NO_VTABLE CDeskBand : public CComObjectRootEx<CComSingleThreadModel>, IObjectWithSite, IPersistStream, IDeskBand, IContextMenu

CDeskBand implements Shell Desk Band and IE Bars objects. It provides five protected virtual methods you can override:

  • LRESULT OnCreate( LPCREATESTRUCT lpCreateStruct ) -- WM_CREATE message handler
  • LRESULT OnDestroy() -- WM_DESTROY message handler
  • LRESULT OnPaint() -- WM_PAINT message handler
  • LRESULT OnCommand( WPARAM wParam, LPARAM lParam ) -- WM_COMMAND message handler
  • LRESULT OnMsg( HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam ) -- generic message handler excluding previous messages

For your Band object, you should derive your own class from CDeskBand. Let's see the example:

DECLARE_MENU_MAP(DeskBandMenu)
extern const CLSID CLSID_SampleDeskBand;

class CSampleDeskBand : public CComCoClass<CSampleDeskBand,
                            &CLSID_SampleDeskBand>,
   public CDeskBand<&CLSID_SampleDeskBand,DeskBandMenu>
{
public:
  CSampleDeskBand();
  ~CSampleDeskBand();

  DECLARE_REGISTRY_RESOURCEID(IDR_DESKBAND)
  DECLARE_PROTECT_FINAL_CONSTRUCT()

protected:
  virtual LRESULT OnPaint();

private:
  // your data data members
};

Downloads

Download demo project
Download source


Comments

  • Opening Link in Main Browser

    Posted by maverick786us on 03/14/2011 10:29am

    I made a slight modification with your code. Instead of buttons, its using hyperlinks. But when I open those hyperlinks, it opens in its own window. How can I make it open those links in the main window? Thanks in Advance

    Reply
  • Refreshing the page

    Posted by maverick786us on 06/21/2010 02:06am

    Hi, 
    How can I refresh the page at DISPID_DOCUMENTCOMPLETE event?

    Reply
  • Error

    Posted by maverick786us on 06/15/2010 12:59am

    I downloaded the demo project and this is the error I am receiving
    
    IUnknown' not accessible because 'CDeskBand' uses 'private' to inherit from 'IObjectWithSite'

    Reply
  • Auto/Manual Load/Unload?

    Posted by TBoneX on 07/04/2006 10:00am

    Great article. I created a deskband myself (toolbar in the taskbar) which works fine. However, after installing it (e.g. via regsvr32.exe /c deskband.dll ) and rebooting, explorer wont load it automatically. The user has to right-click onto the taskbar and choose "Toolbars" and then select the toolbar in order to activate it. How can I programatically make explorer loading/unloading my deskbar and/or autoload it on startup? Any help would be greatly appreciated TBoneX

    Reply
  • Rgester the DLL

    Posted by Legacy on 08/05/2003 12:00am

    Originally posted by: Hariharan

    How can i regester the DLL,
    I tried using the regsvr32 method but the tool band dose not appear in the explorer, even in the view menu.

    Plz let me know how to regester and use the dll

    Reply
  • Compilation fails with .NET 2003

    Posted by Legacy on 05/20/2003 12:00am

    Originally posted by: Justin Howard

    Sample's compilation is failing with:
    c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\atlcom.h(2804) : error C2248: 'IUnknown' : cannot access inaccessible struct declared in class 'ATL::CComContainedObject'
    with
    [
    Base=CSampleDeskBand
    ]
    c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\Unknwn.h(110) : see declaration of 'IUnknown'

    Any ideas ayone? I can't figure out what's changed in ATL. It all looks fine to me.

    Reply
  • How do you capture events? Mouse Clicks, etc?

    Posted by Legacy on 09/24/2002 12:00am

    Originally posted by: 187

    How would you capture events {i.e.e mouse movemeent, clicks, etc? AS well how would you place controls [buttons, edit boxes, etc.] on the bar?

    Reply
  • Cool, but how can I unregister it?

    Posted by Legacy on 06/13/2002 12:00am

    Originally posted by: Alexi Jordanov

    Sorry, but I don't have much experience with COM technology. Can you explain me how can I unregister this control? I try to call _Module.Term(); and DllUnregisterServer(void); (in beggining of DllMain) but nothing happen.

    Also I think that it's a good idea to tell us how we can append our node in "Folders" vertical bar and have some control on it (popup on rigth click, drag&drop).

    Regards, Alex

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • QA teams don't have time to test everything yet they can't afford to ship buggy code. Learn how Coverity can help organizations shrink their testing cycles and reduce regression risk by focusing their manual and automated testing based on the impact of change.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds