Click here to Skip to main content
Click here to Skip to main content

CAppBar, a WTL implementation of AppBar

By , 14 Sep 2005
Rate this:
Please Sign up or sign in to vote.

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)

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

 
GeneralGreat... PinmemberHakunaMatada27-Dec-06 3:57 
GeneralThanks PinmemberJörgen Sigvardsson25-Sep-06 3:03 
Generalthank you (help) Pinmemberredstone_cn5-Mar-06 17:13 
GeneralRe: thank you (help) PinmemberAmit220327-Dec-06 10:04 
GeneralRe: thank you (help) PinmemberAmit220328-Dec-06 22:36 
GeneralMuch better than my implement PinmemberYuchuan_Wang21-Sep-05 22:23 
QuestionVery nice... PinmemberHumanOsc16-Sep-05 9:00 
AnswerRe: Very nice... PinmemberNeil Yao17-Sep-05 17:07 
General"Except" or "Besides" Pinmemberhlszl15-Sep-05 15:52 
GeneralRe: "Except" or "Besides" PinmemberNeil Yao15-Sep-05 15:55 
GeneralGreat ! You save my time !! PinmemberRodrigo Pinho Pereira de Souza15-Sep-05 8:07 
GeneralGood work PinmemberTom Gee14-Sep-05 23:00 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140415.2 | Last Updated 15 Sep 2005
Article Copyright 2005 by Neil Yao
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid