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
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
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
- Transparent bitmap
- Backscreen bitmap
- 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 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
Let's say your button is called
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="");
states are the text values for each button state.
indicates if the
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
SetFx methods list:
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
application crashes -
Bitmap drawing anywhere etc...
No need to Invalidate
if you change the text or style or color etc...