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)
UseLEDBitmap()
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 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:
    IDB_HOT_INTERNAL    BITMAP    DISCARDABLE   "res\\HotInternal.bmp"

Downloads

Download demo project - 73 Kb


Comments

  • EnableWindow not functioning properly

    Posted by kberson on 04/03/2004 06:52am

    If you EnableWindow(FALSE) the button, the text is not being drawn correctly. The button stops working, but text is not showned greyed out.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • CentreCorp is a fully integrated and diversified property management and real estate service company, specializing in the "shopping center" segment, and is one of the premier retail service providers in North America. Company executives travel a great deal, carrying a number of traveling laptops with critical current business data, and no easy way to back up to the network outside the office. Read this case study to learn how CentreCorp implemented a suite of business continuity services that included …

Most Popular Programming Stories

More for Developers

RSS Feeds