Click here to Skip to main content
11,933,180 members (62,774 online)
Click here to Skip to main content
Add your own
alternative version


82 bookmarked

Transparant Image Button (BMP, GIF, JPG...)

, 31 Oct 2004
Rate this:
Please Sign up or sign in to vote.
Using transparant image button~!

Sample Image - CKbcButton.jpg


*I'm not good at English, but if you can understand my story, isn't that enough? Smile | :)

When I made this application, especially as dialog based, a lot of buttons were used. Buttons are very important things in my situation. So I decided to make an Image button source.

As you know, there are many sources for image buttons. I think it's useless work making another image button. But those image buttons have a small problem.

intro - a small problem

In this image, button's background hides the parent's background. That's not what I want. So I am going to handle this problem.

Using the code

There are two ways using this button. First of all, include the following files to your project:

  • KbcBmp.h,
  • KbcBmp.cpp,
  • KbcButton.h,
  • KbcButton.cpp,
  • Picture.h,
  • Picture.cpp

Then, let's start~!

  1. Using DDX_Control
    1. Include "KbcButton.h" in header file.
    2. Declare a CKbcButton variable in header file.
    3. Go to dialog resource and draw a button. Check 'Onwer draw' style.
    4. Use DDX_Control like this in CPP file: DDX_Control(pDX, IDC_PLAYBUTTON, m_btnPlay);
    5. Then set button's image by calling SetButtonImage() function.
      // In your header file
      #include "KbcButton.h"
      class CTestButtonDlg : public CDialog
           CKbcButton  m_btnPlay;
      // in you cpp file
      void CTestButtonDlg::DoDataExchange(CDataExchange* pDX)
           DDX_Control(pDX, IDC_PLAYBUTTON, m_btnPlay);
      BOOL CTestButtonDlg::OnInitDialog()
           // set button image..
  2. Using new operation
    1. Include "KbcButton.h" in header file.
    2. Declare a CKbcButton* variable in header file.
    3. Create CKbcButton instance by using new operator.
    4. Call Create() function.
    5. Then set button's image by calling SetButtonImage() function.
      // In your header file
      #include "KbcButton.h"
      class CTestButtonDlg : public CDialog
           CKbcButton*  m_pButton;
      // in you cpp file
      BOOL CTestButtonDlg::OnInitDialog()
           // create button and set button image..
           CRect rtButton;
           CWnd* pWnd = GetDlgItem(IDC_STATIC_SHOW);
           m_pButton = new CKbcButton;
           m_pButton->Create("CKbcButton", WS_CHILD|WS_VISIBLE|BS_OWNERDRAW, 
                                 rtButton, this, NEWBUTTON);

That's all. Isn't it simple?

Make sure that you set 'Owner draw style' to a button.


Thanks to Dr. Yovav Gad (CPicture's author) and The Code Project. Smile | :) I learned a lot of things from this site.


  • Ver 1.0 (11/01/2004)
    • Used CPicture class supporting JPG, GIF...
    • Fixed cursor problem.


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

ByeongChan Gwak
Web Developer
Korea (Republic Of) Korea (Republic Of)
student of Pohang University of Science and Technology.

You may also be interested in...

Comments and Discussions

GeneralUnicode Pin
Sunny12702-Jan-11 5:43
memberSunny12702-Jan-11 5:43 
Questiongif????????????? Pin
batsword8-Sep-10 16:41
memberbatsword8-Sep-10 16:41 
GeneralToolTip does not appear Pin
MohamadElHajj27-Mar-09 8:19
memberMohamadElHajj27-Mar-09 8:19 
QuestionTransparancy doesn't work on CDHtmlDialog ? Pin
lambertwm10-Apr-08 22:10
memberlambertwm10-Apr-08 22:10 
Generaloh,very very good!!! Pin
wsb_82246-Jun-07 0:29
memberwsb_82246-Jun-07 0:29 
GeneralRe: oh,very very good!!! Pin
logi00116-Dec-09 1:29
memberlogi00116-Dec-09 1:29 
GeneralRe: oh,very very good!!! Pin
batsword8-Sep-10 16:35
memberbatsword8-Sep-10 16:35 
GeneralZqrTalent Pin
Zaqro20-Mar-07 9:19
memberZaqro20-Mar-07 9:19 
Generala note when using VS2005 Pin
rincle30-May-06 0:44
memberrincle30-May-06 0:44 
QuestionHow to hide the white line on the button circle Pin
liaohaizhou11-Apr-06 20:00
memberliaohaizhou11-Apr-06 20:00 
AnswerRe: How to hide the white line on the button circle Pin
ywlee05212-May-06 9:41
memberywlee05212-May-06 9:41 
Generalvery good ,but how to use Resource 'bmp Pin
xnetec13-Dec-05 6:38
memberxnetec13-Dec-05 6:38 
GeneralRe: very good ,but how to use Resource 'bmp Pin
vbachmut10-Feb-06 8:27
membervbachmut10-Feb-06 8:27 
GeneralVery good Pin
Einst13-Oct-05 0:17
memberEinst13-Oct-05 0:17 
GeneralRe: Very good Pin
kbckbc15-Oct-05 21:13
memberkbckbc15-Oct-05 21:13 
GeneralRe: Very good Pin
Einst30-Oct-05 23:00
memberEinst30-Oct-05 23:00 
GeneralNice, but half done Pin
AliRafiee18-Jul-05 11:07
memberAliRafiee18-Jul-05 11:07 
GeneralRe: Nice, but half done Pin
kbckbc15-Oct-05 21:09
memberkbckbc15-Oct-05 21:09 
GeneralRe: Nice, but half done Pin
Xia Xiongjun4-Sep-06 14:35
memberXia Xiongjun4-Sep-06 14:35 
General"Unsupported operation" error Pin
Anarchi22-Apr-05 1:52
memberAnarchi22-Apr-05 1:52 
GeneralRe: "Unsupported operation" error Pin
Mohamed_Bakr22-May-06 0:21
memberMohamed_Bakr22-May-06 0:21 
AnswerRe: "Unsupported operation" error Pin
DennisMattingly10-May-07 5:51
memberDennisMattingly10-May-07 5:51 
GeneralRe: "Unsupported operation" error Pin
zorrothefox29-Nov-07 0:15
memberzorrothefox29-Nov-07 0:15 
GeneralRe: "Unsupported operation" error Pin
DennisMattingly29-Nov-07 4:38
memberDennisMattingly29-Nov-07 4:38 
Generalit's miracle!! this is only thing to want. Pin
reinkorea31-Oct-04 15:08
memberreinkorea31-Oct-04 15:08 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.151126.1 | Last Updated 31 Oct 2004
Article Copyright 2004 by ByeongChan Gwak
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid