Click here to Skip to main content
15,880,392 members
Articles / Desktop Programming / MFC
Article

CWBButton - Resizable Bitmap Button

Rate me:
Please Sign up or sign in to vote.
4.30/5 (7 votes)
2 Jun 2000 157.6K   6.9K   68   11
CWBButton is a resizable bitmap button like GTK+ or Window Blinds.
  • Download source files - 8 Kb
  • Download demo project - 37 Kb
  • Sample Image - CWBButton.jpg

    Introduction

    CWBButton is a 'WindowBlinds' like resizable image button derived from a CButton. In MFC, You can use the class called CBitmapButton, but that's not enough. The size of button is the size of the bitmap, and you can't put a text by calling the API SetWindowText(). I wanted REAL Bitmap Button like GTK+ or WindowBlinds. So I try to create a REAL Bitmap Button referring WindowBlinds.


    How to Use

    Using CWBButton is simple.

    1. Add Files to your project. WBButton.h, WBButton.cpp, AutoFont.h, AutoFont.cpp
    2. To the Dialog's header file: #include "WBButton.h"
    3. Create a button on your dialog, and make sure you turn on the "Owner Draw" property.
    4. Inside the Dialog class: CButton m_btn1 to CWBButton m_btn1
    5. Initialize the CWBButton in the event handler OnInitDialog() as described below:
      m_btn1.LoadBitmaps
      (
         IDB_BITMAP1,  // Bitmap resource ID
         5,            // Num of Bitmaps
         15,           // TopHeight
         6,            // BottomHeight
         15,           // LeftWidth
         8             // RightWidth
      );

    To initialize correctly, you know how to be implemented in the WindowBlinds. Each rectangle lead by LeftWidth, RightWidth, TopHeight, and BottomHeight is static, and not stretched. The others are stretched by the size of button. So you can get natural button images. It may be difficult to set the parameters correctly, but you can refer the Initialize file of WindowBlinds, which name is '*.uis', on the section '[Buttons]'.


    Notes

    1. The bitmap you load should be separate at least four parts. The First is 'Normal' state, the second is 'Select' state, the Third is 'Disable' state, and the fourth is 'Focus' state.
    2. To transparent the button, the bitmap background color should be RGB(255,0,255), also you can change the transparent color by calling the function SetBackColor()

    Problems

    I tested this source on the Japanese version VC6.0 and Windows. Problems may occur on other language environments.

    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
    Japan Japan
    This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

    Comments and Discussions

     
    GeneralThanks! Pin
    Vincent-Lin31-Jul-07 19:49
    Vincent-Lin31-Jul-07 19:49 
    GeneralWM_ERASEBKGN Pin
    AndrianG1-Mar-07 9:56
    AndrianG1-Mar-07 9:56 
    QuestionWhats the fifth bitmap state for ? Pin
    ChrisRibe12-Dec-06 4:28
    ChrisRibe12-Dec-06 4:28 
    Generaldialog Bk color Pin
    nmg4-Dec-03 19:42
    nmg4-Dec-03 19:42 
    Good work but one question:

    what can I do
    if my dlg have a different background color ?
    Rounded corner of buttons apear in gray. How can I fix this ?

    Thanx
    Generalhum... Pin
    kim jyeong hyeon1-Dec-03 22:20
    kim jyeong hyeon1-Dec-03 22:20 
    Generaldisable/enable Pin
    yary19-Dec-02 1:37
    yary19-Dec-02 1:37 
    GeneralOwnerDraw Pin
    MaTrIX2k211-Feb-02 21:32
    MaTrIX2k211-Feb-02 21:32 
    GeneralAny Other Controls Pin
    Matt Newman4-Jul-01 8:11
    Matt Newman4-Jul-01 8:11 
    GeneralComments... Pin
    Orlando L16-Jun-00 6:11
    Orlando L16-Jun-00 6:11 
    GeneralRe: Comments... Pin
    15-Nov-00 21:30
    suss15-Nov-00 21:30 
    GeneralRe: Comments... Pin
    Davide Calabro3-May-01 7:40
    Davide Calabro3-May-01 7:40 

    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.