Click here to Skip to main content
13,899,856 members
Click here to Skip to main content
Add your own
alternative version


170 bookmarked
Posted 19 Nov 2002
Licenced CPOL

DirectUI Window as in XP system folders

Rate this:
Please Sign up or sign in to vote.
A control to show a list of possible tasks just as in XP.


Have you seen these nice little windows that come up in Windows XP when you go to special folders like the Control Panel, My Pictures etc. ? They show up a list of possible and popular tasks for the folder and/or selected items. With this "Top ten" list of things, Windows thinks you would like to do, it's much faster for a beginner than searching for the right command in the toolbar or menu. I thought that this user help would also fit in my own applications, so I wrote this class to simulate this new control.


It's not to hard to write your own control with this behavior. But as I tried to do this I found out that Windows uses a lot of different colors (here: different kinds of blue) - and I'm quite unsure how to get these colors without depending on the theme-thing. So I tried to get almost the same colors, no matter if the way was right. Be sure that there will be theme support in the near future.

As this does not seem to be an official control there's no wording for this. So I used the Spy++ to see the class names decided to name it DirectUI and call the boxes as "groups" and the clickable items as simply "item".

Using the code

This class can now use Themes as a new style. If you'd like to activate them just include a #define USE_THEMES in your StdAfx.h. Otherwise the self-made XP-style will be used.

Add the two files to your project and make sure to have a CMemDC class in your project, or use the one provided in the sample. Insert the window CWndDirectUI anywhere you want, just like a normal control. Before compiling make sure that you have a hand cursor named IDC_MYHAND in your resource.

By default the control is drawn using the style "Themed" (see screenshot above). You can change the style manually any time by simply calling SetStyle() using CWndDirectUI::styleOffice, CWndDirectUI::styleXPclassic, CWndDirectUI::styleXP or CWndDirectUI::styleThemed. For retrieving the current style use GetStyle(). Please be carefull when switching to the office style after the user was able to use the control, as in this style there's no expand/collapse button, so previously collapsed groups can't be expanded by the user withg this style.

For manual expand/collapse use the functions ExpandGroup(groupNr, expand).

To fill the control the best way is to use the function InitFromMenu(UINT id). Pass a menu id containing a 2D menu (no further submenus). It will automatically create the groups from the first level and add the submenu items below. If you'd like you can insert toolbar icons using SetToolbarImages(UINT uiToolbar) by simply passing a toolbar id. Please insert all items into 1 toolbar, as you can use this function only with 1 toolbar at the moment. By the way: scrollbars will automatically show if there are too many items for displaying in the control.




To use images with more than 16 colors use the SetToolbarImages(uiToolbar, uiAlternateImages, nFlagColor, clBackground, nWidth) function with the following parameters:

  • uiAlternateImages: resource id of the hi-color bitmap
  • nFlagColor: See CImageList::Create() for more info. Default is ILC_COLOR8 for 256 color images
  • clBackground: Background color used for maps (default is purple)
  • nWidth: Button width (default is 16)

For manually adding groups and items please see the class definition and the functions AddGroup(),

etc. So for every action the user does simply set a new list - that's all! When the user selects an item in the list the commands come to your application like normal menu commands, so process them like you process all the other commands. Please check this site if you'd like to use it in e.g. a dockable window. There are lots of classes for this so I see no reason to re-invent the wheel again.

Using static text and edit controls

By now two new items are include with CWndUI: static text and an edit control. If you'd like to use these items you have to insert them manually to the list by using AddItemCommand(). So to add a static text and an edit control take a look at the following piece of code from the sample:

  int nGroup;
  nGroup = m_wndDirectUI.AddGroup("Test group");

  m_wndDirectUI.AddItem(nGroup, new CDirectUIItemStatic(
    _T("This is\na multiline\ntest text")));
  m_wndDirectUI.AddItem(nGroup, new CDirectUIItemEdit(
    _T("Edit this!"), &m_wndDirectUI));
  m_wndDirectUI.AddItemCommand(nGroup, "item 1", ID_NUMBER1);

These new items have caused a few changes to the existing code, so if you used this class before and created own controls based on this class please check the code. The CDirectUIItemEdit uses the popular CInPlaceEdit class created by Zafir Anjum (and modified a little for my class) - thank you for your code! In case you are interested in how to use inplace controls take a look at this class, perhaps you find some idea how to do it. As I have no screenshot on how CDirectUIItemStatic and CDirectUIItemEdit are "officially" painted I just used it the way I think it could be. If you have any detailed information please send me an image or modified code.

In case you'd like to extend the control the next step would be a combined class that holds an edit control and a button beside (like "Find" or "Go"), but that's your homework :-)

For the future... what's missing?

There are a few things not implemented in this first version, e.g.:

  • Keyboard support - only the mouse can access this control
  • Focus rect when button is down, and all the behavior that comes with handling the focus

And ... this is my first code using themes. Please tell me if I have made some mistakes!

Compatibility and Testing

The code was tested using Windows XP Home and Visual C++ 6.0 . It should run on all versions starting with Windows 98 and Visual C++ 5. I haven't tested the code too well, so please tell me if there's a bug. I'm sorry, but in the demo (only there) the resources are mixed up in English and German.

Copyright and Credits

Feel free to use this code in any application (freeware, shareware, commercial, ...) as long you keep the copyright in the code and documentation, as well as credits.

  • Thanks a lot to Keith Rule for his CMemDC class!
  • Thanks to David Yuheng Zhao for his CVisualStylesXP class.
  • Thanks to all of you who found a bug (see discussions below), you are mentioned inside the code!
  • Thanks to Zafir Anjum for his CInPlaceEdit class I used!
  • Thanks to Mathieu Dubaele for his help with the edit item.


  • July 27, 2004: Two new items added, lot of code changed
  • May 8, 2004: Now supports Themes as a new style
  • May 2, 2004: Support for hi-color icons, thanks to Dany Cantin for his code for hi-color toolbars
  • December 1, 2003: Bugfix (GDI resources), thanks to Michel Wassink and the others who helped me finding the bug.
  • March 1, 2003:
    • BugFix: When a group is collapsed you can still select an item (OnHittest)
    • BugFix: When scrolled the OnHittest returns wrong results
    • BugFix: Warning for IDC_HAND is fixed
    • Example: How to use in a dialog (select the menu item DIRECTUI_WINDOW, Show dialog for an example)
  • January 5, 2003: Scrolling, expand+collapse, new styles, minor changes. Class and files renamed for CJobWnd to CDirectUI
  • November 19, 2002: First version


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Alexander Bischofberger
Web Developer
Germany Germany
Ok, a few words about me:

I started programming on the C64 by the "trial and error" method. Years later my parents got their first PC (Atari PC4, AT 8 MHz) where I started with Turbo Pascal. The next steps led to Turbo Pascal for Windows, Visual C++ 1.52c, and finally Visual C++ 6.

I had several chances to code larger projects, e.g.
* stand-alone disc copy station software (Win 3.1) with automatic reboot, disc encryption, ...
* government-used strategic decision system
* MLM marketing tool (
* maintenance for show planning system and other TV software (

A lot of code, tipps and help came from this site for my later projects. Thanks again to all who helped me, even if they don't know it. I'm trying to share code (which is worth sharing) so others can get the help I got (and still need) for everyday problems.

Well, I think that's enough.

You may also be interested in...


Comments and Discussions

GeneralRe: Dynamic Group Items Pin
Alexander Bischofberger16-Feb-05 7:53
memberAlexander Bischofberger16-Feb-05 7:53 
GeneralRe: Dynamic Group Items Pin
Rolando Cruz16-Feb-05 14:09
memberRolando Cruz16-Feb-05 14:09 
GeneralRe: Dynamic Group Items Pin
Alexander Bischofberger17-Feb-05 7:47
memberAlexander Bischofberger17-Feb-05 7:47 
GeneralDialog Use Pin
esmithx19-Dec-03 8:27
memberesmithx19-Dec-03 8:27 
GeneralRe: Dialog Use Pin
Alexander Bischofberger10-Jan-04 9:56
memberAlexander Bischofberger10-Jan-04 9:56 
GeneralProble When i use this control with a dialog box Pin
CaptainIgloo23-Nov-03 2:50
memberCaptainIgloo23-Nov-03 2:50 
GeneralI found the resource leak! Pin
Crog18-Oct-03 7:17
memberCrog18-Oct-03 7:17 
GeneralRe: I found the resource leak! Pin
Michel Wassink19-Oct-03 20:55
memberMichel Wassink19-Oct-03 20:55 
Hi Tristan,

I think it is good fix. You can even remove
because Detach() is also executed by DeleteImageList();

However to run it safely under 98 more bugfixes are needed which I already sent to author. Time to update the source filesCool | :cool: .



Michel Wassink

We must make user friendly software. Where are friendly users?
GeneralRe: I found the resource leak! Pin
Alexander Bischofberger20-Oct-03 7:58
memberAlexander Bischofberger20-Oct-03 7:58 
GeneralQuick Fix for Assertion Failure Under VC++ 7.0 Pin
Darcy L. Watkins13-Oct-03 11:56
memberDarcy L. Watkins13-Oct-03 11:56 
GeneralA quick fix for the resource leaks Pin
Renault the Duck28-Jul-03 15:48
memberRenault the Duck28-Jul-03 15:48 
GeneralMemory Overflow Pin
DaRpH14-Jul-03 11:29
memberDaRpH14-Jul-03 11:29 
Generallittle hint Pin
ROK_RShadow16-Jun-03 0:11
memberROK_RShadow16-Jun-03 0:11 
GeneralAnother small bug Pin
Zebrex11-Jun-03 3:51
memberZebrex11-Jun-03 3:51 
Generalgreat work Pin
xp++xp10-May-03 17:32
memberxp++xp10-May-03 17:32 
GeneralHelp Needed Pin
Villly23-Apr-03 22:51
memberVillly23-Apr-03 22:51 
GeneralGreat Control Pin
Brian Shifrin11-Mar-03 13:08
memberBrian Shifrin11-Mar-03 13:08 
GeneralRe: Great Control Pin
Michel Wassink18-Apr-03 2:49
memberMichel Wassink18-Apr-03 2:49 
GeneralRecomentation. Pin
Kastellanos Nikos11-Mar-03 5:22
memberKastellanos Nikos11-Mar-03 5:22 
QuestionCrashes on Windows 98 - GDI resource bugs? Pin
Dominik Reichl8-Mar-03 8:22
memberDominik Reichl8-Mar-03 8:22 
AnswerRe: Crashes on Windows 98 - GDI resource bugs? Pin
Alexander Bischofberger9-Mar-03 23:09
memberAlexander Bischofberger9-Mar-03 23:09 
GeneralRe: Crashes on Windows 98 - GDI resource bugs? Pin
Michel Wassink11-Apr-03 8:22
memberMichel Wassink11-Apr-03 8:22 
GeneralGreat control, shame about a bug I have found :( Pin
Zebrex28-Feb-03 4:14
memberZebrex28-Feb-03 4:14 
GeneralRe: Great control, shame about a bug I have found :( Pin
Zebrex28-Feb-03 4:32
memberZebrex28-Feb-03 4:32 
GeneralRe: Great control, shame about a bug I have found :( Pin
Alexander Bischofberger28-Feb-03 10:50
memberAlexander Bischofberger28-Feb-03 10:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02 | 2.8.190306.1 | Last Updated 2 Aug 2004
Article Copyright 2002 by Alexander Bischofberger
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid