Bitmaps on Command Button using CBitmapButton

CoderSource.net
Bitmaps on Command Button using CBitmapButton
Rating:

Date: 5/1/2004 12:00:00 AM

   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.

 

You Can Rate this Article, if you are Logged In      
 

More Links from CoderSource.net:

 
Refer to a Friend:

Your Details:

Name:     e-mail:

Friend Details:

Name:    e-mail:    


MENU
Home
MFC 
C++
.Net
WIN32
Programming
Forum
My Articles
Add to Google
Add to My Yahoo!
Welcome to Codersource.Net Login | Register | Faq  

SEARCH
Google
 

NOTES:


Thanks for visiting our CoderSource.net. This site will be improved with more articles. Interested visitors can also submit their articles through the Submit Article link.Your article will also be published after due consideration by the editor. 

© Copyright 2003. All rights on content reserved by CoderSource.net. Contact    About Us