Click here to Skip to main content
12,950,399 members (64,958 online)
Click here to Skip to main content
Add your own
alternative version


50 bookmarked
Posted 22 May 2004


, 22 May 2004
Rate this:
Please Sign up or sign in to vote.
Bitmap button which embeds text on it.

Sample Image - CImageTextButton.jpg


Hello guys... Are you looking for a special button?? Then take it :-). I'm Just kidding.. Now, coming to the point, the inspiration to upload this article is, since I didn't get proper solution from the net to show "Text" at a specified position of a bitmap button. I think you got the problem? Yes, I want to show some buttons which have to load some bitmaps for its up, down and disabled state.. and also want to show some text on it.... Remember, there is CBitmapButton, but this can load bitmaps only, can't show text on it. So, I decided to write a reusable class which does the bitmap loading if the bitmaps are given to the class, also provide some methods to give the needed text for the button. Then comes the coloring issue.. who will color the text, by which color the font of the text shows etc.. So, I decided to give methods to support such points.. And now, I.. no, you have a cool simple working code which can be easily incorporated to your workspace.


  • Loading bitmaps (up, down, disabled state; only up state bitmap is mandatory, others are optional) is possible.
  • Text position can be set in two different ways (can specify x,y position or like DT_CENTER|DT_VCENTER etc.).
  • Text font and font size can be configured for each button.
  • Text color for up, down and disabled can be configured.
  • Button size is resized to the size of the bitmap.

Now, have a look at CImageTextButton?

class CImageTextButton : public CButton
 void SetTextPosition(UINT uiPos );
 void SetTextPosition(int nXPos ,int nYPos);
 void SetTextColor(const COLORREF& clrUpDwn, const COLORREF& clrDisabled );
 void SetButtonText(const CString& strCaption);
 void SetButtonImg(UINT uiImageIDU,UINT uiImgIDD =0,UINT uiImgIDX = 0);
 void SetFont(CString srtFntName_i, int nSize_i);

Function Usage.

  • void SetButtonImg(UINT uiImageIDU,UINT uiImgIDD =0,UINT uiImgIDX = 0);

    Method used to set the bitmaps to be loaded for the button. The order of bitmaps is up-state bitmap, then down-state bitmap, and the last one is disabled bitmap.

  • void SetButtonText(const CString& strCaption);

    Method used to set the caption/text of the button, if the button wants to have any text. If this method is not called, only the bitmap is loaded.

  • void SetTextColor(const COLORREF& clrUpDwn, const COLORREF& clrDisabled );

    Method used for setting the color of the button caption for the button's up, down and disabled states. This is valid only when the SetButtonText() is called.

  • void SetTextPosition(UINT uiPos );

    Method used for setting the text position. The valid unit values are..

    DT_TOP          0x00000000
    DT_LEFT         0x00000000
    DT_CENTER       0x00000001
    DT_RIGHT        0x00000002 
    DT_VCENTER      0x00000004 
    DT_BOTTOM       0x00000008 
    DT_WORDBREAK    0x00000010 
    DT_SINGLELINE   0x00000020

    Any combination of the above flags can be used.

  • void SetTextPosition(int nXPos ,int nYPos);

    Method used for setting the x,y position of the text. If anyone of the SetTextPostion() is not called, then the text will be shown as DT_SINGLELINE|DT_CENTER|DT_VCENTER.

  • void SetFont(CString srtFntName_i, int nSize_i);

    Method used to set the font name and font size of the text. If it's not called, default font with default size is taken to draw the text.

Steps to use the class.

  • Add the ImageTextButton.h & ImageTextButton.cpp files to the workspace.
  • Add #include "ImageTextButton.h" at the include portion of the dialog which wants to have the CImageTextButton, as shown:
    #include "stdafx.h"
    #include "ImageTextButton.h"
  • Declare CImageTextButton objects corresponding to each button as:
    //Adding member variables corresponding to each button
    CImageTextButton m_btnOK;
    CImageTextButton m_btnPlay;
    CImageTextButton m_btnEnable;
    CImageTextButton m_btnStrt;
  • Set the properties needed for the buttons inside the Dialog's OnInitDialog() as:


Don't forget to call SubclassDlgItem() for all the bitmap button members, only after this call will the Windows messages will reach the CImageTextButton at which I played the trick....

Now, it's time to build the application and enjoy the result.

[If any one of you find any problems to use this, please do mail to me ...]


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 (Senior) NeST
India India
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralThis code doesn't run in WinCE... help me.. Pin
hwa38433-Nov-04 17:48
memberhwa38433-Nov-04 17:48 
GeneralImprovements Pin
Michael Heber27-Oct-04 0:11
memberMichael Heber27-Oct-04 0:11 
GeneralLook at it Pin
dowj18-Sep-04 13:18
memberdowj18-Sep-04 13:18 
GeneralUrgent Pin
ankooraga9-Jul-04 23:58
sussankooraga9-Jul-04 23:58 
GeneralUrgent Pin
iipc9-Jul-04 23:56
memberiipc9-Jul-04 23:56 
GeneralCButtonST Pin
Davide Calabro26-May-04 23:50
memberDavide Calabro26-May-04 23:50 
This is the wheel.

Davide Calabro'
GeneralCButtonSSL Pin
armentage24-May-04 4:28
memberarmentage24-May-04 4:28 
GeneralDialog Background color in 1 line code Pin
JOHN1123-May-04 2:32
memberJOHN1123-May-04 2:32 
GeneralRe: Dialog Background color in 1 line code Pin
Ravi Bhavnani23-May-04 4:37
memberRavi Bhavnani23-May-04 4:37 
GeneralPretty Good!! Pin
WREY23-May-04 2:29
memberWREY23-May-04 2:29 

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
Web02 | 2.8.170525.1 | Last Updated 23 May 2004
Article Copyright 2004 by anuragvelekkattu
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid