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

CAppBar, a WTL implementation of AppBar

By , 14 Sep 2005
 

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
Member
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 | :)

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 1membersuncuigang20 Nov '12 - 16:29 
good
GeneralAbout AppBarmembername_less11 Sep '10 - 5:15 
Hi, I'm a Chinese software developer, and living in Shanghai too. I had read your article about AppBar, and it is very helpful to me. Thank you. Now I have a question to ask: Can we create own AppBar just like system AppBar(or taskBar)? and we can add application icon into the AppBar.
If you have some ideas ,please tell me. Thank you very much!
My email:ayuan20022003@126.com. Wink | ;)
QuestionHow to implement this with MFC?memberapurv14618 Jan '10 - 23:47 
Hi,
 
This is a nice solution for creating appbar.But this is been developed using ATL.
 
I am using visual studio 2005 and it's compiler does not support your code, as I tried to compile your project but it gives me errors.
 
Is it possible to create the same application in MFC?
 
Thanks in Advance
GeneralDoesn't work with CFrameWndImpl derived classes...memberRob Caldecott6 Feb '09 - 4:47 
Create a new SDI app (derived from CFrameWindowImpl) and add the call to InitAppBar on OnCreate. Make sure to CHAIN_MSG_MAP. Trying to dock the app fails - the main window doesn't actually snap into place.
 
Any ideas?
QuestionVB.NETmemberILESKev21 Jan '09 - 3:10 
Hello,
 
I have no clues how to integrate this with an application (VB.NET) or what WTL is, can anybody point me in the right direction for this. Or even buid an example in VB.NET. I have been using VB.NET for many years but am still a beginner. Any help is appreciated.
 
Thanks
Kev
GeneralApp crashes... can't remove stuffmemberMember 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 monitormemberrreynos15 Mar '07 - 10:48 
Hi,
 
I want to attach the Appbar to the top of a single
monitor in a dual-monitor computer. The AppBar has
to be always visible so AutoHide is not an option.
The weird thing is that even if I set the AppBar size
to use only one monitor, the same area of the second
monitor gets locked. Can´t find a way out of it, if
you can help I will really thanks.
 
Reynos.
 


GeneralRe: docking in dual monitormemberNeil Yao18 Mar '07 - 21:29 
Appbar works for primary monitor only on dual-monitor computer. It won't work if you try to place it in a secondary monitor.
GeneralMFC versionmemberAmit220327 Dec '06 - 9:50 
It is the best implementation (and written in the best way) of the AppBar i found on the net.
 
My question:
 
I have MFC Dialog based application.
Dialog class derived from CHTMLDialog.
 
I want to provide AppBar bahavior for this dialg Application.
 
I am not familiar with WTL.
 
1) I understand there is no way to use WTL AppBar class as is.
2) How complex is to convert this WTL to MFC?
 
Thanks,
Amit
 

GeneralRe: MFC versionmemberapurv14619 Jan '10 - 23:22 
Hi,
 
Hey amit have you got any solution for this?
 
I have created one dialogbase app in MFC and now i want to appbar behavior for that application.
 
If you got any solution for that pl let me know.
 
Thanks in advance

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

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