CBitmapButton uses CBitmapButton as the control class of the MFC, not for many people because it is now spread on all kinds of buttons derived from CButton, where the most famous is the CButtonst class. But recently I saw a few questions in 9CBS are class of CBitmapButton, but due to improper use of errors, the program crashes or errors. So summarize the use of the CBitmapButton class, I hope to help some beginners. You can refer to the example of "Ctrltest" to learn CBitmapButton with the example of the MSDN. Personal summary is as follows: 1. When the resource editor is selected, the OWNER DRAW of the button can be selected, and does not need to select the bitmap attribute! 2. Define a CBITMAPBUTTON member variable in the program. You can't use ClassWizard to map a cbutton variable, then change to CBitmapButton, do not map the button directly into the object of the CBitmapButton class, but initialization error occurs. 3-1, using CBitmapButton :: LoadBitmaps to load pictures of various states, use subclassdlgitem to associate the desired button, use the cbitmapButton :: SizeTOTENT function to make the button to fit the picture size. . Note that loadbitmaps must be done before the button is associated! 3-2, or use the CBitmapButton :: AutoLoad function to associate the desired button. Need to note: a, you cannot use the CBITMAPBUTTON:: Loadbitmaps to load a picture of the various states, otherwise it will be wrong. B, the AutoLoad function completes the ability to change the CBitmapButton :: SizeTOTONTENTON :: SizeToContent function of the button size. C, CBitmapButton :: AutoLoad is the default resource ID, that is, it automatically loads the relevant resource bitmap. The bitmap resource ID format is: "Buttons Caption U", "Buttons Caption D", "Buttons Caption X", represents Up, Down, Focus, and Disable. If the resource editing, the CAPTION of the button wants to be associated is TEST, then its default loaded bitmap resource ID is: "Testu" / "testd" / "testf" / "testx", pay attention to the semicolon "" also Id a part of
When used in VC6, declare the CBITMAPBUTTON object in the header file, use it in the CPP, otherwise an error will occur.
: CDialog (CBMTest1Dlg :: IDD) {// NOTE:.! The obsolete MFC V1 CBitmapButton constructor with 3 arguments is // replaced by a call to LoadBitmaps if (button1.LoadBitmaps (_T ( "Image1Up"), _T ( "Image1Down "), _T (" image1focus ") ||! Button2.loadbitmaps (_T (" image2up "), _t (" image2down "), _t (" image2focus ")) {trace0 (" Failed to load bitmaps for button / N "); AfXTHROWRESOURCEEXCEPTION ();}}
BOOL CBMTest1Dlg :: OnInitDialog () {// each dialog control has special bitmaps VERIFY (button1.SubclassDlgItem (IDOK, this)); button1.SizeToContent (); VERIFY (button2.SubclassDlgItem (IDCANCEL, this)); button2.SizeToContent ( Return True;}