Introduction
Don't be discouraged at the sight of the pictures above. Well, it is
after all, a demo.
This is a class useful to those of my fellow programmers who are tired of the
ever familiar gray rectangles on the screen. Well, here is something that might
give u relief from that... something for a change!!! I had written this code
sometime back and hope some of you will find some use for it.
Ahem… what's the big deal?? Could use CBitmapButton
? Yes
you could but you might have to give 4 different pictures for each state; but not
with CflexiButton
!! You have to give just one pic and voila!! It generates its
own pictures for all the button states! And there is another funny little thing
in there; if you were to change the theme of your system, then the button
will change the button's look in synchrony with the theme. Yes it is a
cool little thing.
Each of the pictures you see on that dialog up there is a button. Each of them
demonstrate a different style of this flexi button. The first one on the left is
a button which changes to the theme color in force in the system. The funny
little up-turned �Next� button is enabled and it represents the active area of
the button exactly. Then the bottom most picture which behaves something like a
normal Bitmap button. Try it and look what happens. The first button gets
disabled. Then finally the �grayed� play picture on top, that is, a �grayed�
play button.
And yes, I have taken help from code project a lot. I had to go through a few
articles and borrow functions from some of them (and fix the bugs) to complete this neat little class.
CXImage
, PictureEx
, WindowBitmap
... to name a few...
thanks to the authors!!
Background
I was programming a mp3 database that works along side my winamp. Then I
thought I'd change the look of the interface from the conventional
rectangles. That's what led me to change the look of the buttons and
thus, the creation of this class.
Using the code
BUTTON EVENTS
#define FB_BTNCLIK WM_USER+111
#define FB_BTNHOVR WM_USER+112
#define FB_BTNLEAV WM_USER+113
PRESETS
#define BTN_PRS_DISP 1
#define FB_CREATEBMPS_SUPPORT 1
BUTTON
STYLES
** Styles used during Bitmap Loading only
#define FBS_ADJUSTTOBMP 0x00000010
** Other Styles
#define FBS_PRESSEFFECT 0x00000001
#define FBS_BLENDSYSCLR 0x00000100
#define FBS_CREATE4ALL 0x00001000
#define FBS_UPDATEBMPS 0x00010000
MEMBER
FUNCTIONS
bool CFlexiButton::EnableWindow(bool bEnable)
bool CFlexiButton::ShowButton(bool bShow)
bool CFlexiButton::ShowButtonRegion(HRGN hRgn)
bool CFlexiButton::DeleteButtonRegion(COLORREF sRef,COLORREF sTol = 0x000000)
bool CFlexiButton::LoadBitmaps (LPCTSTR lpszBitmapResource,
LPCTSTR lpszBitmapResourceSel = NULL,
LPCTSTR lpszBitmapResourceFocus = NULL,
LPCTSTR lpszBitmapResourceDisabled = NULL,
bool bFromFile = 0)
- First bitmap is compulsory, the
disabled bitmap is generated automatically if is is not specified.
- If the
FBS_CREATE4ALL
style is
set, this function will take only the first bitmap and generate images for all
other button states.
- If the
FBS_BLENDSYSCLR
style is
set, then all bitmap colors are blended to the current window frame color.
HWND CFlexiButton::GetWindowHandle()
HWND CFlexiButton::CreateButton (HWND hWnd, int iStyle,
int iButtonID, RECT sRect)
- The
FBS_ADJUSTTOBMP
should be
specified if here if button is to be adjusted accordingly. Removing or adding
this style after this function does not have any effect.
- A resource ID identifying the
Button must be set. And the bounding rectangle of the button i.e., the
coordinates must be in relation to the client area of the parent window.
- If u specify a MFC Button with
handler for the
BN_CLICKED
event, and pass the resource ID of that button to
the CreateButton
Function, the CFlexibutton
will use that handler of that MFC
button. there is no need to trap any event in OnCommand
of the parent window.
I hope the above description of the
methods will make things clear to most of you. Feel free to contact me if you
have any trouble.
#include "FlexiButton.h"
using namespace C001_FlexButton;
CFlexiButton oFButton;
oR.left = 200;
oR.top =250;
oR.bottom = 400;
oR.right = 300;
if(!oFButton4.CreateButton(m_hWnd,FBS_ADJUSTTOBMP,IDC_FLEXBUTTON4,oR))
return 0;
if(!oFButton4.LoadBitmaps("wire13.bmp","wire12.bmp","wire1.bmp","wire14.bmp",1))
return 0;
oFButton4.ShowButton(1);
The above is the code to create the button on the bottom of the dialog in
the picture above. Remember there are some more styles provided by this class.
Points of Interest
Oh yes... you just might find some non-intentional interesting behaviour
while using this class, please let me know about it. I was considering writing
a log file... for a button control?? NAAAAY!!!!
History
This is my first submit to code project or any programmer�s site for that
matter; I'll
call it... Ummmm... CFlexiButton
No.1.0.