January 1998
Give Your Applications the Hot New Interface Look with Cool Menu Buttons
Paul DiLascia
Download ROPview.exe (288KB)
Paul DiLascia is the author of Windows ++: Writing Reusable Code in C++ (Addison-Wesley, 1992) and a freelance consultant and
writer-at-large. He can be reached at askpd@pobox.com
or http://pobox.com/~askpd.
|
In one of my recent columns,
I showed you how to implement the new flat-style toolbars and coolbars found in the Office 97 products, like Microsoft Outlook and Visual Studio 97 (MSJ, August 1997). At the end of the column, I made a crack that everyone would want the new menus next. Well, sure enough, many of you sent email asking how to add buttons to your menus. Naturally I was excited by the prospect of writing code that people were clamoring for.
Implementing the buttons seemed like an easy enough taskand, in the Ory, it was. Kinda sort of. It ended up over a thousand lines. Along the way I ran into so many quirks, pitfalls, and oddities that I decided the subject deserved a full article. If nothing else, it will amaze and amuse you to see how bizarre Windows® can be. Amusing, that is, if you can somehow manage to keep from going postal.
GUI Fashion Rage
In addition to coolbars, the new look incorporates menus with button bitmaps (see Figure 1). The idea is that showing the bitmap next to the command helps users learn which buttons perform which commandsthe same way menus show accelerator names to help you learn keyboard shortcuts. I'm not sure whether cool menus are cool; to me it seems like what my graphic designer friends call screen junk. But then I thought the same thing about toolbars when they first came out. (Screen junk is a highly technical termfor an example, see Figure 2.) |
|
Figure 2 Screen Junk |
Now I'm willing to bet a nickel that Microsoft will eventually incorporate cool menus into a new DLL, but for those of you who simply can't bear to be seen in anything less than up-to-the-minute GUI fashion chic, I'll show you how to implement cool menus ASAP. My cool menu manager can be installed in less time than it takes to compile your app, or in about thirty seconds if you type fast. Really.
Cruising the Cool Menu Manager
|
|
That's it. That's all there is! The toolbar need not be displayed, or even instantiated as a CToolBar object. It only has to exist in your resource file. If you have more than one toolbar, you can call LoadToolbars (note the s). |
|
I wrote LoadToolbars because it makes me weep when I see code like this: |
|
That kind of repetitive, open coding typical of SDK sample programs is one reason there are apps that take over 80MB on disk. It announces to anyone who reads your code: "I am an ignoramus."
In any case, you can see how easy CCoolMenuManager is. Just create an object and call two functions. In addition to that basic picture, CCoolMenuManager offers some extra features that I'll discuss a bit later. For example, there's a flag that lets you turn the buttons on or off: |
|
I used m_bShowButtons in my demo program ROPView (described later) to implement a View | Hide Menu Buttons command. This will be well-appreciated by grumpy hackers like me who think retro is the ultimate GUI fashion statement. (Soon, the world will catch up to my advanced tasteI predict that before the year 2005, Windows will revert to its 3.1 look.)
Inside CCoolMenuManager
|
|
PxLib is a namespace I use for helper functions like the Se to avoid name collisions.
The second trick to loading toolbars is knowing what a toolbar resource looks like in memory. This you can discover from bartool.cpp in Figure 3. |
|
The actual size of the TOOLBARDATA is variable; the items array has wItemCount items. The nth word in the array is the command ID for the nth button in the bitmap, or zero for a...
From the January 1998 issue of Microsoft Systems Journal.
|