4.1 Bitmap Button
Adding a bitmap to a button or changing the font of the button can make the button shine. How can I add a bitmap to the button and change the font of the text on the button? See the following example!
1> Create a dialog box program and create the following dialog box;
Figure 1
Resource ID description:
ID of the left button: idc_button1
ID of the right button: idcancel
2> set the button attribute. Set options, as shown in the arrow;
Figure 2
3> Add a bitmap to a project, such as an arrow;
Figure 3
4> Add control variables to the buttons on the left (use the Class Wizard );
CBitmapButton m_bitmapButton;
※If the cbitmapbutton type does not exist in the Class Wizard, you can change it to cbitmapbutton by default.
5> in the program initialization function of the dialog box, set a bitmap for the buttons on the left and a font for the buttons on the right;
// Todo: add additional initialization code m_bitmapbutton.loadbitmaps (idb_bitmap1, idb_bitmap2) here; // Load button bitmap resource logfont lf; memset (& lf, 0, sizeof (logfont )); // initialize lf. lfheight = 20; // font height (unit: Px) lf. lfwidth = 13; // font width lf. lfitalic = true; // italic lf. lfescapement =-50; // use italic _ tcsncpy_s (LF. lffacename, lf_facesize, _ T ("Arial"), 7); // request a face name "Arial" verify (m_fontbutton.createfontindirect (& lf )); // create a new font getdlgitem (idcancel)-> setfont (& m_fontbutton); // return true for the font application and cancel button; // unless the focus is set to the control, otherwise, true is returned. </span>
6> final
Figure 4
P.s download project source code
[VC programming skills] controls? 4.1 Bitmap Button