Click here to Skip to main content
Click here to Skip to main content

CButtonST v3.9 (MFC Flat buttons)

By , 28 Mar 2003
 

Sample Image Sample Image Sample Image Sample Image

SoftechSoftware homepage
SoftechSoftware Email

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 dinamically created
  • Each button can have its own mouse pointer
  • Button is hilighted 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:
#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:
#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:
CButtonST m_btnOk;
Now attach the button to CButtonST. For dialog-based applications, in your OnInitDialog:
// Call the base-class method
CDialog::OnInitDialog();

// Create the IDOK button
m_btnOk.SubclassDlgItem(IDOK, this);
Or in your DoDataExchange:
// 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:
CButtonST* m_pbtnOk;
Now create the button. For dialog-based applications, in your OnInitDialog:
// 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, <BR>                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:
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.

// Parameters:
//     [IN]   nIconIn
//            ID number of the icon resource to show when the mouse is over the<BR>//            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 <BR>//            the button. Can be NULL.
//            If this parameter is the special value BTNST_AUTO_GRAY (cast to int) <BR>//            the second icon will be automatically created starting from nIconIn <BR>//            and converted to grayscale.
//            If this parameter is the special value BTNST_AUTO_DARKER (cast <BR>//            to int) the second icon will be automatically created 25% <BR>//            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, <BR>              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.
// Parameters:
//     [IN]   nIconIn
//            ID number of the icon resource to show when the mouse is over the <BR>//            button.
//            Pass NULL to remove any icon from the button.
//     [IN]   nIconOut
//            ID number of the icon resource to show when the mouse is <BR>//            outside the button. Can be NULL.
//            If this parameter is the special value BTNST_AUTO_GRAY (cast to int) <BR>//            the second icon will be automatically created starting from <BR>//            nIconIn and converted to grayscale. If this parameter is the <BR>//            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.
// 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. <BR>//            Can be NULL.
//            If this parameter is the special value BTNST_AUTO_GRAY the second
//            icon will be automatically created starting from hIconIn and <BR>//            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.
// Parameters:
//     [IN]   nBitmapIn
//            ID number of the bitmap resource to show when the mouse is <BR>//            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 <BR>//            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, <BR>                 int nBitmapOut = NULL, COLORREF crTransColorOut = 0)

SetBitmaps (using handles)
Assigns bitmaps to the button.
Any previous icon or bitmap will be removed.

// 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, <BR>                 HBITMAP hBitmapOut = NULL, COLORREF crTransColorOut = 0)

SetFlat
Sets the button to have a standard or flat style.

// 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.
// 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.
// 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.
// 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.
// 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.
// 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.
// 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.
// 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.
// 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 hilight logic for the button.
Applies only to flat buttons.
// Parameters:
//     [IN]   bAlwaysTrack
//            If TRUE the button will be hilighted even if the window that owns it, is
//            not the active window.
//            If FALSE the button will be hilighted 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.
// 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.
// 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.
// 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.
// 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.
// 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.
// Return value:
//     BTNST_OK
//        Function executed successfully.
//
DWORD EnableBalloonTooltip()
ActivateTooltip
Enables or disables the button tooltip.
// Parameters:
//     [IN]   bActivate
//            If TRUE the tooltip will be activated.
//
void ActivateTooltip(BOOL bEnable = TRUE)
GetDefault
Returns if the button is the default button.
// 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 trasparent 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.
// 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.
// 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.
// 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.
// 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 <BR>//            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 <BR>//            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.
// 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 <BR>//            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 <BR>//                      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.
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.
// Parameters:
//     [IN]   lpszSound
//            A string that specifies the sound to play.
//            If hMod is NULL this string is interpreted as a filename, <BR>//            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 <BR>//            be loaded.
//            This parameter must be NULL unless lpszSound specifies a <BR>//            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 <BR>//            the button.
//     [IN]   bPlayAsync
//            TRUE if the sound must be played asynchronously.
//            FALSE if the sound must be played synchronously. The <BR>//            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.
// 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.
// 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.
// Return value:
//     Class version. Divide by 10 to get actual version.
//
static short GetVersionI()
GetVersionC
Returns the class version as a string value.
// Return value:
//     Pointer to a null-terminated string containig 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 indipendent 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 dinamically 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 IE
  • 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 speeds 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 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 finds and fixes 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

About the Author

Davide Calabro
Web Developer
Italy Italy
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralRe: trouble whth draw transparentmemberOsman Kevin9 Dec '03 - 16:03 
I met the same problem, the author told us this is a well-know transparency bug and can not be fixed for the time beingCry | :(( from codeguru.com), so if anyone here can help us out of here.
Could we solve it by forcing the window to be top most at startup?
 
Any comment or advice is highly appreciated!
 


 
Osman Kevin
GeneralRe: trouble whth draw transparentmemberSamuele21 Jul '05 - 0:15 
You can solve this problem forcing buttons to refresh their background when the dialog background needs erasing.
You have to add the handler for WM_ERASEBKGND messages in your window class:
 
BOOL CMyDialog::OnEraseBkgnd(CDC* pDC)
{
BOOL bRet = CParentDialog::OnEraseBkgnd(pDC);
OnPostEraseBkgnd(pDC);
return bRet;
}

After erasing the dialog background, you have to force buttons to reload their background, calling a member function OnPostEraseBkgnd, which you'll define like this:
 
void CMyDialog::OnPostEraseBkgnd(CDC* pDC)
{
CWnd* pChildWnd = GetTopWindow();
while (pChildWnd)
{
if(pChildWnd->IsKindOf(RUNTIME_CLASS(CButtonST)))
{
((CButtonST*)pChildWnd)->SetBk(pDC);
}
pChildWnd = pChildWnd->GetWindow(GW_HWNDNEXT);
}
}

 
This function will set for each CButtonST control the updated background of the parent window.
 
Hoping it can be helpful... Cool | :cool:
 
Regards,
Sam Smile | :)
GeneralGDI problem on Win98sussbeback1 Jul '03 - 18:15 
Very good control!
 
But, I've a problem on Win9x.
GDI Object handle is invalid sometimes when SelectObject, DeleteObject, DeleteDC call in CButtonST::DrawTheBitmap().
The button DC is broken when SelectObject returns NULL with invalid GDI object handle.
 
Has the bitmap handle changed for m_csBitmaps?
Or are there many GDI objects in the application?
 
The number of GDI objects is 147(=72 Bitmaps + 7 MemDCs + 54 Fonts + 13 Regions + 1 Palette) in my application.
I'm working on WIn98SE with VC++ 6.0 SP5.
Please, help me!
 
Thanks in advance.
 

Sangbaek Park
Marotech, Inc.
Generalbitmaps on buttons not visible if buttons used in dllmembermanmed_7930 Jun '03 - 23:11 
I have a button (CButtonST) in a dialog which is loaded dynamically. The bitmaps over this buttons are not visible.
 
manmed
GeneralRe: bitmaps on buttons not visible if buttons used in dllmembermanmed_791 Jul '03 - 0:16 
use this statement
 
AFX_MANAGE_STATE(AfxGetStaticModuleState());
 
in the first line of the functions which have the following statement,
 
AfxFindResourceHandle();
 
old code
--------
DWORD CButtonST::SetBtnCursor(int nCursorId, BOOL bRepaint)
{
HINSTANCE hInstResource = NULL;
// Destroy any previous cursor
if (m_hCursor)
{
::DestroyCursor(m_hCursor);
m_hCursor = NULL;
} // if
 
// Load cursor
if (nCursorId)
{
hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(nCursorId), RT_GROUP_CURSOR);
// Load cursor resource
m_hCursor = (HCURSOR)::LoadImage(hInstResource, MAKEINTRESOURCE(nCursorId), IMAGE_CURSOR, 0, 0, 0);
// Repaint the button
if (bRepaint) Invalidate();
// If something wrong
if (m_hCursor == NULL) return BTNST_INVALIDRESOURCE;
} // if
 
return BTNST_OK;
} // End of SetBtnCursor
 

New Code
--------
DWORD CButtonST::SetBtnCursor(int nCursorId, BOOL bRepaint)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
HINSTANCE hInstResource = NULL;
// Destroy any previous cursor
if (m_hCursor)
{
::DestroyCursor(m_hCursor);
m_hCursor = NULL;
} // if
 
// Load cursor
if (nCursorId)
{
hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(nCursorId), RT_GROUP_CURSOR);
// Load cursor resource
m_hCursor = (HCURSOR)::LoadImage(hInstResource, MAKEINTRESOURCE(nCursorId), IMAGE_CURSOR, 0, 0, 0);
// Repaint the button
if (bRepaint) Invalidate();
// If something wrong
if (m_hCursor == NULL) return BTNST_INVALIDRESOURCE;
} // if
 
return BTNST_OK;
} // End of SetBtnCursor
 

Reasone
-------
Resource handle should be taken from currently active module.
 
mansoor ahamed
GeneralRe: bitmaps on buttons not visible if buttons used in dllmemberst0per1 Aug '04 - 3:44 
just what i was after,
 

thank you.
QuestionHow to use in a viewmemberTom Watson25 Jun '03 - 8:19 
How do I set up button st for use in a form view? I use this code in OnInitDialog() for dialogs [it works], and I placed it into OnInitialUpdate for the form view... but there, it does not work.
 
m_leftArrowControl.SubclassDlgItem( IDC_REMOVE, this );
m_leftArrowControl.SetIcon( IDI_LEFT_ARROW, NULL, 16, 16 );
m_leftArrowControl.SetFlat( false );
 
thanks.
AnswerRe: How to use in a viewsussejiue27 Jun '03 - 22:13 
Sleepy | :zzz:
 
I come up against the same problem as you.
It seems that no appropriate position for us to initialize buttons.
In OnininDialog() or OnCreate(),it does't work.
But you can implement your statements in the Function of class CMainFrame.
Eager for anyone else to explain.
AnswerRe: How to use in a viewmemberstorein14 Jun '05 - 5:25 
you can only create CButtonST object dynamically
 
DDX_Control(pDX, ID_BOTTOM_BACK, m_btnBack);
 

then modify it style in view OnInitialUpdate()

Generalthanks you!!!sussAnonymous16 Jun '03 - 16:33 
:-DIs the CButtonST what a package of software is employd a package of software in the order liner of self ? Have to get off the growing source earlier as to CButtonST ? It is not Vc++ since brings type ?
QuestionDrawTransparent don't work when button created in a view?memberskygg4 Jun '03 - 22:48 
and why u call DrawTransparent() in OnSetFocus function? yes Transparence fail when call DrawTransparent() in OnInitDialog();
 
still a question, why not add a VAR BOOL m_bFirstTime TO class CButtonST to control DrawTransparent() only once?
 
Confused | :confused:
 

GeneralPb creating ButtonST subclassmemberMyttO26 May '03 - 6:19 
Great Job!
 
I still have a problem: I want to create a subclass of CButtonST, let's say CButtonDirection, and instanciate it in a property sheet.
 
It seems something is missing (like subclassing directive), 'cause I can't handle window messages like WM_CREATE:
 
int CButtonDirection::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CButtonST::OnCreate(lpCreateStruct) == -1)
return -1;

SetFlat(FALSE);
SetIcon(IDI_UP_ARROW);

return 0;
}

 
I can't figure out what I forgot Confused | :confused: Any help ?
 
-MyttO
QuestionBug with tooltips and XP?memberAndrew Welch25 May '03 - 19:42 
I see there are a few tooltip bug reports already.
 
Is there a bug with the button tooltips when running XP and having a theme aware app?
 
They never show up. I've tried numerous variations for setting them up all to no avail.
AnswerHere's how to recreate...memberAndrew Welch4 Jun '03 - 19:05 

1. Create a checkbox button on a dialog. Set it to the "pushlike" style. (you can actually just create a normal button as well)
 
2. Make sure you include an XP manifest file with your app either in the resources or as btntest.exe.manifest etc. (run under XP as well)
 
3. Subclass the checkbox button as a CButtonST control
 
4. Set a tooltip
 
5. Run the app.. hover over the button.. the tooltip shows up
 
6. click on the button.. tooltip disappears
 
7. tooltip will never show up again regardless of the button state
GeneralRe: Here's how to recreate...memberTim Stubbs23 Jun '03 - 22:02 
I have the same problem - ish Smile | :)
 
I'm using the class in an OLE control which doesn't allow PreTranslate message for CButtonST, so instead i'm doing some fudging in OnMouseMove() to cause the tooltip to appear. This works fine in all cases except when the tooltip times out (i.e. mouse on button and timeout occurs and tooltip hides). Once this has happen the button will never show the tip again. I can force it to be shown with CToolTipCtrl::Update() but this isn't ideal.
 
Still pondering and playing..

 
Tim Stubbs

GeneralRe: Here's how to FIX :)memberTim Stubbs24 Jun '03 - 5:05 
As I said before, when embedded in an OCX control PreTranslate never gets called, so in OnMouseMove I post the info off the the tooltip control with RelayEvent() [see docs for CToolTipCtrl]. I do the same for MouseLeave and LButtonDown (although neither of these is actually necessary it's probably 'cleaner' as CToolTipCtrl is interested in these messages according to MSDN.
 
The problem I specifically had was the tooltip not reappearing after a timeout had occured (cursor left over button and tooltip vanishes after timeout). I've fixed this rather inelegantly by removing the tool from the tooltip control with CToolTipCtrl::DelTool() when the mouse leaves the button (OnMouseLeave()) and then adding it again directly after. This (sadly) fixes the problem and the tooltip re-appears the next time the mouse enters the control area.
I elected to keep the original state of both the tool's text and activation state when SetToolTipText() is called on CButtonST. The latter I already monitor so that i can turn off tooltips when dropping down menus from the buttons (I have done some heavy modification to CButtonST) from a toolbar.
 
This fixes the problem - at least safely enough for me to continue towards my end of the month deadline Dead | X|
 
Tim Stubbs

GeneralRe: Here's how to FIX :)memberAndrew Welch27 Jun '03 - 15:50 
Cool! I may have to give this a try in one project.
 
I also ran into the problem recently where the standard tooltips were showing the tip from the last control due to running on XP when an OpenGL app is running as well. Very annoying Smile | :) This happens with anything that displays a tooltip.. Not just CButtonST..
 
There's a knowledge base article about this and everything - and it's due to be fixed in SP2, although you can somehow get a hot fix for it.
 
To get around this I just created my own (owner drawn and everything) tooltip control for the dialog and handled it that way.
 
Regards,
Andrew
GeneralRe: Here's how to FIX :)member_joe_wilbur_8 Jul '03 - 14:57 

 
Maybe this solution is too obvious to be correct in all situations, but so far I haven't found a problem with it. I too could not get the ToolTips to work in an activeX control. This is how I fixed it.
 

_______________________________________________________
Add the following in the BtnST.h file:
Somewhere on top:
#define THIS_IS_ACTIVEX
 
Then in the protected section:
#ifdef THIS_IS_ACTIVEX
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
afx_msg void OnMButtonDown(UINT nFlags, CPoint point);
afx_msg void OnMButtonUp(UINT nFlags, CPoint point);
#endif

 

____________________________________________________
Add the following in the BtnST.cpp file:
BEGIN_MESSAGE_MAP(CButtonST, CButton)
.
.
.
#ifdef THIS_IS_ACTIVEX
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONDOWN()
ON_WM_MBUTTONDOWN()
ON_WM_MBUTTONDOWN()
ON_WM_RBUTTONDOWN()
ON_WM_RBUTTONDOWN()
#endif
.
.
.
END_MESSAGE_MAP()

 
then later ....
 
#ifdef THIS_IS_ACTIVEX
void CButtonST::OnLButtonDown(UINT nFlags, CPoint point)
{
MSG msg;
msg.hwnd = m_hWnd;
msg.message = WM_LBUTTONDOWN;
msg.wParam = nFlags;
msg.lParam = (point.x & 0xFFFF) | ((point.y & 0xFFFF) << 16);
msg.time = GetTickCount();
msg.pt = point;
PreTranslateMessage(&msg);
CButton::OnLButtonDown(nFlags, point);
}
void CButtonST::OnLButtonUp(UINT nFlags, CPoint point)
{
MSG msg;
msg.hwnd = m_hWnd;
msg.message = WM_LBUTTONUP;
msg.wParam = nFlags;
msg.lParam = (point.x & 0xFFFF) | ((point.y & 0xFFFF) << 16);
msg.time = GetTickCount();
msg.pt = point;
PreTranslateMessage(&msg);
CButton::OnLButtonUp(nFlags, point);
}
void CButtonST::OnRButtonDown(UINT nFlags, CPoint point)
{
MSG msg;
msg.hwnd = m_hWnd;
msg.message = WM_RBUTTONDOWN;
msg.wParam = nFlags;
msg.lParam = (point.x & 0xFFFF) | ((point.y & 0xFFFF) << 16);
msg.time = GetTickCount();
msg.pt = point;
PreTranslateMessage(&msg);
CButton::OnRButtonDown(nFlags, point);
}
void CButtonST::OnRButtonUp(UINT nFlags, CPoint point)
{
MSG msg;
msg.hwnd = m_hWnd;
msg.message = WM_RBUTTONUP;
msg.wParam = nFlags;
msg.lParam = (point.x & 0xFFFF) | ((point.y & 0xFFFF) << 16);
msg.time = GetTickCount();
msg.pt = point;
PreTranslateMessage(&msg);
CButton::OnRButtonUp(nFlags, point);
}
void CButtonST::OnMButtonDown(UINT nFlags, CPoint point)
{
MSG msg;
msg.hwnd = m_hWnd;
msg.message = WM_MBUTTONDOWN;
msg.wParam = nFlags;
msg.lParam = (point.x & 0xFFFF) | ((point.y & 0xFFFF) << 16);
msg.time = GetTickCount();
msg.pt = point;
PreTranslateMessage(&msg);
CButton::OnMButtonDown(nFlags, point);
}
void CButtonST::OnMButtonUp(UINT nFlags, CPoint point)
{
MSG msg;
msg.hwnd = m_hWnd;
msg.message = WM_MBUTTONUP;
msg.wParam = nFlags;
msg.lParam = (point.x & 0xFFFF) | ((point.y & 0xFFFF) << 16);
msg.time = GetTickCount();
msg.pt = point;
PreTranslateMessage(&msg);
CButton::OnMButtonUp(nFlags, point);
}
#endif

And finally, in the OnMouseMove function that already exists, right at the top,
 
void CButtonST::OnMouseMove(UINT nFlags, CPoint point)
{
CWnd* wndUnderMouse = NULL;
CWnd* wndActive = this;
TRACKMOUSEEVENT csTME;
 
#ifdef THIS_IS_ACTIVEX
MSG msg;
msg.hwnd = m_hWnd;
msg.message = WM_MOUSEMOVE;
msg.wParam = nFlags;
msg.lParam = (point.x & 0xFFFF) | ((point.y & 0xFFFF) << 16);
msg.time = GetTickCount();
msg.pt = point;
PreTranslateMessage(&msg);
#endif
CButton::OnMouseMove(nFlags, point);
.
.
.
.
}

 
This appears to work like a champ.

 
J. Wilbur
GeneralRe: Here's how to FIX :)memberTim Stubbs8 Jul '03 - 20:46 
I guess that would work too - but it's not so dissimilar to what i'm doing, you're just forwarding the events in a slighty different way. Hey, as long as it works..
Poke tongue | ;-P
 
Tim Stubbs

GeneralRe: Here's how to recreate...memberYOAN Jun19 Sep '03 - 0:22 
I also worried about the same problem.
Please try the following code. Smile | :)
 
--- CButtonST.h ---
:
<code>protected:
    CString m_strTipText;
</code>:
--- CButtonST.cpp ---
void CButtonST::SetTooltipText(LPCTSTR lpszText, BOOL bActivate)
{
    // We cannot accept NULL pointer
    if (lpszText == NULL) return;
 
    ////////
    m_strTipText = lpszText;
    ////////
    :
}
LRESULT CButtonST::OnMouseLeave(WPARAM wParam, LPARAM lParam)
{
    CancelHover();
    ////////
    if (m_ToolTip.m_hWnd != NULL) {
        m_ToolTip.DelTool(this, 1);
        if (m_strTipText.IsEmpty() != TRUE) {
            CRect rectBtn; 
            GetClientRect(rectBtn);
            m_ToolTip.AddTool(this, m_strTipText, rectBtn, 1);
            m_ToolTip.Activate(TRUE);
        }
    }
    ////////
    return 0;
} // End of OnMouseLeave
 

QuestionWhat are these defines for?memberJosema15 May '03 - 0:48 
I've seen these defines
 
#ifndef TTM_SETTITLE
#define TTM_SETTITLEA (WM_USER + 32) // wParam = TTI_*, lParam = char* szTitle
#define TTM_SETTITLEW (WM_USER + 33) // wParam = TTI_*, lParam = wchar* szTitle
#ifdef UNICODE
#define TTM_SETTITLE TTM_SETTITLEW
#else
#define TTM_SETTITLE TTM_SETTITLEA
#endif
#endif
 
but I don't found where are they used?
 
What are they for?

GeneralDay 6 of Learn C++ in 21 days!sussAnonymonkey7 May '03 - 23:29 
I'm on day 6 of the course....'Learn C++ in 21 days'.
 
How long will it take me to learn how to use this calss?
 
I'v managed to get an irregular bit mapped image to come up as a dialog with standard buttons -but i want to add custom buttons and the smart stuff by button king -Davide Calabro.
 
Oh Well ....Cry | :((
 

GeneralRe: Day 6 of Learn C++ in 21 days!sussAnonymous9 May '03 - 16:00 
Smile | :) got it all working - and integrated CbuttonST with David Forrester's irregular shaped bit-mapped dialog class (BitmapDialog).
 
Whoopee!
 
Can now do dialogs of any shape/size/bitmap with buttons of any size/icon/bitmap.
 
Just need to add a bit more to it all to get animation sequences on buttons & workout how to do irregular shaped buttons without using graphical trickery.
 
Many thanks Davide
 
Tammy
GeneralDynamic creation of buttons, No tooltipmemberjimNLX6 May '03 - 11:44 
I'm creating many buttons dynamically using this to initialize it:
 
m_Icon[ndx].Create(_T(""), WS_CHILD WS_VISIBLE , CRect(0, 0, 0, 0), this,IDC_BTN );
 
Then later I'm adding in other information and then putting it on the screen:
 
m_Icon[0].SetTooltipText((LPCTSTR)ps1,true);
m_Icon[0].ActivateTooltip(true);
m_Icon[0].SetIcon(IDI_ICON1,NULL);
m_Icon[0].MoveWindow(iXpos ,(yscalestart + yscalediff*(profile.counter[0].iStationNum -10)),29,33,TRUE);
 
Any ideas on why the tool tip doesn't work?
 
If used tool tips before using static items and it was never a problem
 
Thanks,
 
Jim
Generalproblem EnableBalloonTooltipmemberAdam Keadey24 Apr '03 - 8:40 
If I call EnableBalloonTooltips in my app it stops showing the tooltips.
 
Remove the EnableBalloonTooltips and the tooltips work fine.
 
here is my code in the OnInitDialog of a dialog class.
 
m_print_ctrl.SetIcon(IDI_PRINT_CRS, 16, 16);
m_print_ctrl.SetRounded(TRUE);
m_print_ctrl.SetColor(CButtonST::BTNST_COLOR_BK_OUT, ::GetSysColor(COLOR_3DHIGHLIGHT));
m_print_ctrl.SetColor(CButtonST::BTNST_COLOR_BK_FOCUS, ::GetSysColor(COLOR_3DHIGHLIGHT));
m_print_ctrl.SetSound(MAKEINTRESOURCE(IDR_WAVE1), ::GetModuleHandle(NULL));
m_print_ctrl.EnableBalloonTooltip();
m_print_ctrl.SetTooltipText(_T("Print The Current Listing"));
GeneralRe: problem EnableBalloonTooltipmemberadam Keadey25 Apr '03 - 5:07 
also discovered when I create this same button with the EnhableBalloonTooltip or without the tool tip never shows.
 
I have to missing something somewhere.
QuestionTransparent bitmap images and PressedStyle?membercephelo17 Apr '03 - 8:00 
By the way, great class! love it!
 
I have a transparent bitmap button and when its pressed, it is being offset. I do not want that. Could you add functionality to the SetPressedStyle to have it set so there is NO offset? Thanks
AnswerRe: Transparent bitmap images and PressedStyle?membercephelo21 Apr '03 - 18:52 
I fixed this myself by adding a constant to the enum of the pressed states, (in BtnST.h)
 

enum { BTNST_PRESSED_LEFTRIGHT = 0, // Pressed style from left to right (as usual)
BTNST_PRESSED_TOPBOTTOM, // Pressed style from top to bottom
BTNST_PRESSED_NOMOVE // Pressed style does not change EAB 4-21-03
};

 
And then in BtnST.cpp in the SetPressedStyle function:
 

case BTNST_PRESSED_NOMOVE:
m_ptPressedOffset.x = 0;
m_ptPressedOffset.y = 0;

 
Works perfect.
QuestionAny chance on making the disabled look cleaner?memberEyes`Only9 Apr '03 - 12:10 
As we all know, the disabled button look leaves much to be desired in C++. Is there a change you could incorporate a function that would let us specify a 'disabled bitmap' to use instead of greying/embossing the current bitmap? On many displays, that greyed/embossed bitmap looks quite ugly. I'd like to simply take the same bitmap that I use for enabled, convert it to greyscale, and use it for disabled. Could someone modify this to do that? Or show me what lines could be 'tweaked' to enable this effect?
AnswerRe: Any chance on making the disabled look cleaner?memberBaris Kurtlutepe4 May '03 - 8:52 
Actually I've confronted the same problem and it looks really ugly under XP with all the nice colors and alpha stuff etc. So, here's my 'solution':
 
Change the function DrawTheIcon (or if you're using bitmaps instead of icons, then apply the change to the DrawTheBitmap function) as follows:
 
In the last line, there's an API call like:
 
pDC->DrawState( rImage.TopLeft(),
rImage.Size(),
m_csIcons[byIndex].hIcon,
(bIsDisabled ? DSS_DISABLED : DSS_NORMAL),
(CBrush*)NULL);

 
change it to:
 
pDC->DrawState( rImage.TopLeft(),
rImage.Size(),
m_csIcons[byIndex].hIcon,
DSS_NORMAL,
(CBrush*)NULL);

 
Notice the DSS_DISABLED style, that tells the OS to draw the icon disabled using its own implementation, which gives it the ugly 16 color look. So all you have to do is simply remove it and your icon will show in its original color. That is if you've given your icon two states, the second (not hovered) one will be shown. If you want to display an extra -third- icon you can make your own implementation by increasing the size of the m_csIcons array and change the bIndex value properly in the beginning of the function.

QuestionMaking check box look normal?memberxeon_boy7 Apr '03 - 19:34 

Hi there! I want to have a check box with a white background. In normal Visual C++ programming, this is not easily possible, but with CButtonST, I can achieve this effect.
 
The only problem is that if my check boxes are derived from CButtonST and lets CButtonST handle all the drawing for me etc., the original square tick-box is not present!
 
I guess this is because the owner-draw code overrides this appearance with it's own.
 
Is there no way to get around this?!
Please and thanks a lot! Smile | :)
 
......
AnswerRe: Making check box look normal?membercrewchill17 Jun '03 - 11:55 
This may sound stupid, but I actually have 2 bitmaps, one with normal square, the other one with checked square. Then do:
 
m_chkButton.SetBitmaps(IDB_BITMAP_CHECK_ON,Red,IDB_BITMAP_CHECK_OFF,Red);
 
The Red ( == RGB(255,0,0) ) is the transparency color, which I dont have in the bitmap since I want opaque background. Hope this helps.
GeneralGood Job!!memberAisha Ikram1 Apr '03 - 0:43 
I liked your work Smile | :)
 
@!$h@

GeneralProblem with transparencymemberdeimos17 Mar '03 - 3:54 
Please answer on question!
http://www.codeproject.com/buttonctrl/cbuttonst.asp?df=100&forumid=111&exp=0&select=338578&fr=26#xx338578xx
Generalcheckbox style and flickersussyugami10 Mar '03 - 8:26 
your checkbox style flickers when being set into the down position and you do work of any note
 
create a handler in the advanced tab dialog for it and do Sleep(100) to notice it.
GeneralTransparent Icon buttonssussAnonymous6 Mar '03 - 7:34 
Is there anyway I can make some buttons transparent if I use an Icon?
GeneralCButtonST v3.9 is out!memberDavide Calabro3 Mar '03 - 21:53 
Currently available only on www.SoftechSoftware.it

 
SoftechSoftware
Davide Calabro'
davide_calabro@yahoo.com
http://www.softechsoftware.it
GeneralRe: CButtonST v3.9 is out!memberTim Stubbs18 Mar '03 - 23:26 
v3.9 (03/March/2003)
Added support for Windows XP icons
 
What exactly do you mean David? Will it now display 32bit icons (24bit + 8bit transparency) or do you mean something else? I've diffed the code but can't quite see this...

 
Tim Stubbs

GeneralRe: CButtonST v3.9 is out!memberDavide Calabro19 Mar '03 - 0:43 
Well, the support for XP icons was already there...
If you have a .ico file that has ALSO the icon in XP format, the
system will use it automatically. See the 48x48 butterfly icon
into the "Transparent effect" tab. If running under XP the icon
will have the smooth effect, while if running under 9x/2000 it will
have the old effect. If you open Butterfly.ico you will find
more than one icon.
To see this if must run the 3.9 sample application.
 
SoftechSoftware
Davide Calabro'
davide_calabro@yahoo.com
http://www.softechsoftware.it
GeneralRe: CButtonST v3.9 is out!memberTim Stubbs19 Mar '03 - 2:26 
Cheers David - i see what you mean - so you're saying the rendering is taken care of by
 
pDC->DrawState( rImage.TopLeft(),
rImage.Size(),
m_csIcons[byIndex].hIcon,
(bIsDisabled ? DSS_DISABLED : DSS_NORMAL),
(CBrush*)NULL);
 
In DrawTheIcon() ?
 
I shall have to experiment with this versus using the UXTheme.DLL's 'interpretation'. Hey, doesn't that mean that CButtonST supports > 256 colours so you have to change your spec:
"Support for any size icons (max. 256 colors)"
Smile | :)
 
Cheers,

 
Tim Stubbs

GeneralError in Windows2000+VC6memberelisa28 Feb '03 - 4:45 
Debug info:
Confused | :confused:
HEAP[TestBtnST.exe]: Heap block at 001377A8 modified at 001377DC past requested size of 2c
 
Why?
GeneralRe: Error in Windows2000+VC6membersakee28 Feb '03 - 7:13 
I have not encountered this specific problem. But when heap issue occurs, you might want to do "re-build all".
QuestionWin32 Release Unicode ,then get a warning ?memberloomwolf27 Feb '03 - 19:18 
Confused | :confused: Confused | :confused: Confused | :confused: After i add "#define TTS_BALLOON 0x40" on the top area of BtnST.cpp, Win32 Release Unicode ,then get a warning :
LINK : warning LNK4089: all references to "comdlg32.dll" discarded by /OPT:REF
 
What's wrong?????
 
thanks a lot
 

AnswerRe: Win32 Release Unicode ,then get a warning ?membersakee28 Feb '03 - 7:06 
I added the "#define TTS_BALLOON 0x40" just before the function "DWORD CButtonST::EnableBalloonTooltip()" and there isn't any problem.
GeneralMemory Leaksmembersakee26 Feb '03 - 22:21 
I have encountered memory leaks too. The CButtonST class used is the current v3.8 one. Any solution? Thanks.
GeneralRe: Memory LeaksmemberDavide Calabro26 Feb '03 - 22:52 
You too ?
Who also have memory leaks? No one reported memory leaks in version 3.8 ....
 
Cheers,
 
SoftechSoftware
Davide Calabro'
davide_calabro@yahoo.com
http://www.softechsoftware.it
GeneralRe: Memory LeaksmemberTim Stubbs27 Feb '03 - 22:16 
I've not experienced any problems with memory leaks in the current version...

 
Tim Stubbs

GeneralRe: Memory Leaksmembersakee28 Feb '03 - 7:04 
Okay I have found that the memory leak is caused by calliung DDX_Control() on the same radio button resource for different CButtonST objects. This mistake occurs very frequently when I added many buttons resource at one go.... sorry for any inconvenience caused and thanks for responding.
GeneralBrill work, thanks and now a question...memberTim Stubbs24 Feb '03 - 3:21 
I've been a silent (and happy user/abuser) of your class for quite a while - thanks a heck of a lot it's saved me a lot of effort and time. I've modified it myself a little over the past year or so, for my own evil needs Poke tongue | ;-P
 
I'm currently looking at themeing for Windows XP. This is turning out to be quite hard, but i'm getting there - i've (much like yourself) developed a derived CButtonST class which themes itself for WinXP (or doesn't for Win2k), but i'm using it for toolbars instead (i'm odd). This has got me thinking, over the past week or so, about colour support. Am I right in thinking XP has some weird-ass support for 32bit icons, which break down into 24bit colour plus 8bit for the transparency? ButtonST supports just 8bit? Is this correct? If i want nice, anti-aliased icon images on my buttons have you any idea on the direction i might be taking? I notice that the UXTHEME DLL has a icon-rendering-function-thingy but is this the right way to go, versus DrawState?
 
Just thinking out loud, but hopefully such a discussion may be useful for yourself and others!

 
Tim Stubbs

GeneralRe: Brill work, thanks and now a question...memberTim Stubbs26 Feb '03 - 3:18 
Looking into this further i think the way to go with this is to provide another virtual function allowing a derived class to override the drawing of the icon, much as you do for drawing the border and background. I believe i've got the rendering working for 32bit icons within CButtonST itself so i will now see if i can do this externally to avoid modifying the base class too heavily...

 
Tim Stubbs

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 29 Mar 2003
Article Copyright 1999 by Davide Calabro
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid