Added Watermark and Title Icon properties.
Titlebars in Search mode can now wrap onto more than one line.
Control can now be resized horizontally or vertically at runtime and items are wrapped correctly.
Bug fixes: font property, Title background colour properties, MSVBVM50.DLL dependency, large number of items truncated, key navigation. See the BugTrak for full details.
vbAccelerator Explorer Bar Control
Create highly customisable XP Style Explorer user interfaces on all versions of Windows
The vbAccelerator Explorer Bar control is a new control entirely written in VB which provides a user interface like the one in Windows Explorer under XP. You can use it to create handy lists of shortcuts and informational panels, or you can incorporate controls into the panels to provide flexible and configurable complex user interface panels. The code allows you to use the inbuilt XP styles when available or to draw using an emulation otherwise.
About the Demonstration
The control demonstration includes three forms which demonstrate all the aspects of using the control. The main form shows how to create an Explorer-style shortcut link bar, and demonstrates adding and removing items as well as using emulated mode and customising the colours. The Search demonstration form shows how to create an Explorer style Search interface complete with different search modes and customisation. Finally, the Media Search form demonstrates how you might use the control to create a P2P search interface.
Using the Control
The Explorer bar itself has three modes of drawing, depending on which Windows version you're using and the setting of the UseExplorerStyle flag. When the UseExplorerStyle flag is False, which is the default, the control will either draw using the current XP theme's details, or will draw using the XP Window Classic style if no theme is in effect or you're running on an earlier version of Windows. If the UseExplorerStyle is set to True then the control draws using an emulated XP theme based on the current system colours. You can also then customise the colours with your own choices for a specific appearance.
These different modes are illustrated below:
You can also decide whether each Bar in the control has its own distinct, separated box (the default), or whether all of the bars appear within the same area with no spaces between them, like the XP Explorer Search mode using the Style property.
Once the mode has been set, you can start working with the bars and items in the control. cExplorerBar objects represent groupings of items in the control. These groupings normally have a title bar and can be expanded and collapsed by the user, although this behaviour can be customised. cExplorerBarItem objects represent items within the bars of the control. Items can have one of three different styles: they can either be links, in which case they appear underlined and can be clicked by the user, captions in which case they purely display textual information or control place holders, in which case the item can hold any control.
The control has a full object model to work with the bars and items, as shown in the diagram below:
Working With Bars
Bars are controlled through the control's Bars property. This property returns a cExplorerBars collection object which allows you to manipulate the bars in the control. These methods and properties are available through the collection:
Once a bar has been added, you can manipulate the properties of the bar itself. The properties affecting a bar's appearance are listed below:
Working With Items
Items are controlled through a cExplorerBar object's Items property. This property returns a cExplorerBarItems collection object which allows you to manipulate the items in the bar using the same methods as for a bar (described earlier). The only difference is that when you add an item you can also optionally specify the icon and the style (ItemType) of the item.
Properties and methods for working with an item in a bar are as follows:
The control raises events for bar and item clicks, mouse-over highlighting and when the system colour settings change:
Limitations and Requirements
Please note the limitations and requirements for the control:
The Redraw property allows you to make changes to the content of the control without the control redrawing after each change. This can greatly speed up removing and adding items to the control since each change does not cause the control to redraw.
Implementing the Control
The control presented here has the same fundamental window structure as the Windows version of the control. However, when I commenced on this project I believed that the control was drawn using the XP Theme API. It turns out this isn't entirely the case. The Media Explorer Bar uses this API to do some of its drawing (its probably that the Search Bar does too, because this appears in both Explorer and IE). However, the bar that is shown in Explorer when neither Search or Folders mode is in effect is not drawn using this API.
Where Does Windows Keep The Graphics?
A little look at the XP Theme directory reveals why this is. It appears that Explorer's bar, whilst related to the other Explorer Bars, was a last minute hack to the theme and hence the rendering is not directly part of the XP Visual Style theme stuff. If you look at your XP themes directory (typically found at Windows\Resources\Themes\Luna) you'll see that the Luna directory has a subdirectory called Shell. This directory in turn contains three directories, each containing a DLLs for one of the theme's different colour settings (at least, this is true for the default Windows XP theme setup, if you have a custom theme then you may have something different. If this causes problems with the control then please write and tell me the problem plus how I can reproduce your setup.)
Looking at these DLLs using the Bitmap Extractor Utility shows that these are the actual source of all images displayed in the Explorer bar. This is a pain. It means that the Explorer Bar's rendering is not accessible through UxTheme.DLL calls, and so some reverse engineering is required to draw the whole thing.
The first thing you can do (if you are running XP) is to find where the relevant ShellStyle.DLL resource utility can be found. This is done by interrogating the UxTheme.DLL API for the current theme and colour set:
Private Declare Function OpenThemeData Lib "uxtheme.dll" _ (ByVal hWnd As Long, ByVal pszClassList As Long) As Long Private Declare Function CloseThemeData Lib "uxtheme.dll" _ (ByVal hTheme As Long) As Long Private Declare Function GetCurrentThemeName Lib "uxtheme.dll" ( _ ByVal pszThemeFileName As Long, _ ByVal dwMaxNameChars As Long, _ ByVal pszColorBuff As Long, _ ByVal cchMaxColorChars As Long, _ ByVal pszSizeBuff As Long, _ ByVal cchMaxSizeChars As Long _ ) As Long ... hTheme = OpenThemeData(UserControl.hWnd, StrPtr("ExplorerBar")) If Not (hTheme = 0) Then ReDim bThemeFile(0 To 260 * 2) As Byte lPtrThemeFile = VarPtr(bThemeFile(0)) ReDim bColorName(0 To 260 * 2) As Byte lPtrColorName = VarPtr(bColorName(0)) hRes = GetCurrentThemeName(lPtrThemeFile, 260, lPtrColorName, 260, 0, 0) sThemeFile = bThemeFile iPos = InStr(sThemeFile, vbNullChar) If (iPos > 1) Then sThemeFile = left(sThemeFile, iPos - 1) sColorName = bColorName iPos = InStr(sColorName, vbNullChar) If (iPos > 1) Then sColorName = left(sColorName, iPos - 1) sShellStyle = sThemeFile For iPos = Len(sThemeFile) To 1 Step -1 If (Mid(sThemeFile, iPos, 1) = "\") Then sShellStyle = left(sThemeFile, iPos) Exit For End If Next iPos sShellStyle = sShellStyle & "Shell\" & sColorName & "\shellstyle.dll" ... CloseThemeData hThem End If
Once that's done you can start loading the actual images themselves. ShellStyle itself turns out to include both 256 bit images for the title bars themselves and 32 bit images with an alpha channel for the expand and collapse button images. To ensure these are displayed correctly, the control uses the LR_CREATEDIBSECTION flag when calling LoadImage to read the images from the resource. See the Bitmap Extractor Utility and Reading Data from Local and External Resources articles for more details on how to do this.
The remainder of the code for rendering the Explorer Bar has to all be custom code, since there's no assistance from the UxTheme API to do this. Essentially this means watching what Explorer does under various theme and colour settings and best emulating what's there. This means that some of the colours do not entirely match the Explorer versions. But they are generally visually pleasing (IMHO) and you can always use the emulation mode with your own colours if you disagree. Note that under some XP themes there are some colours used in the Explorer Bar which theme with the bitmap used with the title bar: there is no API call to retreive these colours and the control can only use the system colour settings. This means that the background colours for the Silver theme look a little anaemic in emulated mode. Any suggestions as to how to repair this would be interesting.
Despite lack of co-operation from Windows and VB, this control implements an Explorer Bar which can be used on any OS to manage a series of links and/or controls in a neat graphical interface.