Self-painting button addendum

Source: Internet
Author: User
Tags bool

(Includes: Improved Cxpbutton class, practice program, practice program answer)

The Cxpbutton button shown in the article "Self-painting button implementation" can be described as an irregular button from the shape. We make the controls provided in MFC a standard control, and the button controls in it are called rule buttons because the shape is a rectangular rectangle of rules. But as streamlined design is widely used in interface design, more and more programmers are willing to add some irregular-shaped controls to their work. Take the button as an example, the simplest is to have a round button, triangle buttons and so on. The following figure is a well-defined set of circular buttons:

But these seem to show irregular-shaped buttons in our eyes, sometimes not nearly as satisfying. Take the previous design of the Cxpbutton as an example, let's look for its flaws below. Let's change the background color of the dialog to a different color to see what happens. You can modify the background color as follows: Add a WM_ERASEBKGND message for the dialog class, and if you can't find the message in the Class Wizard, refer to the method described in the custom button implementation, and notice that in the Add dialog box, filter for messages available To set as child windows to see WM_ERASEBKGND messages in the list. We add the code that paints the background color to the function:

BOOL CXPButtonDemoDlg::OnEraseBkgnd(CDC* pDC)
{
  BOOL retValue= CDialog::OnEraseBkgnd(pDC);
  CRect rc;
  GetClientRect(&rc);
  pDC->FillSolidRect(&rc,RGB(0,0,255));
  return retValue;
}
After compiling the program, you can see the following effect, in the four corners of the button there is an ugly corner, which is what I call the flaw:

Now that you've found the problem, of course it's time to start solving the problem. As has been said in the article "Self-painting button implementation", the drawing of a button is mainly done in the DrawItem () function. The added point here is that DrawItem () is a system function provided by MFC, so you can add it by using the following diagram. Select Add Virtual Function ... Then find DrawItem in the list on the left side of the pop-up dialog box, and select Add and edit.

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.