Click here to Skip to main content
15,068,988 members
Articles / Desktop Programming / WTL
Posted 14 Sep 2005


50 bookmarked

CAppBar, a WTL implementation of AppBar

Rate me:
Please Sign up or sign in to vote.
4.82/5 (26 votes)
14 Sep 2005CPOL3 min read
A reusable WTL base class to support AppBar


There are lots of articles about docking windows, most of which are about tool windows inside an application. However, I found few articles talking about AppBar, which is a docking window for the Windows desktop. A normal AppBar will occupy certain desktop space on any of the four sides. An AppBar could also be set to auto hide, so that it will disappear when not active, and appear when the mouse cursor is moved over its edge. The Windows taskbar is an AppBar. It’s the best reference about how an AppBar should behave like.

Win32 API actually provides an API function called SHAppBarMessage to help programmers develop AppBars similar to the Windows taskbar. This single API can accomplish a lot when we need an AppBar application. Except for the SDK documents, this article is the best reference about SHAppBarMessage. We can create an AppBar following this article. A simple sample application is also provided by MSDN. However, it’s all old style SDK code which is hard to read and reuse.

I also found this article in CodeProject, which implements an AppBar. However, it is not based on SHAppBarMessage. Furthermore, the code is too complex for me.

CAppBar template class

Since there’s no available code to reuse, I decided to create my own. WTL appears to be the best architecture for reusing code for me, so I decided to accomplish a CAppBar template class for reuse in any WTL application. It should be simple enough and flexible enough like other WTL classes. And it comes with CAppBar class.

The SHAppBarMessage API plays a big roll in the CAppBar class, however, lots of other code is provided to make it a reusable and full featured class. It could be easily added to any WTL application.


  1. use CAppBar class as a base class. The derived class must also be derived from CWindowImpl directly or indirectly.
  2. use CHAIN_MSG_MAP to chain message to the CAppBar class.
  3. call InitAppBar in the OnCreate or OnInitDialog function.
  4. (optional) call DockAppBar to dock the window to any side of the screen during runtime.
  5. (optional) call SetAutoHide to change the autohide behavior during runtime.
  6. (optional) call SetKeepSize to enable keeping original window size when docking on the screen during runtime.
  7. (optional) if you want to do any specific operation when docking side is changed, override OnDockingChanged function in the ATL way.


  • The application can be docked to or detached from any side of the desktop by function calls (DockAppBar).
  • The application window can be moved by mouse dragging on any area of the window, and can be docked to or detached from desktop visually.
  • The KeepSize mode enables an application window to dock on the desktop while maintaining its original size. This mode will take effect only if AutoHide mode is also enabled.


Well, the code and sample project is attached. I hope it would be easy to use and simple to read. I also hope some day it would be part of WTL. I was using Visual Studio 2003 and WTL7.5 when writing this code. I did not test it in any other platform. I hope it would work as well. If it doesn't, send me a message. I might try to make it better.


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


About the Author

Neil Yao
China China
I'm a chinese programer living in Shanghai, currently working for a software company whose main business is to deliver computer based testing. Software simulation for computer based testing and certifications is my main responsibility in this company. Execpt for software development, I like out-door activities and photography. I am willing to make friends in China and all over the world, so contact me if you have anything in common with meSmile | :)

Comments and Discussions

GeneralMy vote of 1 Pin
suncuigang20-Nov-12 16:29
Membersuncuigang20-Nov-12 16:29 
QuestionHow to implement this with MFC? Pin
apurv14618-Jan-10 23:47
Memberapurv14618-Jan-10 23:47 
GeneralDoesn't work with CFrameWndImpl derived classes... Pin
Rob Caldecott6-Feb-09 4:47
MemberRob Caldecott6-Feb-09 4:47 
QuestionVB.NET Pin
ILESKev21-Jan-09 3:10
MemberILESKev21-Jan-09 3:10 
GeneralApp crashes... can't remove stuff Pin
Member 448331429-Oct-08 5:09
MemberMember 448331429-Oct-08 5:09 
Generaldocking in dual monitor Pin
rreynos15-Mar-07 10:48
Memberrreynos15-Mar-07 10:48 
GeneralRe: docking in dual monitor Pin
Neil Yao18-Mar-07 21:29
MemberNeil Yao18-Mar-07 21:29 
GeneralMFC version Pin
Amit220327-Dec-06 9:50
MemberAmit220327-Dec-06 9:50 
GeneralRe: MFC version Pin
apurv14619-Jan-10 23:22
Memberapurv14619-Jan-10 23:22 
GeneralGreat... Pin
HakunaMatada27-Dec-06 3:57
MemberHakunaMatada27-Dec-06 3:57 
GeneralThanks Pin
Jörgen Sigvardsson25-Sep-06 3:03
MemberJörgen Sigvardsson25-Sep-06 3:03 
Generalthank you (help) Pin
redstone_cn5-Mar-06 17:13
Memberredstone_cn5-Mar-06 17:13 
GeneralRe: thank you (help) Pin
Amit220327-Dec-06 10:04
MemberAmit220327-Dec-06 10:04 
GeneralRe: thank you (help) Pin
Amit220328-Dec-06 22:36
MemberAmit220328-Dec-06 22:36 
GeneralMuch better than my implement Pin
Yuchuan_Wang21-Sep-05 22:23
MemberYuchuan_Wang21-Sep-05 22:23 
QuestionVery nice... Pin
HumanOsc16-Sep-05 9:00
MemberHumanOsc16-Sep-05 9:00 
AnswerRe: Very nice... Pin
Neil Yao17-Sep-05 17:07
MemberNeil Yao17-Sep-05 17:07 
General"Except" or "Besides" Pin
hlszl15-Sep-05 15:52
Memberhlszl15-Sep-05 15:52 
GeneralRe: "Except" or "Besides" Pin
Neil Yao15-Sep-05 15:55
MemberNeil Yao15-Sep-05 15:55 
GeneralGreat ! You save my time !! Pin
Rodrigo Pinto Pereira de Souza15-Sep-05 8:07
MemberRodrigo Pinto Pereira de Souza15-Sep-05 8:07 
GeneralGood work Pin
Tom Gee14-Sep-05 23:00
MemberTom Gee14-Sep-05 23:00 

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.