Click here to Skip to main content
15,891,783 members
Articles / Desktop Programming / MFC
Article

Image Button Control

Rate me:
Please Sign up or sign in to vote.
3.46/5 (42 votes)
27 Mar 2003 202K   5.5K   73   20
Image Button Control MFC Class ( CImageButton )

Sample Image - CImageButton.jpg

Class header file

CImageButton class info :

class CImageButton : public CButton
{
// Construction
public:
 CImageButton();

 enum {
    TEXT_INCLUDE      = 0x0001, 
    IMAGE_RIGHT      = 0x0002,
    IMAGE_VCENTER     = 0x0004,
    IMAGE_BOTTOM      = 0x0008,
    IMAGE_HCENTER     = 0x0010,
    FOCUS_TEXTONLY    = 0x0020,
    }; 
// Attributes
public: 
// Operations
public: 
// Overrides
 // ClassWizard generated virtual function overrides
 //{{AFX_VIRTUAL(CImageButton)
 public:
 virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
 //}}AFX_VIRTUAL 
// Implementation
public:
 void SetTextColor( COLORREF color );
 BOOL SetAlignStyle( DWORD dwStyle );
 BOOL SetButtonImage( UINT uiImageID , COLORREF  clrMask );
 virtual ~CImageButton(); 
 // Generated message map functions
protected: 

 void ReCalculateSettings(); 

 COLORREF    m_clrMask;
 CBitmap     m_bitmapImage;
 BITMAP      m_bitmap;
 HBITMAP     m_hbmpDisabled;
 CImageList m_ImageList;
 BOOL        m_bLoaded; 
 DWORD       m_dwAlign;   //View Style 

 CRect       m_RectImage;
 CRect       m_RectText;
 CRect       m_RectTextFocus; 
 COLORREF    m_clrText;       //Text Color
 
 //{{AFX_MSG(CImageButton)
 afx_msg void OnSetFocus(CWnd* pOldWnd);
 afx_msg void OnSysColorChange();
 afx_msg void OnSize(UINT nType, int cx, int cy);
 afx_msg void OnEnable(BOOL bEnable);
 //}}AFX_MSG 
 DECLARE_MESSAGE_MAP()
}; 

Class Usage

Here is some sample code to show you how to use the class.

CImageButton m_Button; 
m_Button.SetTextColor( RGB( 200 , 0 , 0 ) );
m_Button.SetAlignStyle( CImageButton::FOCUS_TEXTONLY |  
    CImageButton::TEXT_INCLUDE |   CImageButton::IMAGE_RIGHT | 
    CImageButton::IMAGE_VCENTER );
 m_Button.SetButtonImage( IDB_BITMAP1 , RGB( 255 , 0 , 255 ) ); 

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


Written By
Software Developer
Turkey Turkey
I'm working as a software developer in a local software company. My firm is a special solution company. This is work about different projects. Some friends thinking it is amazing. Smile | :) ))

Comments and Discussions

 
QuestionChange background color of CImagebutton Pin
Member 1278531716-Jun-20 23:35
Member 1278531716-Jun-20 23:35 
Generalit does a specific job and it does it well enough Pin
philipcunningham10-Jan-10 12:24
philipcunningham10-Jan-10 12:24 
GeneralNice one! Pin
softwaremonkey25-Sep-06 17:05
softwaremonkey25-Sep-06 17:05 
Well done! This control works really well and despite earlier criticism, the code does not require or justify an 'article' - just a few minutes thought from the potential user. I for one would not like to have missed out on this nice piece of code simply because it wasn't backed up with a page or two of unnecessary text. Cool | :cool:

Good work!
QuestionHow deep the bitmap? Pin
Do Manh Hung20-May-05 16:10
Do Manh Hung20-May-05 16:10 
GeneralI like it Pin
luftwaffe1-Apr-04 20:03
luftwaffe1-Apr-04 20:03 
GeneralIt has no comments but.. Pin
meeths4-Jan-04 11:42
meeths4-Jan-04 11:42 
GeneralDon't be so harsh Pin
armentage5-Jun-03 10:51
armentage5-Jun-03 10:51 
GeneralRe: Don't be so harsh Pin
Christian Graus5-Jun-03 11:38
protectorChristian Graus5-Jun-03 11:38 
GeneralYou are lazy people! Pin
e-sushi14-Apr-03 9:38
e-sushi14-Apr-03 9:38 
GeneralRe: You are lazy people! Pin
razankbj6113-Feb-05 19:17
razankbj6113-Feb-05 19:17 
GeneralRe: You are lazy people! Pin
Tess Durbeyfield10-Oct-05 0:25
Tess Durbeyfield10-Oct-05 0:25 
GeneralThis effort is lacking!! Pin
WREY4-Apr-03 23:31
WREY4-Apr-03 23:31 
GeneralRe: This effort is lacking!! Pin
kicknfast3-Aug-03 9:46
kicknfast3-Aug-03 9:46 
GeneralRe: This effort is lacking!! Pin
WREY3-Aug-03 13:07
WREY3-Aug-03 13:07 
GeneralRe: This effort is lacking!! Pin
kicknfast3-Aug-03 15:06
kicknfast3-Aug-03 15:06 
GeneralRe: This effort is lacking!! Pin
WREY3-Aug-03 19:18
WREY3-Aug-03 19:18 
GeneralRe: This effort is lacking!! Pin
kicknfast3-Aug-03 21:21
kicknfast3-Aug-03 21:21 
GeneralHmmm... Pin
David Stone29-Mar-03 6:29
sitebuilderDavid Stone29-Mar-03 6:29 
GeneralNo, no ,no! Not again! Pin
Rickard Andersson2029-Mar-03 6:07
Rickard Andersson2029-Mar-03 6:07 
GeneralArticle Text Pin
John M. Drescher28-Mar-03 8:50
John M. Drescher28-Mar-03 8:50 

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.