Microsoft KB Archive/252610

From BetaArchive Wiki

HOWTO: Use Drop-Down Toolbar Buttons in a Shell Namespace Extension


The information in this article applies to:

  • Microsoft Win32 Application Programming Interface (API)


The view of a shell namespace extension can add items to the Windows Explorer toolbar by calling IShellBrowser::SetToolbarItems. When the Desktop Update was introduced, the capability to add drop-down toolbar items (BTNS_DROPDOWN or TBSTYLE_DROPDOWN) was also added. The problem is that Windows Explorer does not forward the TBN_DROPDOWN notifications to the view window, so there has not been any clear way for the view to respond to the drop-down button. This article describes how Windows Explorer actually does notify the view that a drop-down button has been pressed and how the view can react to it.


Windows Explorer does not forward the TBN_DROPDOWN notification directly, but it does send a WM_COMMAND message to the view. The WPARAM of this message contains the command identifier of the toolbar button, and the LPARAM contains a pointer to a private data structure. This structure contains the rectangle of the toolbar button, in screen coordinates. Generally, this is all the information that is necessary for the view to respond to the drop-down notification. The structure of this data is:

typedef struct
    HWND        hwndFrom;
    VARIANTARG  *pva;
    DWORD       dwUnused;

The hwndFrom member of this structure usually contains the window handle of the browser. However, it may instead contain the handle to a different window, so this possibility must be taken into account.

The pva member of this structure is of VT_INT_PTR type and the byref member of the VARIANT contains the rectangle of the toolbar button.

The dwUnused member of this structure is not used and should be 0.

If you want to display a pop-up menu under the drop-down toolbar button, you can use code like the following to do so:

if(VT_INT_PTR == ptbd->pva->vt)
   HMENU hMenu  = CreatePopupMenu();
      LPRECT   prc = (LPRECT)ptbd->pva->byref;
      AddYourMenuItems(hMenu); //Private function that adds the items to the popup menu.
      TrackPopupMenu(hMenu, TPM_LEFTALIGN, prc->left, prc->bottom, 0, hwndView, NULL);

Additional query words:

Keywords : kbExtension kbNameSpace kbSDKWin32 kbShellGrp kbDSupport
Issue type : kbhowto
Technology : kbAudDeveloper kbWin32sSearch kbWin32API

Last Reviewed: April 12, 2000
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.