Abstract
CCeButtonST
is a class derived from MFC CButton
class.
With this class your CE applications can have standard buttons or new and modern buttons with "flat" style!
Main CCeButtonST
features are:
- Standard
CButton
properties
- Text and icon on the same button
- Only text or only icon buttons
- Support for any size icons (max. 256 colors)
- 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 basic support for menus
- Can be derived to create other button styles not supplied by default
- Full source code included!
- UNICODE compatible
- Windows CE v3.0 compatible
- Cost-less implementation in existing applications
How to integrate CCeButtonST in your application
In your project include the following files:
Create a CCeButtonST 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:
CCeButtonST m_btnOk;
Now attach the button to
CCeButtonST
. For dialog-based applications, in your
OnInitDialog
:
CDialog::OnInitDialog();
m_btnOk.SubclassDlgItem(IDOK, this);
Or in your
DoDataExchange
:
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDOK, m_btnOk);
Create a CCeButtonST object dynamically
In your application, create a member variable for the button. Please note that this variable is a pointer:
CCeButtonST* m_pbtnOk;
Now create the button. For dialog-based applications, in your
OnInitDialog
:
CDialog::OnInitDialog();
m_pbtnOk = new CCeButtonST;
m_pbtnOk->Create(_T("&Ok"), WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP, CRect(10, 10, 200, 100), this, IDOK);
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 resources)
Assigns icons to the button.
Any previous icon will be removed.
DWORD SetIcon(int nIconIn, CSize sizeIn = CSize(32,32), int nIconOut = NULL,
CSize sizeOut = CSize(32,32), int nIconDis = NULL, CSize sizeDis = CSize(32,32))
SetIcon (using handles)
Assigns icons to the button.
Any previous icon will be removed.
DWORD SetIcon(HICON hIconIn, CSize sizeIn = CSize(32,32), HICON hIconOut = NULL,
CSize sizeOut = CSize(32,32), HICON hIconDis = NULL, CSize sizeDis = CSize(32,32))
SetFlatSets the button to have a standard or flat style.
DWORD SetFlat(BOOL bFlat = TRUE, BOOL bRepaint = TRUE)
SetAlignSets the alignment type between icon and text.
DWORD SetAlign(BYTE byAlign, BOOL bRepaint = TRUE)
SetCheckSets the state of the checkbox.
If the button is not a checkbox, this function has no meaning.
DWORD SetCheck(int nCheck, BOOL bRepaint = TRUE)
GetCheckReturns the current state of the checkbox.
If the button is not a checkbox, this function has no meaning.
int GetCheck()
SetDefaultColorsSets all colors to a default value.
DWORD SetDefaultColors(BOOL bRepaint = TRUE)
SetColorSets the color to use for a particular state.
DWORD SetColor(BYTE byColorIndex, COLORREF crColor, BOOL bRepaint = TRUE)
GetColorReturns the color used for a particular state.
DWORD GetColor(BYTE byColorIndex, COLORREF* crpColor)
SetAlwaysTrackSets the hilight logic for the button.
Applies only to flat buttons.
DWORD SetAlwaysTrack(BOOL bAlwaysTrack = TRUE)
SetBtnCursorSets the cursor to be used when the mouse is over the button.
DWORD SetBtnCursor(int nCursorId = NULL, BOOL bRepaint = TRUE)
DrawBorderSets if the button border must be drawn.
Applies only to flat buttons.
DWORD DrawBorder(BOOL bDrawBorder = TRUE, BOOL bRepaint = TRUE)
DrawFlatFocusSets if the focus rectangle must be drawn for flat buttons.
DWORD DrawFlatFocus(BOOL bDrawFlatFocus, BOOL bRepaint = TRUE)
GetDefaultReturns if the button is the default button.
BOOL GetDefault()
SetURLSets the URL that will be opened when the button is clicked.
DWORD SetURL(LPCTSTR lpszURL = NULL)
SetMenuAssociates a menu to the button.
The menu will be displayed clicking the button.
DWORD SetMenu(UINT nMenu, HWND hParentWnd, BOOL bRepaint = TRUE)
OnDrawBackgroundThis function is called every time the button background needs to be painted.
This is a virtual function that can be rewritten in CCeButtonST-derived classes
to produce a whole range of buttons not available by default.
virtual DWORD OnDrawBackground(CDC* pDC, LPCRECT pRect)
OnDrawBorderThis function is called every time the button border needs to be painted.
This is a virtual function that can be rewritten in CCeButtonST-derived classes
to produce a whole range of buttons not available by default.
virtual DWORD OnDrawBorder(CDC* pDC, LPCRECT pRect)
GetVersionIReturns the class version as a short value.
static short GetVersionI()
GetVersionCReturns the class version as a string value.
static LPCTSTR GetVersionC()
History
- v1.2 (18/December/2001)
Corrected a CE bug in OnLButtonDown
- v1.1 (28/November/2001)
Corrected the "DestroyCursor
" problem
- v1.0 (22/October/2001)
First release
Remarks
The demo application shows nearly all the features of the CCeButtonST
class.
It includes project settings for all the emulators included in Visual C++ eMbedded Tools v3.0 plus
settings to compile and run on the Advantech PCM-4823 single board computer.
CCeButtonST
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 CCeButtonST
demo application.
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.