Click here to Skip to main content
16,015,755 members
Articles / Desktop Programming / MFC

CButtonST v3.9 (MFC Flat buttons)

Rate me:
Please Sign up or sign in to vote.
4.95/5 (246 votes)
28 Mar 20039 min read 3.2M   92.9K   645   635
A fully featured owner-draw button class - it's got the lot!

Sample Image Sample Image Sample Image Sample Image

Abstract

CButtonST is a class derived from MFC CButton class.

With this class, your applications can have standard buttons or new and modern buttons with "flat" style!

Main CButtonST features are:

  • Standard CButton properties
  • Text and icon (or bitmap) on the same button
  • Only text or only icon/bitmap buttons
  • Support for any size icons (max. 256 colors)
  • Support for bitmaps
  • Support for transparent buttons (for bitmapped applications)
  • Standard or flat button style
  • Change runtime from flat to standard style
  • Buttons can have two images. One when the mouse is over the button and one when the mouse is outside (only for "flat" buttons)
  • Every color can be customized
  • Can be used via DDX_ calls
  • Can be used in DLLs
  • Can be dynamically created
  • Each button can have its own mouse pointer
  • Button is highlighted also when the window is inactive, like happens in Internet Explorer
  • Built-in support for multiline tooltips
  • Built-in basic support for menus
  • Built-in support for owner draw menus (using BCMenu class)
  • Built-in basic support for sounds
  • Can be derived to create other button styles not supplied by default
  • Full source code included!
  • UNICODE compatible
  • Cost-less implementation in existing applications

Bitmapped application

Click here to see a real-world application made using CButtonST.

How to Integrate CButtonST in Your Application

In your project, include the following files:

  • BtnST.h
  • BtnST.cpp

Starting from version 3.5, CButtonST now supports menus created using the BCMenu class.

This 3rd party class gives you the ability to show menus using the most recent visual styles as seen on the latest Microsoft products or even in Windows XP.

Latest BCMenu version can be found here.

To enable support for BCMenu, the following two lines in BtnST.h must be enabled:

C++
#define	BTNST_USE_BCMENU
#include "BCMenu.h"

Also, the following files must be included in your project:

  • BCMenu.h
  • BCMenu.cpp

Note: Please note that when BCMenu support is enabled, the parameters accepted by the SetMenu method are different!

Starting from version 3.6, CButtonST can play sounds on particular button states.

To enable support for sound, the following line in BtnST.h must be enabled:

C++
#define	BTNST_USE_SOUND

This gives access to the SetSound method.

Create a CButtonST Object Statically

With dialog editor, create a standard button called, for example, IDOK (you don't need to make it owner drawn) and create a member variable for this button:

C++
CButtonST m_btnOk;

Now attach the button to CButtonST. For dialog-based applications, in your OnInitDialog:

C++
// Call the base-class method
CDialog::OnInitDialog();

// Create the IDOK button
m_btnOk.SubclassDlgItem(IDOK, this);

Or in your DoDataExchange:

C++
// Call the base method
CDialog::DoDataExchange(pDX);

// Create the IDOK button
DDX_Control(pDX, IDOK, m_btnOk);

Create a CButtonST Object Dynamically

In your application, create a member variable for the button. Please note that this variable is a pointer:

C++
CButtonST* m_pbtnOk;

Now create the button. For dialog-based applications, in your OnInitDialog:

C++
// Call the base-class method
CDialog::OnInitDialog();

// Create the IDOK button
m_pbtnOk = new CButtonST;
m_pbtnOk->Create(_T("&Ok"), WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP, 
                CRect(10, 10, 200, 100), this, IDOK);
// Set the same font of the application
m_pbtnOk->SetFont(GetFont());

Remember to destroy the button or you will get a memory leak. This can be done, for example, in your class destructor:

C++
if (m_pbtnOk) delete m_pbtnOk;

Class Methods

SetIcon (using multi-size resources)

  • Assigns icons to the button
  • Any previous icon or bitmap will be removed
C++
// Parameters:
//     [IN]   nIconIn
//            ID number of the icon resource to show when the mouse is over the
//            button.  Pass NULL to remove any icon from the button.
//     [IN]   nCxDesiredIn
//            Specifies the width, in pixels, of the icon to load.
//     [IN]   nCyDesiredIn
//            Specifies the height, in pixels, of the icon to load.
//     [IN]   nIconOut
//            ID number of the icon resource to show when the mouse is outside 
//            the button. Can be NULL.
//            If this parameter is the special value BTNST_AUTO_GRAY (cast to int) 
//            the second icon will be automatically created starting from nIconIn 
//            and converted to grayscale.
//            If this parameter is the special value BTNST_AUTO_DARKER (cast 
//            to int) the second icon will be automatically created 25% 
//            darker starting from nIconIn.
//     [IN]   nCxDesiredOut
//            Specifies the width, in pixels, of the icon to load.
//     [IN]   nCyDesiredOut
//            Specifies the height, in pixels, of the icon to load.
//
// Return value:
//      BTNST_OK
//          Function executed successfully.
//      BTNST_INVALIDRESOURCE
//          Failed loading the specified resource.
//
DWORD SetIcon(int nIconIn, int nCxDesiredIn, int nCyDesiredIn, 
              int nIconOut = NULL, int nCxDesiredOut = 0, int nCyDesiredOut = 0)

SetIcon (using resources)

  • Assigns icons to the button
  • Any previous icon or bitmap will be removed
C++
// Parameters:
//     [IN]   nIconIn
//            ID number of the icon resource to show when the mouse is over the 
//            button.
//            Pass NULL to remove any icon from the button.
//     [IN]   nIconOut
//            ID number of the icon resource to show when the mouse is 
//            outside the button. Can be NULL.
//            If this parameter is the special value BTNST_AUTO_GRAY (cast to int) 
//            the second icon will be automatically created starting from 
//            nIconIn and converted to grayscale. If this parameter is the 
//            special value BTNST_AUTO_DARKER (cast to int) the second
//            icon will be automatically created 25% darker starting from nIconIn.
//
// Return value:
//      BTNST_OK
//          Function executed successfully.
//      BTNST_INVALIDRESOURCE
//          Failed loading the specified resource.
//
DWORD SetIcon(int nIconIn, int nIconOut = NULL)

SetIcon (using handles)

  • Assigns icons to the button
  • Any previous icon or bitmap will be removed
C++
// Parameters:
//     [IN]   hIconIn
//            Handle fo the icon to show when the mouse is over the button.
//            Pass NULL to remove any icon from the button.
//     [IN]   hIconOut
//            Handle to the icon to show when the mouse is outside the button. 
//            Can be NULL.
//            If this parameter is the special value BTNST_AUTO_GRAY the second
//            icon will be automatically created starting from hIconIn and 
//            converted to grayscale.
//            If this parameter is the special value BTNST_AUTO_DARKER the second
//            icon will be automatically created 25% darker starting from hIconIn.
//
// Return value:
//      BTNST_OK
//          Function executed successfully.
//      BTNST_INVALIDRESOURCE
//          Failed loading the specified resource.
//
DWORD SetIcon(HICON hIconIn, HICON hIconOut = NULL)

SetBitmaps (using resources)

  • Assigns bitmaps to the button
  • Any previous icon or bitmap will be removed
C++
// Parameters:
//     [IN]   nBitmapIn
//            ID number of the bitmap resource to show when the mouse is 
//            over the button.
//            Pass NULL to remove any bitmap from the button.
//     [IN]   crTransColorIn
//            Color (inside nBitmapIn) to be used as transparent color.
//     [IN]   nBitmapOut
//            ID number of the bitmap resource to show when the mouse 
//            is outside the button.
//            Can be NULL.
//     [IN]   crTransColorOut
//            Color (inside nBitmapOut) to be used as transparent color.
//
// Return value:
//     BTNST_OK
//        Function executed successfully.
//     BTNST_INVALIDRESOURCE
//        Failed loading the specified resource.
//     BTNST_FAILEDMASK
//        Failed creating mask bitmap.
//
DWORD SetBitmaps(int nBitmapIn, COLORREF crTransColorIn, 
                 int nBitmapOut = NULL, COLORREF crTransColorOut = 0)

SetBitmaps (using handles)

  • Assigns bitmaps to the button
  • Any previous icon or bitmap will be removed
C++
// Parameters:
//     [IN]   hBitmapIn
//            Handle fo the bitmap to show when the mouse is over the button.
//            Pass NULL to remove any bitmap from the button.
//     [IN]   crTransColorIn
//            Color (inside hBitmapIn) to be used as transparent color.
//     [IN]   hBitmapOut
//            Handle to the bitmap to show when the mouse is outside the button.
//            Can be NULL.
//     [IN]   crTransColorOut
//            Color (inside hBitmapOut) to be used as transparent color.
//
// Return value:
//     BTNST_OK
//        Function executed successfully.
//     BTNST_INVALIDRESOURCE
//        Failed loading the specified resource.
//     BTNST_FAILEDMASK
//        Failed creating mask bitmap.
//
DWORD SetBitmaps(HBITMAP hBitmapIn, COLORREF crTransColorIn, 
                 HBITMAP hBitmapOut = NULL, COLORREF crTransColorOut = 0)

SetFlat

  • Sets the button to have a standard or flat style
C++
// Parameters:
//     [IN]   bFlat
//            If TRUE the button will have a flat style, else
//            will have a standard style.
//            By default, CButtonST buttons are flat.
//     [IN]   bRepaint
//            If TRUE the control will be repainted.
//
// Return value:
//     BTNST_OK
//        Function executed successfully.
//
DWORD SetFlat(BOOL bFlat = TRUE, BOOL bRepaint = TRUE)

SetAlign

  • Sets the alignment type between icon/bitmap and text
C++
// Parameters:
//     [IN]   byAlign
//            Alignment type. Can be one of the following values:
//            ST_ALIGN_HORIZ          Icon/bitmap on the left, text on the right
//            ST_ALIGN_VERT           Icon/bitmap on the top, text on the bottom
//            ST_ALIGN_HORIZ_RIGHT    Icon/bitmap on the right, text on the left
//            ST_ALIGN_OVERLAP        Icon/bitmap on the same space as text
//            By default, CButtonST buttons have ST_ALIGN_HORIZ alignment.
//     [IN]   bRepaint
//            If TRUE the control will be repainted.
//
// Return value:
//     BTNST_OK
//        Function executed successfully.
//     BTNST_INVALIDALIGN
//        Alignment type not supported.
//
DWORD SetAlign(BYTE byAlign, BOOL bRepaint = TRUE)

SetPressedStyle

  • Sets the pressed style
C++
// Parameters:
//     [IN]   byStyle
//            Pressed style. Can be one of the following values:
//            BTNST_PRESSED_LEFTRIGHT     Pressed style from left to right (as usual)
//            BTNST_PRESSED_TOPBOTTOM     Pressed style from top to bottom
//            By default, CButtonST buttons have BTNST_PRESSED_LEFTRIGHT style.
//     [IN]   bRepaint
//            If TRUE the control will be repainted.
//
// Return value:
//     BTNST_OK
//        Function executed successfully.
//     BTNST_INVALIDPRESSEDSTYLE
//        Pressed style not supported.
//
DWORD SetPressedStyle(BYTE byStyle, BOOL bRepaint = TRUE)

SetCheck

  • Sets the state of the checkbox
  • If the button is not a checkbox, this function has no meaning
C++
// Parameters:
//     [IN]   nCheck
//            1 to check the checkbox.
//            0 to un-check the checkbox.
//     [IN]   bRepaint
//            If TRUE the control will be repainted.
//
// Return value:
//     BTNST_OK
//        Function executed successfully.
//
DWORD SetCheck(int nCheck, BOOL bRepaint = TRUE)

GetCheck

  • Returns the current state of the checkbox
  • If the button is not a checkbox, this function has no meaning
C++
// Return value:
//     The current state of the checkbox.
//        1 if checked.
//        0 if not checked or the button is not a checkbox.
//
int GetCheck()

SetDefaultColors

  • Sets all colors to a default value.
C++
// Parameters:
//     [IN]   bRepaint
//            If TRUE the control will be repainted.
//
// Return value:
//     BTNST_OK
//        Function executed successfully.
//
DWORD SetDefaultColors(BOOL bRepaint = TRUE)

SetColor

  • Sets the color to use for a particular state
C++
// Parameters:
//     [IN]   byColorIndex
//            Index of the color to set. Can be one of the following values:
//            BTNST_COLOR_BK_IN       Background color when mouse is over the button
//            BTNST_COLOR_FG_IN       Text color when mouse is over the button
//            BTNST_COLOR_BK_OUT      Background color when mouse is outside the button
//            BTNST_COLOR_FG_OUT      Text color when mouse is outside the button
//            BTNST_COLOR_BK_FOCUS    Background color when the button is focused
//            BTNST_COLOR_FG_FOCUS    Text color when the button is focused
//     [IN]   crColor
//            New color.
//     [IN]   bRepaint
//            If TRUE the control will be repainted.
//
// Return value:
//     BTNST_OK
//        Function executed successfully.
//     BTNST_INVALIDINDEX
//        Invalid color index.
//
DWORD SetColor(BYTE byColorIndex, COLORREF crColor, BOOL bRepaint = TRUE)

GetColor

  • Returns the color used for a particular state
C++
// Parameters:
//     [IN]   byColorIndex
//            Index of the color to get.
//            See SetColor for the list of available colors.
//     [OUT]  crpColor
//            A pointer to a COLORREF that will receive the color.
//
// Return value:
//     BTNST_OK
//        Function executed successfully.
//     BTNST_INVALIDINDEX
//        Invalid color index.
//
DWORD GetColor(BYTE byColorIndex, COLORREF* crpColor)

OffsetColor

  • This function applies an offset to the RGB components of the specified color.
  • This function can be seen as an easy way to make a color darker or lighter than its default value.
C++
// Parameters:
//     [IN]   byColorIndex
//            Index of the color to set.
//            See SetColor for the list of available colors.
//     [IN]   shOffsetColor
//            A short value indicating the offset to apply to the color.
//            This value must be between -255 and 255.
//     [IN]   bRepaint
//            If TRUE the control will be repainted.
//
// Return value:
//     BTNST_OK
//        Function executed successfully.
//     BTNST_INVALIDINDEX
//        Invalid color index.
//     BTNST_BADPARAM
//        The specified offset is out of range.
//
DWORD OffsetColor(BYTE byColorIndex, short shOffset, BOOL bRepaint = TRUE)

SetAlwaysTrack

  • Sets the highlight logic for the button
  • Applies only to flat buttons
C++
// Parameters:
//     [IN]   bAlwaysTrack
//            If TRUE the button will be highlighted even if the window that owns it, is
//            not the active window.
//            If FALSE the button will be highlighted only if the window that owns it,
//            is the active window.
//
// Return value:
//     BTNST_OK
//        Function executed successfully.
//
DWORD SetAlwaysTrack(BOOL bAlwaysTrack = TRUE)

SetBtnCursor

  • Sets the cursor to be used when the mouse is over the button
C++
// Parameters:
//     [IN]   nCursorId
//            ID number of the cursor resource.
//            Pass NULL to remove a previously loaded cursor.
//     [IN]   bRepaint
//            If TRUE the control will be repainted.
//
// Return value:
//     BTNST_OK
//        Function executed successfully.
//     BTNST_INVALIDRESOURCE
//        Failed loading the specified resource.
//
DWORD SetBtnCursor(int nCursorId = NULL, BOOL bRepaint = TRUE)

DrawBorder

  • Sets if the button border must be drawn
  • Applies only to flat buttons
C++
// Parameters:
//     [IN]   bDrawBorder
//            If TRUE the border will be drawn.
//     [IN]   bRepaint
//            If TRUE the control will be repainted.
//
// Return value:
//     BTNST_OK
//        Function executed successfully.
//
DWORD DrawBorder(BOOL bDrawBorder = TRUE, BOOL bRepaint = TRUE)

DrawFlatFocus

  • Sets if the focus rectangle must be drawn for flat buttons
C++
// Parameters:
//     [IN]   bDrawFlatFocus
//            If TRUE the focus rectangle will be drawn also for flat buttons.
//     [IN]   bRepaint
//            If TRUE the control will be repainted.
//
// Return value:
//     BTNST_OK
//        Function executed successfully.
//
DWORD DrawFlatFocus(BOOL bDrawFlatFocus, BOOL bRepaint = TRUE)

SetTooltipText (Using resource)

  • Sets the text to show in the button tooltip
C++
// Parameters:
//     [IN]   nText
//            ID number of the string resource containing the text to show.
//     [IN]   bActivate
//            If TRUE the tooltip will be created active.
//
void SetTooltipText(int nText, BOOL bActivate = TRUE)

SetTooltipText

  • Sets the text to show in the button tooltip
C++
// Parameters:
//     [IN]   lpszText
//            Pointer to a null-terminated string containing the text to show.
//     [IN]   bActivate
//            If TRUE the tooltip will be created active.
//
void SetTooltipText(LPCTSTR lpszText, BOOL bActivate = TRUE)

EnableBalloonTooltip

  • Enables the tooltip to be displayed using the balloon style
  • This function must be called before any call to SetTooltipText is made
C++
// Return value:
//     BTNST_OK
//        Function executed successfully.
//
DWORD EnableBalloonTooltip()

ActivateTooltip

  • Enables or disables the button tooltip
C++
// Parameters:
//     [IN]   bActivate
//            If TRUE the tooltip will be activated.
//
void ActivateTooltip(BOOL bEnable = TRUE)

GetDefault

  • Returns if the button is the default button
C++
// Return value:
//     TRUE
//        The button is the default button.
//     FALSE
//        The button is not the default button.
//
BOOL GetDefault()

DrawTransparent

  • Enables the transparent mode
  • Note: This operation is not reversible.
  • DrawTransparent should be called just after the button is created.
  • Do not use transparent buttons until you really need it (you have a bitmapped background) since each transparent button makes a copy in memory of its background.
  • This may bring unnecessary memory use and execution overload.
C++
// Parameters:
//     [IN]   bRepaint
//            If TRUE the control will be repainted.
//
void DrawTransparent(BOOL bRepaint = FALSE)

SetURL

  • Sets the URL that will be opened when the button is clicked.
C++
// Parameters:
//     [IN]   lpszURL
//            Pointer to a null-terminated string that contains the URL.
//            Pass NULL to removed any previously specified URL.
//
// Return value:
//     BTNST_OK
//        Function executed successfully.
//
DWORD SetURL(LPCTSTR lpszURL = NULL)

SetMenu

  • Associates a menu to the button
  • The menu will be displayed clicking the button
  • This method is available only if BTNST_USE_BCMENU is not defined
C++
// Parameters:
//     [IN]   nMenu
//            ID number of the menu resource.
//            Pass NULL to remove any menu from the button.
//     [IN]   hParentWnd
//            Handle to the window that owns the menu.
//            This window receives all messages from the menu.
//     [IN]   bRepaint
//            If TRUE the control will be repainted.
//
// Return value:
//     BTNST_OK
//        Function executed successfully.
//     BTNST_INVALIDRESOURCE
//        Failed loading the specified resource.
//
DWORD SetMenu(UINT nMenu, HWND hParentWnd, BOOL bRepaint = TRUE)

SetMenu

  • Associates a menu to the button
  • The menu will be displayed clicking the button.
  • This method is available only if BTNST_USE_BCMENU is defined. The menu will be handled by the BCMenu class.
C++
// Parameters:
//     [IN]   nMenu
//            ID number of the menu resource.
//            Pass NULL to remove any menu from the button.
//     [IN]   hParentWnd
//            Handle to the window that owns the menu.
//            This window receives all messages from the menu.
//     [IN]   bWinXPStyle
//            If TRUE the menu will be displayed using the new Windows XP style.
//            If FALSE the menu will be displayed using the standard style.
//     [IN]   nToolbarID
//            Resource ID of the toolbar to be associated to the menu.
//     [IN]   sizeToolbarIcon
//            A CSize object indicating the size (in pixels) of each icon 
//            into the toolbar.
//            All icons into the toolbar must have the same size.
//     [IN]   crToolbarBk
//            A COLORREF value indicating the color to use as background 
//            for the icons into the toolbar.
//            This color will be used as the "transparent" color.
//     [IN]   bRepaint
//            If TRUE the control will be repainted.
//
// Return value:
//     BTNST_OK
//        Function executed successfully.
//     BTNST_INVALIDRESOURCE
//        Failed loading the specified resource.
//
DWORD SetMenu(UINT nMenu,
              HWND hParentWnd,
              BOOL bWinXPStyle = TRUE,
              UINT nToolbarID = NULL,
              CSize sizeToolbarIcon = CSize(16, 16),
              COLORREF crToolbarBk = RGB(255, 0, 255),
              BOOL bRepaint = TRUE)

SetMenuCallback

  • Sets the callback message that will be sent to the specified window just before the menu associated to the button is displayed
C++
// Parameters:
//     [IN]   hWnd
//            Handle of the window that will receive the callback message.
//            Pass NULL to remove any previously specified callback message.
//     [IN]   nMessage
//            Callback message to send to window.
//     [IN]   lParam
//            A 32 bits user specified value that will be passed to the 
//            callback function.
//
// Remarks:
//     the callback function must be in the form:
//     LRESULT On_MenuCallback(WPARAM wParam, LPARAM lParam)
//     Where:
//            [IN]     wParam
//                     If support for BCMenu is enabled: a pointer to BCMenu
//                     else a HMENU handle to the menu that is being to be 
//                      displayed.
//            [IN]     lParam
//                     The 32 bits user specified value.
//
// Return value:
//     BTNST_OK
//        Function executed successfully.
//
DWORD SetMenuCallback(HWND hWnd, UINT nMessage, LPARAM lParam = 0)

SizeToContent

  • Resizes the button to the same size of the image
  • To get good results, both the IN and OUT images should have the same size
C++
void SizeToContent()

SetSound

  • Sets the sound that must be played on particular button states
  • This method is available only if BTNST_USE_SOUND is defined
C++
// Parameters:
//     [IN]   lpszSound
//            A string that specifies the sound to play.
//            If hMod is NULL this string is interpreted as a filename, 
//            else it is interpreted as a resource identifier.
//            Pass NULL to remove any previously specified sound.
//     [IN]   hMod
//            Handle to the executable file that contains the resource to 
//            be loaded.
//            This parameter must be NULL unless lpszSound specifies a 
//            resource identifier.
//     [IN]   bPlayOnClick
//            TRUE if the sound must be played when the button is clicked.
//            FALSE if the sound must be played when the mouse is moved over 
//            the button.
//     [IN]   bPlayAsync
//            TRUE if the sound must be played asynchronously.
//            FALSE if the sound must be played synchronously. The 
//            application takes control after the sound is completely played.
//
// Return value:
//     BTNST_OK
//        Function executed successfully.
//
DWORD SetSound(LPCTSTR lpszSound, 
               HMODULE hMod = NULL, 
               BOOL bPlayOnClick = FALSE, 
               BOOL bPlayAsync = TRUE)

OnDrawBackground

  • This function is called every time the button background needs to be painted.
  • If the button is in transparent mode, this function will NOT be called.
  • This is a virtual function that can be rewritten in CButtonST-derived classes to produce a whole range of buttons not available by default.
C++
// Parameters:
//     [IN]   pDC
//            Pointer to a CDC object that indicates the device context.
//     [IN]   pRect
//            Pointer to a CRect object that indicates the bounds of the
//            area to be painted.
//
// Return value:
//     BTNST_OK
//        Function executed successfully.
//
virtual DWORD OnDrawBackground(CDC* pDC, CRect* pRect)

OnDrawBorder

  • This function is called every time the button border needs to be painted.
  • This is a virtual function that can be rewritten in CButtonST-derived classes to produce a whole range of buttons not available by default.
C++
// Parameters:
//     [IN]   pDC
//            Pointer to a CDC object that indicates the device context.
//     [IN]   pRect
//            Pointer to a CRect object that indicates the bounds of the
//            area to be painted.
//
// Return value:
//     BTNST_OK
//        Function executed successfully.
//
virtual DWORD OnDrawBorder(CDC* pDC, CRect* pRect)

GetVersionI

  • Returns the class version as a short value.
C++
// Return value:
//     Class version. Divide by 10 to get actual version.
//
static short GetVersionI()

GetVersionC

Returns the class version as a string value.

C++
// Return value:
//     Pointer to a null-terminated string containing the class version.
//
static LPCTSTR GetVersionC()

History

  • v3.9 (03/March/2003)
    • Added support for Windows XP icons
    • Added support for multi-size icons
    • Added BTNST_AUTO_DARKER as a special value for second icon
    • Fixed the grayscale icon bug under Win9x/Me
    • Class is now independent from TTS_BALLOON
  • v3.8 (25/November/2002)
    • Added support for balloon tooltips
    • Added EnableBalloonTooltip method
    • OnDrawBorder virtual method is now called also for non-flat buttons
    • OnDrawBackground and OnDrawBorder now receive a correct CRect* parameter
    • Fixed a little color bug
    • Correctly works under MFC 7.0
  • v3.7 (22/July/2002)
    • Added SetPressedStyle method
    • Added BTNST_INVALIDPRESSEDSTYLE return value
    • Added ST_ALIGN_OVERLAP align style
  • v3.6 (09/July/2002)
    • Added SetMenuCallback method to give the ability to modify the associated menu just before is it displayed
    • Added basic support for sounds
    • Added SetSound method
    • Added ResizeToContent method
  • v3.5 (18/April/2002)
    • Second icon can be automatically created in grayscale
    • Added BTNST_AUTO_GRAY as a special value for second icon
    • Bitmap is draw disabled if the button is disabled
    • Added support for owner draw menus (using BCMenu class)
    • Added an overloaded SetMenu method to support BCMenu class
    • Added OffsetColor method
    • Added support for DDX_Check calls
  • v3.4 (17/October/2001)
    • Added basic support for menus
    • Added SetMenu method
  • v3.3 (20/September/2001)
    • Default button is now handled correctly
    • Removed some rarely used methods
    • Other optimizations
  • v3.2 (14/June/2001)
    • Added support for bitmaps
    • Added SetBitmaps methods
  • v2.6
    • Added an overloaded version of the SetIcon method
    • Added ST_ALIGN_HORIZ_RIGHT flag to SetAlign function
    • Fixed a bug when used in MFC extension DLLs
    • Improved code for transparent buttons
  • v2.5
    • Support for 16x16 32x32 and 48x48 icons
    • Buttons can be dynamically created
    • Added support for transparent buttons
    • Auto-detect default button (useful only for standard buttons)
    • Auto-detect icon's dimension
    • Added DrawTransparent method
    • Added GetDefault method
    • Modified SetIcon method
  • v2.4
    • Added support for tooltips
    • Added SetTooltipText, ActivateTooltip members
    • The "Double-click bug" should be fixed
  • v2.3
    • The class should now work from within a DLL
    • The "Spacebar-Bug" should be fixed
    • Added RedrawWindow() as the last line of SetIcon member
    • The focus rectangle is now the last thing drawn
    • The focus rectangle can now be drawn also for "flat" buttons
    • Added SetFlatFocus, GetFlatFocus members
    • Added SetBtnCursor member
    • Flat buttons can now work like in Internet Explorer
  • v2.2
    • Removed SubclassDlgItem member (this is transparent for the user)
    • Added PreSubclassWindow member (this allows DDX_ calls)
    • Added SetDefaultActiveFgColor, SetActiveFgColor, GetActiveFgColor members
    • Added SetDefaultActiveBgColor, SetActiveBgColor, GetActiveBgColor members
    • Added SetDefaultInactiveFgColor, SetInactiveFgColor, GetInactiveFgColor members
    • Added SetDefaultInactiveBgColor, SetInactiveBgColor, GetInactiveBgColor members
    • When the mouse is over a button, the focus now remains to the control that owns it!
    • The flat buttons now work properly also in windows not derived from CDialog!
    • A memory DC (CMemDC) is used to draw the button. This should speed up the graphic operations.
  • v2.1
    • Support for two icons
    • Modified SetIcon member
    • Added SetShowText/GetShowText members
    • Fixed a bug dealing with the left mouse button
    • Little optimizations
  • v2.0
    • Changed the class name for name convention
    • Support for 256 colors icons
    • Removed a stupid memory leak!
    • Removed support for CImagelists
    • Documentation in HTML format
  • ST_CButton v1.1
    • Some minor changes
  • ST_CButton v1.0
    • First release

Remarks

The demo application shows nearly all the features of the CButtonST class.

CButtonST architecture makes it possible to produce a whole range of buttons not available by default. If someone implements new button styles, I will be happy to include his code in the next CButtonST demo application.

Thanks

Thanks very much to the dozens of users that are using CButtonST in their applications.

Thanks also to all the people that find and fix bugs. Thanks!

If possible, please send a screenshot of your application where CButtonST is used. These screenshots will be collected for personal interest.

Disclaimer

THE SOFTWARE AND THE ACCOMPANYING FILES ARE DISTRIBUTED "AS IS" AND WITHOUT ANY WARRANTIES WHETHER EXPRESSED OR IMPLIED. NO REPONSIBILITIES FOR POSSIBLE DAMAGES OR EVEN FUNCTIONALITY CAN BE TAKEN. THE USER MUST ASSUME THE ENTIRE RISK OF USING THIS SOFTWARE.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here.


Written By
Web Developer
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: Nice class thanks Pin
Davide Calabro28-Sep-00 20:53
Davide Calabro28-Sep-00 20:53 
GeneralCButtonST and PropertyPages Pin
Corneliu I. Tusnea29-Aug-00 0:40
sussCorneliu I. Tusnea29-Aug-00 0:40 
GeneralOnSysColorChange doesn't work unless ... Pin
Nicholas Blumhardt23-Aug-00 15:03
Nicholas Blumhardt23-Aug-00 15:03 
GeneralSetting button color at runtime Pin
jjjjjrrrrrjjjjjjrrrrr19-May-00 9:05
jjjjjrrrrrjjjjjjrrrrr19-May-00 9:05 
QuestionHow did you get that dialog bmp background ?? Pin
shock_the_monkey16-May-00 10:53
sussshock_the_monkey16-May-00 10:53 
GeneralCrash when dialog exits Pin
Chris Kotchey10-May-00 10:56
sussChris Kotchey10-May-00 10:56 
QuestionRight click on button? Pin
Chris Davies21-Apr-00 3:07
Chris Davies21-Apr-00 3:07 
GeneralI want to know the way to display tooltip ...... Pin
Member 240716-Apr-00 16:07
Member 240716-Apr-00 16:07 
thanks for your great class..
It works wonderful. but I want to know the way to display
tooltip in button when dialog lose focus.

by
GeneralYour class is great, but... Pin
Member 240713-Apr-00 22:44
Member 240713-Apr-00 22:44 
GeneralRe: Your class is great, but... Pin
Davide Calabro14-Apr-00 1:40
Davide Calabro14-Apr-00 1:40 
GeneralMultiline text and disable state. Pin
Member 31244-Apr-00 9:16
Member 31244-Apr-00 9:16 
GeneralRe: Multiline text and disable state. Pin
25-May-01 4:59
suss25-May-01 4:59 
GeneralUsing in FormView application Pin
Sadhu24-Feb-00 8:07
Sadhu24-Feb-00 8:07 
GeneralRe: Using in FormView application Pin
12-Mar-01 21:42
suss12-Mar-01 21:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.