Click here to Skip to main content
Click here to Skip to main content
Go to top

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

Introduction

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)

Limitations

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
myButton.SetFxText("Ok");
myButton.SetFxTextFont("Arial");
// Init bitmap
myButton.SetFxBitmap("IDB_BITMAP1");
myButton.SetFxBitmapTransparentColor1(RGB(0,255,0));
// Init background color
myButton.SetFxBkcolor(RGB(100,100,100));
// Create the button
myButton.FxCreateButton();

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

SetFxClippingMode
SetFxClippingColor1
SetFxClippingColor2

Background

SetFxBkColor
SetFxBkColorMode

Borders

SetFxBorderSize
SetFxBorderColorMode
SetFxBorderEffect

Bitmap

SetFxBitmap
SetFxBitmapRect
SetFxBitmapPosition
SetFxBitmapTransparentColor1
SetFxBitmapTransparentColor2
SetFxBitmapTransparentMode
SetFxBitmapEffect

Text

SetFxText
SetFxTextRect
SetFxTextPosition
SetFxTextFont
SetFxTextSize
SetFxTextColor
SetFxTextStyle
SetFxTextEffect

Media

SetFxSound
SetFxCursor
SetFxSystemCursor

Tooltip

SetFxToolTip

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

m_Background
m_Bitmap
m_Border
m_Text
m_Focus
m_Media
m_ToolTip
m_Button
m_Control

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.

History

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

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

License

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

Share

About the Author

RiriOnTheWeb
Software Developer (Junior)
France France
No Biography provided

Comments and Discussions

 
QuestionFast clicking on a "check box push button" sometimes makes the GetCheck function to return a incorrect answer. PinmemberSunny127025-Jun-12 20:37 
AnswerRe: Fast clicking on a "check box push button" sometimes makes the GetCheck function to return a incorrect answer. PinmemberRichardV26-Jun-12 6:52 
GeneralRe: Fast clicking on a "check box push button" sometimes makes the GetCheck function to return a incorrect answer. PinmemberSunny127026-Jun-12 18:40 
GeneralRe: Fast clicking on a "check box push button" sometimes makes the GetCheck function to return a incorrect answer. PinmemberRichardV28-Jun-12 11:05 
QuestionCan not enter the Function:void CFxButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) Pinmemberlablas6-Mar-11 22:34 
AnswerRe: Can not enter the Function:void CFxButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) PinmemberRichardV8-Mar-11 1:29 
GeneralNo text in buttons in windows vista Pinmembersirnoname12-Jun-08 11:18 
QuestionHow can enable button with Enter Pinmemberzit_gir26-Oct-05 0:40 
GeneralActive with enter Pinmemberzit_gir23-Oct-05 22:21 
GeneralBug Report Pinmemberliuhoihing27-Nov-03 19:48 
GeneralRe: Bug Report PinmemberRichardV28-Nov-03 6:55 
GeneralRe: Bug Report Pinmemberliuhoihing28-Nov-03 14:56 
GeneralCFxButton and CFormView PinmemberAurCe4-Nov-03 4:25 
GeneralRe: CFxButton and CFormView PinmemberRichardV8-Nov-03 11:37 
GeneralSetFXBitmapTransparentColor1 does not work for me... Pinmembertlee_HK29-Jul-03 18:34 
GeneralRe: SetFXBitmapTransparentColor1 does not work for me... PinmemberRichardV25-Aug-03 0:41 
Generalcool Pinmembershanila6-Jul-03 14:56 
GeneralCreate in runtime Pinmemberazprivat12-Jun-03 23:14 
GeneralRe: Create in runtime PinmemberRichardV16-Jun-03 10:27 
Generaluhm.. Pinmemberector1-Feb-03 2:53 
GeneralRe: uhm.. PinmemberRichardV2-Feb-03 23:48 
GeneralInvalid Archive PinmemberSteve McLenithan31-Jan-03 7:37 
GeneralRe: Invalid Archive PinmemberRichardV3-Feb-03 6:45 
Questionwow, is there more to the button? PinmemberChopper30-Jan-03 23:31 
AnswerRe: wow, is there more to the button? PinmemberRichardV3-Feb-03 6:52 

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 25 Nov 2003
Article Copyright 2003 by RiriOnTheWeb
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid