CHotButton – a “HotSpot” Button

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.

wpeF.jpg (1596 bytes)

wpe13.jpg (3756 bytes)

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.

UseXBitmap() wpeE.jpg (1016 bytes)
UseCheckBitmap() wpeD.jpg (884 bytes)
UseFolderBitmap() wpeC.jpg (1045 bytes)
UsePaperBitmap() wpeB.jpg (903 bytes)
UsePrinterBitmap() wpeA.jpg (1071 bytes)
UseRightArrowBitmap() wpe8.jpg (880 bytes)
UseLeftArrowBitmap() wpe7.jpg (829 bytes)
UseEllipseBitmap() wpe6.jpg (853 bytes)
UseBinocularBitmap() wpe2.jpg (986 bytes)
UseClockBitmap() wpe5.jpg (1085 bytes)
UseRedFlagBitmap() wpe4.jpg (904 bytes)
UseBannedBitmap() wpe3.jpg (971 bytes)

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
like this:

wpe14.jpg (2825 bytes)

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
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:
DISCARDABLE   "res\\HotInternal.bmp"


Download demo project – 73 Kb

More by Author

Must Read