CButtonST v2.3
Copyright (C) 1998 by SoftechSoftware
Thank you for use this SoftechSoftware! Thanks very much!
Contact addresses
SoftechSoftware E-Mail:
davide_calabro@yahoo.com
SoftechSoftware homepage:
http://members.tripod.com/~SoftechSoftware/index.html
CButtonST homepage:
http://members.tripod.com/~SoftechSoftware/cbtnst.html
Description
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!
CButtonST features:
- Standard CButton properties
- Text and icon buttons
- Only text or only icon buttons
- 16 and 256 colors icon support
- Standard or new "flat" button style
- Change runtime from "flat" to standard styles
- Button can have two icons. One when the mouse is over the button
and one when the mouse is off (only for "flat" buttons)
- Every color can be customized
- Can be used via DDX_ calls
- Can be used in DLLs
- Each button can have its own mouse pointer
- Button is hilighted also when the window is inactive, like happens
in Internet Explorer (this is user configurable)
- Written in Visual C++ v5.0
- Full source code included!
- It's free!
You are encouraged to use this class everywhere you want; there is no fee
required for CButtonST. Freely add modifications and/or fix bugs, but please,
send any of these to
SoftechSoftware!
How to integrate CButtonST in your application
In your project include the following files:
BtnST.h
BtnST.cpp
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, with resource editor, create an icon called, for example, IDI_OK256
You can also import it from one that already exists, such as, one included
in the sample project (i.e. 32x32x256_Ok.ico).
Remember to use 32x32 pixel icons. Even if there is support for icons wich
dimension is not 32x32 they can be drawn incorrectly.
Now attach the button to CButtonST. In your OnInitDialog procedure:
// Call the base method
CDialog::OnInitDialog();
// Create the IDOK button
m_btnOk.SubclassDlgItem(IDOK, this);
// Assign the icon
m_btnOk.SetIcon(IDI_OK256);
You may use two icons for the same button. First icon will be displayed when
the mouse pointer is over the button. Second icon will be displayed when the
mouse pointer is outside the button. If you design two same icons but one
with colors and one black & white you can have a great visual effect!
// Assign two icons
m_btnOk.SetIcon(IDI_OK256, IDI_OK256_BW);
Please note that two icons must have the same size!
By default the button will have the icon on the left and the text on
the right. If you want a button with the icon on the top and the text
on the bottom, you must set the alignment of the button:
// Align icon vertically
m_btnOk.SetAlign(CButtonST::ST_ALIGN_VERT);
Again, by default, the button will have the new "flat" style. If you want
a standard button just use the following piece of code:
// Draw the button as a standard button
m_btnOk.SetFlat(FALSE);
The following applies only with "flat" buttons: by default when the mouse
pointer passes over the button, this highlights itself. If you don't want
this just disable it. (In the demo program look what happens at the button
with the CD-ROM inside it!)
// Don't draw border for this button
m_btnOk.DrawBorder(FALSE);
Every button's color can be customized.
Background color is the button's face color while foreground color is the
text color. Inactive colors are that colors shown when the mouse is off the
button while active colors are that colors shown when the mouse is over.
// Set some color effect
COLORREF crStandard = ::GetSysColor(COLOR_BTNFACE);
m_btnOk.SetInactiveBgColor(crStandard - RGB(20,20,20));
m_btnOk.SetActiveBgColor(crStandard + RGB(20,20,20));
m_btnOk.SetInactiveFgColor(RGB(0,255,0));
m_btnOk.SetActiveFgColor(RGB(255,0,0));
Each button can have its own mouse pointer.
For example a button that runs an internet browser could change the pointer
to a hand when the user moves the mouse on it!
// Set a hand cursor
m_btnOk.SetBtnCursor(IDC_HAND);
Your button is now a CButtonST!
Look inside the demo program to learn more about CButtonST. This is the best way!
CButtonST members
void SetIcon(int nIconInId, int nIconOutId = NULL, BYTE cx = 32, BYTE cy = 32)
Set icon(s) for the button
- nIconInId
The icon resource (when the mouse pointer is inside)
- nIconOutId
The icon resource (when the mouse pointer is outside)
If NULL the first icon will be used instead
- cx, cy
The icon size. You can use 16x16, 32x32 or 48x48 icons but the best are 32x32
Example:
m_btnOk.SetIcon(IDI_OK256);
m_btnOk.SetIcon(IDI_OK256, IDI_OK256_BW);
m_btnOk.SetIcon(NULL); // To get a button without icon(s)
void SetAlign(int nAlign)
Set icon position (if one is defined)
Input values:
- ST_ALIGN_HORIZ
Icon on the left and text on the right (default)
- ST_ALIGN_VERT
Icon on top and text on bottom
Example:
m_btnOk.SetAlign(CButtonST::ST_ALIGN_VERT);
int GetAlign()
Get current icon position (see SetAlign for possible return values)
Example:
int nRetValue = m_btnOk.GetAlign();
void SetFlat(BOOL bState = TRUE)
Set button style ("flat" or standard)
Input values:
- TRUE
Button is drawn as "flat" (default)
- FALSE
Button is drawn as standard
Example:
m_btnOk.SetFlat();
m_btnOk.SetFlat(FALSE);
BOOL GetFlat()
Return current button style (see SetFlat for possible return values)
Example:
int nRetValue = m_btnOk.GetFlat();
void DrawBorder(BOOL bEnable = TRUE)
Set highlight ON/OFF (only for "flat" buttons)
Input values:
- TRUE
Button highlights itself (default)
- FALSE
Button doesn't highlight itself
Example:
m_btnOk.DrawBorder();
m_btnOk.DrawBorder(FALSE);
static const short GetVersionI()
static const char* GetVersionC()
Return CButtonST version
Example:
int nVer = CButtonST::GetVersionI(); // Divide by 10 to get actual version
char szVer[20];
strcpy(szVer, CButtonST::GetVersionC());
void SetShowText(BOOL bShow = TRUE)
Add or remove text (caption) from button at runtime
Input values:
- TRUE
Text is displayed
- FALSE
Text is not displayed (but still exists!)
Example:
m_btnOk.SetShowText();
m_btnOk.SetShowText(FALSE);
BOOL GetShowText()
Return current text status (displayed or not)
Example:
int nRetValue = m_btnOk.GetShowText();
void SetDefaultActiveFgColor()
Sets to the system default the text's color (when the mouse is over the button)
This is automatically called when a button is created.
Example:
m_btnOk.SetDefaultActiveFgColor();
void SetDefaultActiveBgColor()
Sets to the system default the button's color (when the mouse is over it)
This is automatically called when a button is created.
Example:
m_btnOk.SetDefaultActiveBgColor();
void SetDefaultInactiveFgColor()
Sets to the system default the text's color (when the mouse is outside the button)
This is automatically called when a button is created.
Example:
m_btnOk.SetDefaultInactiveFgColor();
void SetDefaultInactiveBgColor()
Sets to the system default the button's color (when the mouse is outside it)
This is automatically called when a button is created.
Example:
m_btnOk.SetDefaultInactiveBgColor();
void SetActiveFgColor(COLORREF crNew, BOOL bRepaint = FALSE)
Sets the text's color (when the mouse is over the button)
Input values:
- crNew
The new color
- bRepaint
If TRUE the button is immediately redrawn
Example:
m_btnOk.SetActiveFgColor(RGB(255, 255, 0));
void SetActiveBgColor(COLORREF crNew, BOOL bRepaint = FALSE)
Sets the button's color (when the mouse is over it)
Input values:
- crNew
The new color
- bRepaint
If TRUE the button is immediately redrawn
Example:
m_btnOk.SetActiveBgColor(RGB(128, 128, 128));
m_btnOk.SetActiveBgColor(::GetSysColor(COLOR_BTNFACE), TRUE);
void SetInactiveFgColor(COLORREF crNew, BOOL bRepaint = FALSE)
Sets the text's color (when the mouse is outside the button)
Input values:
- crNew
The new color
- bRepaint
If TRUE the button is immediately redrawn
Example:
m_btnOk.SetInactiveFgColor(RGB(255, 255, 255));
void SetInactiveBgColor(COLORREF crNew, BOOL bRepaint = FALSE)
Sets the button's color (when the mouse is outside it)
Input values:
- crNew
The new color
- bRepaint
If TRUE the button is immediately redrawn
Example:
m_btnOk.SetInactiveBgColor(RGB(128, 128, 128));
const COLORREF GetActiveFgColor()
Returns the current text's color (when the mouse is over the button)
Example:
COLORREF crCurrent = m_btnOk.GetActiveFgColor();
const COLORREF GetActiveBgColor()
Returns the current button's color (when the mouse is over it)
Example:
COLORREF crCurrent = m_btnOk.GetActiveBgColor();
const COLORREF GetInactiveFgColor()
Returns the current text's color (when the mouse is outside the button)
Example:
COLORREF crCurrent = m_btnOk.GetInactiveFgColor();
const COLORREF GetInactiveBgColor()
Returns the current button's color (when the mouse is outside it)
Example:
COLORREF crCurrent = m_btnOk.GetInactiveBgColor();
void SetFlatFocus(BOOL bDrawFlatFocus, BOOL bRepaint = FALSE)
Enable/Disable the drawing of the focus rectangle
This is valid ONLY for "flat" buttons; standard buttons always have the focus rectangle.
Input values:
- bDrawFlatFocus
When TRUE the "flat" buttons will have the focus rectangle
By default "flat" buttons have not the focus rectangle
- bRepaint
If TRUE the button is immediately redrawn
Example:
m_btnOk.SetFlatFocus(TRUE);
m_btnOk.SetFlatFocus(FALSE, TRUE);
BOOL GetFlatFocus()
Returns the state of the focus rectangle
This is valid ONLY for "flat" buttons; standard buttons always have the focus rectangle.
Return value:
- TRUE
Focus rectangle will be drawn
- FALSE
Focus rectangle will not be drawn
Example:
BOOL bDrawFlatFocus = m_btnOk.GetFlatFocus();
BOOL SetBtnCursor(int nCursorId = -1)
Assign a cursor to the button
The mouse pointer will change when over the button.
Input values:
- nCursorId
The cursor resource identifier
Output value:
- TRUE
Cursor assigned
- FALSE
Cannot load cursor resource
Example:
BOOL bRetValue = m_btnOk.SetBtnCursor(IDC_HAND);
m_btnOk.SetBtnCursor(); // To remove the assigned cursor
History
-
CButtonST 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
-
CButtonST 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.
-
CButtonST v2.1
Support for two icons
Modified SetIcon member
Added SetShowText/GetShowText members
Fixed a bug dealing with the left mouse button
Little optimizations
-
CButtonST 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
Things to do
- Support for bitmaps (under development)
- Any suggestion?
Special thanks
CButtonST is now receiving many suggestions from the users.
This section want to be the right place to say a THANK! to all of them for their precious help.
Armin Mendle
Chris Maunder (CHyperLink class)
Jeremy Davis (Suggestions about focus rectangles)
Keith Rule (CMemDC class)
Michael Santoro (For the ideas his CSXButton class given me!)
Mike Turner
Milan Gardian (Suggestions about color customization)
Ralph Varjabedian (For his many bug fixes!)
Copyright © 1998 by SoftechSoftware.
davide_calabro@yahoo.com