CHotButton is a subclassed CButton that has a "hot" area on the right.
This makes it a dual purpose button, pressing the hotspot area sends the button
notification BN_HOT_CLICKED instead of BN_CLICKED. Pressing the non-hot text area sends
the normal BN_CLICKED notification. When the mouse hovers over the hot area, or when the
keyboard focus is in the hot area of the bitmap, an active bitmap is shown, else the
inactive bitmap is shown.
CHotButton has two keyboard focus areas, the left text portion and the right hot spot
portion. The arrow, tab and shift-tab keys navigate between the two CHotButton areas,
behaving like two buttons in that respect.
There are 13 internal hot images, each is shown by calling a corresponding method.
Application defined bitmaps may also be used. They must be provided as a bitmap
containing a series of image pairs of two equally sized halves, the left being the active
bitmap, the right being the inactive bitmap. For example, a series of one pair would look
The method CHotButton::SetAppBmp(UINT nBitmapID, int cx, COLORREF crMask) installs
the application defined bitmap. The parameters are: nBitmapID – the resource ID of
the bitmap, cx – the width of a single image (the active or inactive part), and crMask,
the transparency color, purple in this case being RGB(255,0,255).
The app may select which application defined pair to use via UseAppBitmap(int
iBitmap), where iBitmap is the zero based index of the image pair to use.
A Tooltip may be set for the hotspot via a call to SetTooltipText(LPCSTR
szText, BOOL bActivate = TRUE), where szText is the text to display when
"hot", and bActivate is the initial activation state. The tooltip may be
turned on/off via ActivateTooltip(BOOL bEnable = TRUE).
The hot area may be turned on/off via EnableHotSpot(BOOL bEnable = TRUE). When
disabled, the inactive bitmap always displays, the tooltip does not show, and the normal
BN_CLICKED notification is sent when pressing the button on the hotspot area. The hotspot
image area may be hidden/shown via ShowBitmap(BOOL bShow = TRUE), the button looks
like a normal button then the hotspot image is hidden.
There are several limitations to the button:
- – only the 3D frame border is supported
- – horizontal center/left/right text is supported, but vertical centering is not
- – multi-line text is not supported
- – the text does not gray out when the WS_DISABLED style is used (this is a TODO,
somebody mail me some code!)
In the downloadable source project, HotButton.cpp and HotButton.h are the source code
files, res/HotInternal.bmp is the bitmap for the button’s internal images, which should be
mapped to resource ID IDB_HOT_INTERNAL in your own project: