New Features for the Statusbar in MFC
(Page 1 of 4 )
Expanding existing objects with new and better features is a way of imitating evolution in the living world. Still, the result is just as good as in nature. Gradually we create tools for our work that make life much easier. A similar process can be observed in the Statusbar of the Windows operating system. Let us see what improvements we have at hand with the appearance of the newest generation of tools. This is the second part of an eight-part series.
Previously I showed you how to handle the classic Statusbar. As with everything around us, this has also improved in the last few years. This will be a great opportunity for those who want to see and learn about the new features available. If for some reason you are not familiar with how the classic Statusbar worked I strongly advise you to read my previous article titled Status Bar in MFC.
I already mentioned that with the MFC Feature Pack launched along with Service Pack One of Visual Studio 2008, the Statusbar was improved with the addition of the following features: the capability to post images, animations, and progress bars in the Statusbar. We can also make it respond to mouse double-clicks performed within the surface of the Statusbar.
For a quick review, let me recall the example project I created last time. I added an extra pane to the Statusbar in which I displayed the current day and the clock of the local system. Today I am going to expand on this by adding an image of a clock near it.
First, we need to add a bitmap image to the resource. Go to the resource view and import the following picture into it:

Change its name in the properties section to ID_STATUS_CLOCK_ICON. Now add the following lines to the end of the OnCreate section:
CBitmap m_StatusBarClockIcon;
m_StatusBarClockIcon.LoadBitmap (ID_STATUS_CLOCK_ICON);
m_wndStatusBar.SetPaneIcon(m_wndStatusBar.CommandToIndex( ID_STATUS_TEXT), m_StatusBarClockIcon,TRUE);
For starters, we loaded the image, and then set it to the corresponding pane. The icon is appended to the left side of the pane and has no influence on the size of the text. The pane's size is extended to fit in the icon near the text's side. Once compiled and run, you can see the effect:

Adding small tooltip texts that pop up once you hover over a pane is just as easy with the SetTipText function:
m_wndStatusBar.SetTipText(
m_wndStatusBar.CommandToIndex(ID_STATUS_TEXT),
_T(" The current time"));

Next: Animation >>
More .NET Articles
More By Gabor Bernat