Click here to Skip to main content
13,451,997 members (48,922 online)
Click here to Skip to main content
Add your own
alternative version


76 bookmarked
Posted 30 Jan 2003

FxButton Class

, 24 Nov 2003
Rate this:
Please Sign up or sign in to vote.
FxButton allows developers to create customized buttons using captions, bitmaps, tooltips, etc.

First demo - play with one button

Second demo button gallery


FxButton allows developers to create customized buttons using captions, bitmaps, tooltips, etc. It cannot do everything, so be sure to check its limitations. I'm a beginner in coding VC++ with MFC and I made this class for fun and - above all - to learn.

The aim of this class - but not the only one - is to make it as easy as possible to integrate it in an application and to have the maximum options available. If you don't know what a handle is and you want a bitmap button, you can use this class.

The first FxButton demo is not a button gallery; it contains only one FxButton but you can play with it. The demo gives access to about 30 button components. Each of these options can be applied to any button state: normal, pushed, over or disabled.

The second FxButton demo is a button gallery. It shows the use of clipping regions for buttons and transparent bitmaps applied to push, check or radio buttons.

What's new in this update

a very minor change but it killed a bad bug. Applications no more crash after a few minutes of execution. I didn't test with Win98-95 but it's ok for the others.

Background (optional)


First of all, you may want to know what FxButton cannot do before reading through this document without finding what you're looking for. You should not use FxButton class if you :

  • Want to see animated bitmaps or AVIs on a button.
  • Want to see animated text, flashing colors, or use GIF pictures.
  • Need to use a check button with the 3States property.
  • Want an auto-sized button with the bitmap size drawn on it.
  • Want a button which automatically takes into account all the basic and extended styles available on the Resource Editor of Visual C++.
  • Want to have 5 different bitmaps and 5 different clipping windows using only 2 GDI objects.
  • Want to create a heavily customized button with only 3 lines of codes.

What Fx Button does

An FxButton can contain different data for the normal, pushed, over and disabled states. This means it can manage 4 bitmaps, 4 captions, 4 background colors, etc. Here is a list of all the button items :

  • Background color
  • Border color and size
  • Bitmap
  • Transparent bitmap
  • Backscreen bitmap
  • Text
  • Tooltips
  • Focus
  • Cursor
  • Sound
  • Clipping region

Some other features:

  • The bitmap can be stretched to any position on the button rectangle.
  • The caption can be drawn anywhere on the button
  • Many others options are available; just see the demo and the documents.
  • Button types include: push, radio, check, push-like for check and radio buttons.
  • Buttons can be rounded rectangles.
  • The focus can alter colors in more of the classic rectangle.
  • Use 2 transparent colors for bitmap and clipping regions. It can have different bitmaps while maintaining the same custom clipping region.

Using the code

All FxButton initialization methods start with SetFx, which is a great help when you make your button. Here's an example to show how simple it can be.

Let's say your button is called myButton.

// Init text
// Init bitmap
// Init background color
// Create the button

Of interest is that the SetFx methods allow developers to set the values for the 4 button states. Almost all SetFx methods have this same rule. Here is one example to set the text:

SetFxText(CString Normal="", bool Duplicate=true,
    CString Pushed="", CString Over="", CString Disabled="");
The Normal, Pushed, Over and Disabled states are the text values for each button state. Duplicate indicates if the Normal value is to be applied to other button states if they are not set. The best way to test a button state is to set its text like:

myButton.SetFxText("Normal", true, "Pushed", "Over", "Disabled");

Now just play with mouse to see the text change.

This one has no text in its normal state, but silently tells you when the mouse is over it, thanks you when clicked, and it hates being disabled. This "silent notification" text button is:

myButton.SetFxText("", false, "Thanks", "Click me !", "Oh No !");

Now you can apply all the SetFx methods in the same way. Here is the SetFx methods list:

Button Sets














These SetFx methods initialize the data members. To avoid too many data members, they are stored in structures which are:


Only the 9 data members help performance. See the documentation for more details about them.

Points of Interest

As shown in the demo, the button can be entirely recreated. Since the clipping regions, bitmaps, colors, captions, etc., can easily be modified, this class could implement a skined application. Another interesting point is the facility to recreate a button. The FxButton class allows developers to change the button bitmaps and clipping regions easily.


    November 2003 : First update
    Fix bug
    application crashes - Bitmap drawing anywhere etc...

    No need to Invalidate if you change the text or style or color etc...


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

Software Developer (Junior)
France France
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionFast clicking on a "check box push button" sometimes makes the GetCheck function to return a incorrect answer. Pin
Sunny127025-Jun-12 20:37
memberSunny127025-Jun-12 20:37 
AnswerRe: Fast clicking on a "check box push button" sometimes makes the GetCheck function to return a incorrect answer. Pin
RichardV26-Jun-12 6:52
memberRichardV26-Jun-12 6:52 
GeneralRe: Fast clicking on a "check box push button" sometimes makes the GetCheck function to return a incorrect answer. Pin
Sunny127026-Jun-12 18:40
memberSunny127026-Jun-12 18:40 
GeneralRe: Fast clicking on a "check box push button" sometimes makes the GetCheck function to return a incorrect answer. Pin
RichardV28-Jun-12 11:05
memberRichardV28-Jun-12 11:05 
QuestionCan not enter the Function:void CFxButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) Pin
lablas6-Mar-11 22:34
memberlablas6-Mar-11 22:34 
AnswerRe: Can not enter the Function:void CFxButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) Pin
RichardV8-Mar-11 1:29
memberRichardV8-Mar-11 1:29 
GeneralNo text in buttons in windows vista Pin
sirnoname12-Jun-08 11:18
membersirnoname12-Jun-08 11:18 
QuestionHow can enable button with Enter Pin
zit_gir26-Oct-05 0:40
memberzit_gir26-Oct-05 0:40 
GeneralActive with enter Pin
zit_gir23-Oct-05 22:21
memberzit_gir23-Oct-05 22:21 
GeneralBug Report Pin
liuhoihing27-Nov-03 19:48
memberliuhoihing27-Nov-03 19:48 
GeneralRe: Bug Report Pin
RichardV28-Nov-03 6:55
memberRichardV28-Nov-03 6:55 
GeneralRe: Bug Report Pin
liuhoihing28-Nov-03 14:56
memberliuhoihing28-Nov-03 14:56 
GeneralCFxButton and CFormView Pin
AurCe4-Nov-03 4:25
memberAurCe4-Nov-03 4:25 
GeneralRe: CFxButton and CFormView Pin
RichardV8-Nov-03 11:37
memberRichardV8-Nov-03 11:37 
GeneralSetFXBitmapTransparentColor1 does not work for me... Pin
tlee_HK29-Jul-03 18:34
membertlee_HK29-Jul-03 18:34 
GeneralRe: SetFXBitmapTransparentColor1 does not work for me... Pin
RichardV25-Aug-03 0:41
memberRichardV25-Aug-03 0:41 
Generalcool Pin
shanila6-Jul-03 14:56
membershanila6-Jul-03 14:56 
GeneralCreate in runtime Pin
azprivat12-Jun-03 23:14
memberazprivat12-Jun-03 23:14 
GeneralRe: Create in runtime Pin
RichardV16-Jun-03 10:27
memberRichardV16-Jun-03 10:27 
Generaluhm.. Pin
ector1-Feb-03 2:53
memberector1-Feb-03 2:53 
GeneralRe: uhm.. Pin
RichardV2-Feb-03 23:48
memberRichardV2-Feb-03 23:48 
GeneralInvalid Archive Pin
Steve McLenithan31-Jan-03 7:37
memberSteve McLenithan31-Jan-03 7:37 
GeneralRe: Invalid Archive Pin
RichardV3-Feb-03 6:45
memberRichardV3-Feb-03 6:45 
Questionwow, is there more to the button? Pin
Chopper30-Jan-03 23:31
memberChopper30-Jan-03 23:31 
AnswerRe: wow, is there more to the button? Pin
RichardV3-Feb-03 6:52
memberRichardV3-Feb-03 6:52 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04-2016 | 2.8.180318.3 | Last Updated 25 Nov 2003
Article Copyright 2003 by RiriOnTheWeb
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid