Buttons for beautifying the VC interface

Source: Internet
Author: User

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.

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.