|
|||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionRecently my new client wanted a custom button for the new consumer application that I am building for him. Oh oh, I thought; buttons are difficult, because of the many states and modes you have to handle. Even worse, ownerdraw buttons require special treatment to look right under themed XP. The button my client wanted was similar to what is displayed when you select Search... from Explorer right-click menu:
Mousing over one of these buttons produces another effect:
The same two effects occur with radio buttons that are displayed on the Search panel. Now my only question was, "How did Microsoft implement these?" Is it possible these buttons are not really ownerdraw? To investigate further, I turned to one of my favorite programming tools, HPS HwndSpy. To my relief, HPS HwndSpy showed that buttons were not ownerdraw:
Implementation DetailsNow that I was sure I could implement this button without needing to make them ownerdraw, I decided that API could be very simple; the only option was display state: bold, underlined, or bold and underlined. So XEmphasisButton has two public APIs: Emphasis GetEmphasis() { return m_eEmphasis; }
void SetEmphasis(Emphasis eEmphasis)
{
m_eEmphasis = eEmphasis;
SetEmphasisFont();
}
The choices for parameter are given by enum Emphasis
{
NONE = 0,
BOLD, // button text will be bold if GetCheck() is TRUE
UNDERLINE, // button text will be underlined if mouse over
BOLD_AND_UNDERLINE
};
Since emphasis state is limited to four cases, programming is fairly simple. In
Demo AppThe demo app allows you to try out various combinations of display attributes:
How To UseTo integrate
Next, include header file XEmphasisButton.h in appropriate project files (usually, this will be in header file for dialog class). Then replace declaration of button control with this: CXEmphasisButton m_MyButton;
(use whatever variable name already exists).
Now you are ready to start using m_MyButton.SetEmphasis(CXEmphasisButton::BOLD_AND_UNDERLINE);
(use whatever display attributes you wish).
Revision HistoryVersion 1.0 — 2006 August 15
UsageThis software is released into the public domain. You are free to use it in any way you like, except that you may not sell this source code. If you modify it or extend it, please to consider posting new code here for everyone to share. This software is provided "as is" with no expressed or implied warranty. I accept no liability for any damage or loss of business that this software may cause.
|
||||||||||||||||||||||||||