Dave's Brain

Browse - programming tips - mfc bitmap buttons

Date: 2008sep7
Platform: MFC
Language: C/C++

Q.  How do I make bitmap buttons with MFC?

A.  Make the button style BS_BITMAP and BS_OWNERDRAW.
Many other instructions out there don't mention BS_OWNERDRAW --
it essential.  This means it can not be a default button.
For example:

	CONTROL "",IDOK,"Button",BS_OWNERDRAW | BS_BITMAP, 10,10,100,100

Import at least 2 bitmaps as resources.

	IDB_OK                  BITMAP  DISCARDABLE     "res\\ok.bmp"
	IDB_OK_PRESSED          BITMAP  DISCARDABLE     "res\\ok_pressed.bmp"

The bitmaps can be more than 256 colors.

In your class declare it as CBitmapButton.  Like this:

	CBitmapButton	m_OK;

In your InitDialog routine do:

	m_OK.LoadBitmaps(IDB_OK, IDB_OK_PRESSED);

You can add more bitmaps for other states.
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2012, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.
Advertisements: