Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

CAppBar, a WTL implementation of AppBar

0.00/5 (No votes)
14 Sep 2005 2  
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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here