4.VC button Display Picture

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.