1. Method 1: Load bitmap display, the disadvantage is: the picture fixed size, does not automatically stretch
// Import a bitmap in the resource file, such as Idc_bitmap1 // set the Bitmap property of the button to TRUE // . cpp New // Create a Picture object // load a picture from a resource = (hbitmap) pbitmap->// button Display Picture
2. Method 2 Self-draw button in DrawItem
//set the Owner Draw property of the button to true//overloaded virtual function On_wm_drawitem-ondrawitem in parent windowvoidXxxdlg::ondrawitem (intNidctl, lpDrawItemStruct lpdrawitemstruct) { //TODO: Add Message Handler code and/or call default values here if(Nidctl = =Idc_button2) { //Draw a button frameUINT Ustyle =Dfcs_buttonpush; //did you press down? if(Lpdrawitemstruct->itemstate &ods_selected) {Ustyle|=dfcs_pushed; } CDC DC; dc. Attach (lpDrawItemStruct-HDC); dc. Drawframecontrol (&lpDrawItemStruct->RcItem, Dfc_button, Ustyle); //Output Textdc. SelectObject (&M_font); dc. SetTextColor (RGB (0,0,255)); CString StrText; StrText= _t ("Sylar Test"); dc. TextOut (lpDrawItemStruct->rcitem.left + +, Lpdrawitemstruct->rcitem.top + -, StrText); //whether to get focus if(Lpdrawitemstruct->itemstate &Ods_focus) { //Draw a dashed boxCRect Rcfocus = lpdrawitemstruct->RcItem; Rcfocus.deflaterect (3,3); dc. DrawFocusRect (&Rcfocus); } return; } cdialogex::ondrawitem (Nidctl, lpdrawitemstruct);}//font SettingsCFont M_font;m_font. CreatePointFont ( -, _t ("Song Body"), NULL);
3. Method 3 inherits the CButton class and implements it by itself.
4.VC button Display Picture