Click here to Skip to main content
Email Password   helpLost your password?

Sample Image Sample Image Sample Image

SoftechSoftware homepage
SoftechSoftware Email

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:

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:
// 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 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:
// Call the base-class method

CDialog::OnInitDialog();

// Create the IDOK button

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

m_pbtnOk->SetFont(GetFont());
Remember to destroy the button or you will get a memory leak. This can be done, for example, in your class destructor:
if (m_pbtnOk) delete m_pbtnOk;

Class methods

SetIcon (using resources)
Assigns icons to the button.
Any previous icon will be removed.

// Parameters:

//      [IN]    nIconIn

//              ID number of the icon resource to show when the mouse is over the button.

//              Pass NULL to remove any icon from the button.

//      [IN]    sizeIn

//              Size of the icon.

//      [IN]    nIconOut

//              ID number of the icon resource to show when the mouse is outside the button.

//              Can be NULL.

//      [IN]    sizeOut

//              Size of the icon.

//      [IN]    nIconDis

//              ID number of the icon resource to show when the button is disabled.

//              Can be NULL.

//      [IN]    sizeDis

//              Size of the icon.

//

// Return value:

//      BTNST_OK

//          Function executed successfully.

//

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.
// 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]   sizeIn

//            Size of the icon.

//     [IN]   hIconOut

//            Handle to the icon to show when the mouse is outside the button.

//            Can be NULL.

//     [IN]   sizeOut

//            Size of the icon.

//     [IN]   hIconDis

//            ID number of the icon resource to show when the button is disabled.

//            Can be NULL.

//     [IN]   sizeDis

//            Size of the icon.

//

// Return value:

//      BTNST_OK

//          Function executed successfully.

//

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))
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.

//     [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 and text.
// Parameters:

//     [IN]   byAlign

//            Alignment type. Can be one of the following values:

//            ST_ALIGN_HORIZ          Icon on the left, text on the right

//            ST_ALIGN_VERT           Icon on the top, text on the bottom

//            ST_ALIGN_HORIZ_RIGHT    Icon on the right, text on the left

//            By default, CCeButtonST 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)
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. 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

//     [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)
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)
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()
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.
// 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)
OnDrawBackground
This 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.
// 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, LPCRECT 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 CCeButtonST-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, LPCRECT 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

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.

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
Generalthank you!
JOYZML
5:23 26 Dec '09  
thank you!
——————
GeneralThanks a lot!
Lysy95
5:28 15 Jun '09  
Saved me a lot of work and doc reading!
GeneralBUG? if use it for lots of buttons,then program dead!
rengdongzwf
19:53 24 May '07  
hello, i have use this class for my program, which have about 60 dialogs and so there are many buttons drived from CCeButton.Then i run it ,after i click some buttons, the program is dead, i use it the same like the demo project, why this happened? Is it a bug? can you help me ? thanks a lot!
ZouWeiFeng from china
QuestionIcon does not center
Kunchongji
20:07 3 Aug '06  
Hi,

I am using CCeButtonST in a Pocket PC project. The icon I want to display does not center on the button. The button is suppose to have the same size as the icon (16*16), but if this is the case, only a portion of the icon is shown down the bottom on the right hand side of the button.

Any idea?

Thanks in advance!

Feifei
GeneralDemo project problems
advatronix
15:11 19 Dec '05  
Demo project has multiple errors when trying to open resources. Have to comment out many things. After being compiled constantly fails assertion.
GeneralHow change Font meu in Pocket Pc 2003
nguyenthanhtung
16:22 15 Feb '05  
I insert button load menu in application. I don't change font menu. How do I do?Frown
GeneralChange Font Menu?
nguyenthanhtung
18:21 31 Jan '05  
I trying button set menu. How do I change font menu:(:(:(:(
GeneralBTNST_COLOR_BK_OUT seems not take effect...
Little Jonny
7:06 13 Nov '04  
Hi,

BTNST_COLOR_BK_OUT option seems not work in SetColor function,
How do i can make a button has a default look (border,color...)

ps: The CCeButtonST will not display color and border if mouse not hover or click

Please help and thanks
Cry
GeneralCCeButtonST and Default Buttons
Hadi Rezaee
23:14 1 Oct '04  
Hi Davide, Smile

I'm writing a program and I've a Button in my main dialog.
I used CCeButtonST for button ...

The problem is I can't use of the button as a default button anymoreFrown
What should i do ?!!

Regards,
Hadi
GeneralMemory Leakeage
SMPCHRIS
9:25 22 Jun '04  
If you change only the icons you get memory leaks in 4k size
(tested on WCE 4.2 and Microsoft Visual c++ 4.0 compiler).



chris
GeneralIcon size under NT
SMPCHRIS
3:28 14 Jun '04  
I use your CCeButtonST class. The class works really good under WCE.
But I want to use the same classes under NT and I have the following problem:

A button with a 110x110 icon under WCE is filled (That's fine).
But under NT the icon is much smaler and I don't find the mistake.
Please help.
regards chris
GeneralIcon
GuilhemMtp
21:56 1 Apr '04  
Is is possible to load the icon an the Dialog Box directly???

There is no matter to load "standard" icons.
But when the icon is bigger....

Sorry for my poor English Wink
GeneralRe: Icon
flyball
20:24 8 Sep '04  
i'm also confused wity that for a long time...
Has some one knows?
Help me plz~~~Sleepy

GeneralProblems with the control
Simone1976
0:26 21 Nov '03  
Hi, I use your control in my app dialog based, but at the third dialog, when I use again your control (in all map I use your control), the PDA crash and also the emulator going to crash. I use Pocket Pc 2002 and eVC++ 3. When I'm going to next dialog, i delete this variable on the OnCancel or OnOk function, but the problem persist ... can you help me?
Thanks

Simone Sanfilippo
GeneralHow to use in in Win 32 API based program
annum
10:52 2 Oct '03  
I am working on a Win32 based application and not a
mfc application.

Can I still use the class in there?
Any help is welcome
GeneralRe: How to use in in Win 32 API based program
Davide Calabro
12:08 2 Oct '03  
You can't, sorryFrown

SoftechSoftware
Davide Calabro'
davide_calabro@yahoo.com
http://www.softechsoftware.it
GeneralRe: How to use in in Win 32 API based program
Anonymous
12:27 2 Oct '03  
thanks!.

So is there a way of making cool buttons like this especially the one with green background and left/right arrows, using win32 only.

If there are some websites or links I will very much appreciate the help



GeneralRe: How to use in in Win 32 API based program
annum
12:31 2 Oct '03  
thanks!.

So is there a way of making cool buttons like this especially the one with green background and left/right arrows, using win32 only.

If there are some websites or links I will very much appreciate the help

GeneralRe: How to use in in Win 32 API based program
arvindr@erivasystems.com
0:07 22 Apr '05  
is there any alternative for win32?

arvish27@yahoo.co.in
GeneralProblems Changing Font
Andrea Benini (Ben)
0:16 9 Apr '03  
Hi All,
I'm trying to change the button font with command like these:
CFont m_font;
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT));
lf.lfHeight = 20;
wcscpy(lf.lfFaceName, L"Courier");
m_font.CreateFontIndirect(&lf);
m_mybutton.SetFont(&m_font);

Where m_mybutton is the button to be changed, note: i'm using the same instructions with Visual C++ under Windows and it works fine, instead of using the WCSCPY i'm using this one -->strcpy(lf.lfFaceName, "Courier");<--.
I've tried to use m_mybutton.SetFont(GetFont()); to get the standard font and it works, but what did i do wrong in my piece of code ?

Thanks in advance and Regards
note: your class rocks !


Andrea (Ben) Benini
GeneralRe: Problems Changing Font
Davide Calabro
22:47 9 Apr '03  
You have to fill ALL the LOGFONT fields. And m_font MUST be a member variable of your class, not a local one.

P.S.: supporta le mie classi!

SoftechSoftware
Davide Calabro'
davide_calabro@yahoo.com
http://www.softechsoftware.it
GeneralRe: Problems Changing Font
Andrea Benini (Ben)
6:01 10 Apr '03  
GRAZIE Smile
Generalsos
buaafang
16:20 5 Apr '03  
I hava to develop a program .but i don't kown how to ??
can you help me ?

buaafang@Hotmail.com

Fangweiwei From C.P.R
GeneralHelp
Mariz
8:30 27 Mar '03  
I can not download the project demo...

GeneralFlicker occurence
Soliant
16:49 19 Feb '03  
Does the flickering of the buttons occur only on the Emulator?

I only have emulator at this time, and when I run it , with debug build it flickers pretty much.

Great Job!



R.Bischoff | C++  
.NET, Kommst du mit?


Last Updated 19 Dec 2001 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010