Bitmaps on Command Button using CBitmapButton

   CBitmapButton class provided by MFC can be used to place bitmaps on command buttons. It allows up to four bitmaps to be placed on the command button depending on the button's state viz., Normal, Selected, Focused and Disabled.

Bitmap Button on a Dialog - CBitmapButton:

   The following steps explain how to place a bitmap button on the dialog using CBitmapButton.

  1. Create an MFC Dialog based application or a normal SDI or MDI MFC application with a dialog box.
  2. Place a Command Button on the dialog. This sample assumes the id of the command button as ID_BITMAP_BUTTON_SAMPLE.
  3. In the Properties dialog --> Styles tab, set the Owner Draw style to TRUE. i.e., keep the check box in checked state. This enables Windows to send WM_DRAWITEM and WM_MEASUREITEM messages for the bitmap button.
  4. Create a bitmap resource using the Menu --> Insert  --> Resource --> Bitmap.
  5. Open the Class Wizard by pressing Ctrl + W key combination or Menu --> View --> ClassWizard.
  6. In the Member Variables tab, Add a member for ID_BITMAP_BUTTON_SAMPLE with the control class as CButton. The sample assumes the variable name as m_bmpSample;
  7. In the SampleDialog.H file, modify the CButton m_bmpSample declaration as CBitmapButton m_bmpSample.
  8. In the OnInitDialog function call the LoadBitmaps function, a member of CBitmapButton.
  9. m_bmpSample.LoadBitmaps(IDB_BITMAP1);

  10. The function can accommodate upto 4 bitmaps depending on the state of the command button.
  11. Build and run the application. The bitmap will be loaded on the command button.

 

Close    To Top
  • Prev Article-Programming:
  • Next Article-Programming:
  • Now: Tutorial for Web and Software Design > Programming > c > Programming Content
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Geek Tutorial
     

    Blogging Tutorial

      RSS Tutorial
      Podcasting Tutorial
    Graphic Design Tutorial
      Coreldraw Tutorial
      Illustrator Tutorial
      3D Tutorials
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial/ Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial/ Articles
     

    XML Style

      AJAX Tutorial
      XML Mobile
    Flash Tutorial/ Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial/ Articles
      Linux Tutorial
      Symbian Tutorial
      MacOS Tutorial
    Personal Tech
      Hardware Tutorial
      Software Tutorial
      Online Auction