SoftechSoftware homepage
SoftechSoftware Email
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:
In your project include the following files:
#define BTNST_USE_BCMENU #include "BCMenu.h"Also, the following files must be included in your project:
#define BTNST_USE_SOUND
This gives access to the
SetSound
method.
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
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;
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)
// 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)
// 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)
// 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
// 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
// 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
// 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
// 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
// Parameters: // [IN] bRepaint // If TRUE the control will be repainted. // // Return value: // BTNST_OK // Function executed successfully. // DWORD SetDefaultColors(BOOL bRepaint = TRUE)SetColor
// 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
// 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
// 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
// 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
// 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
// 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
// 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)
// 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
// 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
// Return value: // BTNST_OK // Function executed successfully. // DWORD EnableBalloonTooltip()ActivateTooltip
// Parameters: // [IN] bActivate // If TRUE the tooltip will be activated. // void ActivateTooltip(BOOL bEnable = TRUE)GetDefault
// Return value: // TRUE // The button is the default button. // FALSE // The button is not the default button. // BOOL GetDefault()DrawTransparent
// Parameters: // [IN] bRepaint // If TRUE the control will be repainted. // void DrawTransparent(BOOL bRepaint = FALSE)SetURL
// 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
// 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
// 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
// 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
void SizeToContent()
SetSound
// 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
// 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
// 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
// Return value: // Class version. Divide by 10 to get actual version. // static short GetVersionI()GetVersionC
// Return value: // Pointer to a null-terminated string containig the class version. // static LPCTSTR GetVersionC()
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.