• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 792
  • Last Modified:

Bitmap Button

hi guys,

can anyone help me with CBitmapButton?

question:
I have a bitmap image which i want to map on to a button in a dialog box. a bitmap image should be displayed on the button instead of text.

thanx for ur help
krithi
0
krithi
Asked:
krithi
1 Solution
 
KurtVonCommented:
I'm not sure what you mean.  Using CBitmapButton on a dialog do the following:

Add the bitmap to your dialog resource.  Make sure it is set to owner draw.

Add the bitmap itself to your resources.

Add the OnInitDialog function and a CBitmapButton object to the dialog object.  In OnInitDialog add

m_cBitmapButton.LoadBitmap(IDC_BUTTON_BITMAP);
m_cBitmapButton.SubclassDlgItem(IDC_BUTTON_ID, this);

If you have the bitmap in a CBitmap, you have to use an owner draw button and draw it yourself.
0
 
zfactCommented:
Hi Kirthi,

See MSDN. I am pasteing few examples found in the MSDN. Go through it.


-----------------------------------------------------------
//CButton::SetBitmap

Example
CButton myButton;

// Create a bitmap button.
myButton.Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_BITMAP,
   CRect(10,10,60,50), pParentWnd, 1);

// Set the bitmap of the button to be the system check mark bitmap.
myButton.SetBitmap( ::LoadBitmap(NULL, MAKEINTRESOURCE(OBM_CHECK)) );
-----------------------------------------------------------

//CButton::GetBitmap

Call this member function to get the handle of a bitmap, previously set with SetBitmap, that is associated with a button.

HBITMAP GetBitmap( ) const;
Return Value
A handle to a bitmap. NULL if no bitmap is previously specified.

Example
CButton myButton;

// Create a bitmap button.
myButton.Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_BITMAP,
   CRect(10,10,60,50), pParentWnd, 1);

// If no bitmap is defined for the button, define the bitmap to the
// system close bitmap.
if (myButton.GetBitmap() == NULL)
   myButton.SetBitmap( ::LoadBitmap(NULL, MAKEINTRESOURCE(OBM_CLOSE)) );
----------------------------------------------------------
//CBitmapButton::LoadBitmaps

CBitmapButton myButton;

// Create the bitmap button (must include the BS_OWNERDRAW style).
myButton.Create(NULL, WS_CHILD|WS_VISIBLE|BS_OWNERDRAW,
   CRect(10,10,100,100), pParentWnd, 1);

// Load the bitmaps for this button.
myButton.LoadBitmaps(IDB_UP, IDB_DOWN, IDB_FOCUS, IDB_DISABLE);
-----------------------------------------------------------

Try It, All The Best
Zfact
0
 
sreenu_v78Commented:
hai krithi

if u want set bitmap for button change button style BITMAP
create BitMap using resource.

write this code

     CButton *but=(CButton*)GetDlgItem(IDC_BUTTON1);

     CBitmap *bit=new CBitmap;
     bit->LoadBitmap( IDB_BITMAP1);
     
     but->SetBitmap((HBITMAP)bit->m_hObject);


if u want change bitmap dynamically go thru this link what i answer previously..

http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_20519121.html

best wishes..
sreenu.

sreenu_v78@yahoo.com

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now