First: Bitmap point of the style on the button property page Cbitmap bitmap; Bitmap. loadbitmap (idb_bitmap1 ); Hbitmap = (hbitmap) bitmap. Detach (); Cbutton * pbutton = (cbutton *) getdlgitem (idcancel ); Pbutton-> setbitmap (hbitmap ); It seems that the effect is not very good. Because the image is not automatically stretched. Second: You can use the cbuttonst control, which is more useful than those of MFC. Assume that the button ID is idc_button1 1. Add member variables Cbuttonst m_btn; 2. Add a bitmap resource with the ID set to idb_bitmap1. 3. In the oninitdialog function, initialize the button m_btn.subclassdlgitem (idc_button1, this ); M_btn.setbitmaps (idb_bitmap1, RGB (0, 0 )); M_btn.offsetcolor (cbuttonst: btnst_color_bk_in, 30 ); Note: The above setbitmaps function sets the point with the color value RGB (, 0) in the image to transparent. Third: Set the button property to ower draw. Then map the ondrawitem message You can draw it yourself in the ondraw function. Void cui6dlg: ondrawitem (INT nidctl, lpdrawitemstruct) { If (nidctl = idc_hello_cfan) { // Draw the button Frame Uint ustyle = dfcs_buttonpush; // Do you want to press it? If (lpdrawitemstruct-> itemstate & ods_selected) Ustyle | = dfcs_pushed; Cdc dc; DC. Attach (lpdrawitemstruct-> HDC ); DC. drawframecontrol (& lpdrawitemstruct-> rcitem, dfc_button, ustyle ); // Output text DC. SelectObject (& m_font ); DC. settextcolor (RGB (0, 0,255 )); DC. setbkmode (transparent ); Cstring stext; M_hellocfan.getwindowtext (stext ); DC. textout (lpdrawitemstruct-> rcitem. Left + 20, lpdrawitemstruct-> rcitem. Top + 20, stext ); // Whether the focus is obtained If (lpdrawitemstruct-> itemstate & ods_focus) { // Draw a dotted box Crect rtfocus = lpdrawitemstruct-> rcitem; Rtfocus. deflaterect (3, 3 ); DC. drawfocusrect (& rtfocus ); } Return; } Cdialog: ondrawitem (nidctl, lpdrawitemstruct ); } Fourth: 1. Select the button attribute onwer Drew. The button ID is idc_button1. 2. Define the private variable: Cbitmapbutton m_button; 3. During Initialization M_button.loadbitmaps (_ T ("idb_bitmap3"), _ T ("idb_bitmap4"), _ T ("idb_bitmap3"), _ T ("idb_bitmap5 ")); M_button.subclassdlgitem (idc_button1, this ); M_button.sizetocontent (); This method also works. |