Click here to Skip to main content
15,867,704 members
Articles / Desktop Programming / WTL
Article

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 86.4K   2.6K   50   21
A reusable WTL base class to support AppBar

Introduction

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.

Usage

  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.

Features

  • 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.

Enjoy

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.

License

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


Written By
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
suncuigang20-Nov-12 16:29 
QuestionHow to implement this with MFC? Pin
apurv14618-Jan-10 23:47
apurv14618-Jan-10 23:47 
GeneralDoesn't work with CFrameWndImpl derived classes... Pin
Rob Caldecott6-Feb-09 4:47
Rob Caldecott6-Feb-09 4:47 
QuestionVB.NET Pin
ILESKev21-Jan-09 3:10
ILESKev21-Jan-09 3:10 
GeneralApp crashes... can't remove stuff Pin
Member 448331429-Oct-08 5:09
Member 448331429-Oct-08 5:09 
I am creating an APPBAR in c++ and I can do all that just fine. I wanted to test what would happen if my application just straight up crashed without being able to unregister itself from the system list... so I just hit shift + f5 and found out what happens. My actual app bar disappears but the space that it was taken up is still taken up. I Did this several times and now on my test box all I have is maybe 200 pixels left for windows/desktop icons on a 1680x1200 dimension screen. I have tried to look for some way to access this internal list that I see referenced in the MSDN but I cannot find anything on how to do this?

How can I access this list so that I can get a handle and then send the SHAppBarMessage(ABM_REMOVE, &AppBarData); command? Thanks in advance, and code samples would be most appreciated. This is quite annoying and there should be an easy way to remove the items for instances where your application could possibly crash.
Generaldocking in dual monitor Pin
rreynos15-Mar-07 10:48
rreynos15-Mar-07 10:48 
GeneralRe: docking in dual monitor Pin
Neil Yao18-Mar-07 21:29
Neil Yao18-Mar-07 21:29 
GeneralMFC version Pin
Amit220327-Dec-06 9:50
Amit220327-Dec-06 9:50 
GeneralRe: MFC version Pin
apurv14619-Jan-10 23:22
apurv14619-Jan-10 23:22 
GeneralGreat... Pin
HakunaMatada27-Dec-06 3:57
HakunaMatada27-Dec-06 3:57 
GeneralThanks Pin
Jörgen Sigvardsson25-Sep-06 3:03
Jörgen Sigvardsson25-Sep-06 3:03 
Generalthank you (help) Pin
redstone_cn5-Mar-06 17:13
redstone_cn5-Mar-06 17:13 
GeneralRe: thank you (help) Pin
Amit220327-Dec-06 10:04
Amit220327-Dec-06 10:04 
GeneralRe: thank you (help) Pin
Amit220328-Dec-06 22:36
Amit220328-Dec-06 22:36 
GeneralMuch better than my implement Pin
Yuchuan_Wang21-Sep-05 22:23
Yuchuan_Wang21-Sep-05 22:23 
QuestionVery nice... Pin
HumanOsc16-Sep-05 9:00
HumanOsc16-Sep-05 9:00 
AnswerRe: Very nice... Pin
Neil Yao17-Sep-05 17:07
Neil Yao17-Sep-05 17:07 
General"Except" or "Besides" Pin
hlszl15-Sep-05 15:52
hlszl15-Sep-05 15:52 
GeneralRe: "Except" or "Besides" Pin
Neil Yao15-Sep-05 15:55
Neil Yao15-Sep-05 15:55 
GeneralGreat ! You save my time !! Pin
Rodrigo Pinto Pereira de Souza15-Sep-05 8:07
Rodrigo Pinto Pereira de Souza15-Sep-05 8:07 
GeneralGood work Pin
Tom Gee14-Sep-05 23:00
Tom 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.