I checked a lot of information on the Internet, but most of them were not detailed. Today I made a bitmap button for testing. I sorted the information on the Internet as follows:
Cbitmapbutton is an MFC built-in button class that provides the image Button Function and supports displaying different images in different States. Its usage is relatively simple, more beautiful than cbutton, and more concise than other third-party buttons. Therefore, Bitmap Buttons are often used when being made.
Method 1:
1. Select the owner draw attribute of the button during resource editing. You do not need to select the bitmap attribute.
Right-click the button --> styles --> owner draw
2. Define a cbitmapbutton member variable in the program.
Note: you cannot use classwizard to map a cbutton variable for the button and change it to cbitmapbutton,
In this case, buttons cannot be directly mapped to the cbitmapbutton class object, but initialization errors may occur.
3. Use cbitmapbutton: loadbitmaps to load images of various States,
Use cbitmapbutton: subclassdlgitem to associate it with the desired button,
Use the cbitmapbutton: sizetocontent function to make the button fit the image size.
Note that loadbitmaps must be performed before the associated button!
First, select the owner draw attribute of the button and load two *. BMP bitmaps in the resource,
Then add the following to the dialog box:
Cbitmapbutton m_btnx1; <br/> // defines the variable, which must be placed outside the function for normal implementation </P> <p> bool cxxxxxxx: oninitdialog () <br/>{< br/> cdialog: oninitdialog (); </P> <p> 8m_btnx1.loadbitmaps (idb_xxxx_up, idb_xxxx_down ); <br/> // The two bitmaps are displayed. You can press and play the bitmap. <br/> // you can add only one ID resource. <br/> m_btnx1.subclassdlgitem (idc_dasen_x1, this); <br/> m_btnx1.sizetocontent (); <br/>}< br/>
The main difference between this method and method 2 is:
Method 1 do not need to associate the bitmap and button names
In method 2, the bitmap and button must be directly named and associated.
Method 2:
Cbitmapbutton provides the following simple strategy:
1. In the MFC dialog project, add a button in a dialog, Set ID to idc_button_test, caption to button_test, and select the owner draw attribute in the style. (Note the relationship between caption naming and ID naming)
2. Add a button image to the resource.
Assume that the image is as follows:
Button image when test_up.bmp is normal
Button image when test_down.bmp is clicked
Test_focused.bmp
Image after the test_disable.bmp button expires
Set its ID to (note that both the left and right sides must contain double quotation marks)
"Button_testu"
"Button_testd"
"Button_testf"
"Button_tests"
3. Define a cbitmapbutton member variable in the program.
Note: you cannot use classwizard to map a cbutton variable for the button and change it to cbitmapbutton,
In this case, buttons cannot be directly mapped to the cbitmapbutton class object, but initialization errors may occur.
4. In the oninitdialog () function, associate the bitmap with a specific button. Note that the IDs of the associated buttons must comply with the rules 1st and 2.
M_button.autoload (idc_button_test, this );
Note that using this method, you do not need to use loadbitmap () to load resources, because the compiler automatically associates bitmap resources with specific buttons according to naming conventions.
Cbitmapbutton m_button; // It must be placed outside the function for normal implementation <br/> bool cxxxxxxx: oninitdialog () <br/>{< br/> cdialog: oninitdialog (); </P> <p> m_button.autoload (idc_button_test, this); // The caption of the button whose ID is idc_button_test is: button_test}
References:
Http://blog.sina.com.cn/s/blog_44e571d70100080o.html
Http://blog.163.com/yanghua9981@126/blog/static/262925712007623105417327/
Http://www.itqun.net/content-detail/123911.html
Http://www.cnblogs.com/qqingmu/archive/2007/09/06/884840.html
Http://topic.csdn.net/t/20021107/14/1156670.html
Http://blog.csdn.net/hityct1/archive/2009/02/03/3859286.aspx
Http://blog.sina.com.cn/s/blog_4d90492b01000f2h.html