Use VC6 to extend the CButton class to create a unique style of buttons

Source: Internet
Author: User
Tags bool extend

First, this article introduces a CButton derived class Clinkbutton, the buttons made with this derived class have the following characteristics:

1, the appearance of the button is similar to the static control class CStatic objects produced. (See figure I)

Figure I

2, when the mouse cursor moved to the button, but did not press, the cursor changes shape, font change shape; buttons similar to the Flat button effect applied to toolbars and menus. (See figure II)

Figure II

3, when the button pressed the situation: (see figure III)

Figure Three

Two, the following specific description of the implementation of the button and steps:

    • generates a dialog-based project in the VC6 IDE environment.
    • Opens the property page of the button in the dialog resource, and selects the Owner Draw property of the button on the Style tab page. The
    • introduces the cursor to the application's resources.
    • derives a new class using ClassWizard, CButton as a base class: Clinkbutton.
    • to overload a virtual function of the base class CButton in a derived class: virtual void DrawItem (lpdrawitemstruct lpdrawitemstruct) The reason to overload this function is that the application's framework calls this function to redraw the button when the visual behavior of the button is changed when the button's "Owner Draw" property has been selected.  
    • Customizes the following message processing: afx_msg void OnMouseMove (UINT nflags, CPoint point);
      afx_msg BOOL onsetcursor (cwnd* pwnd, UINT nhittest, UINT message);
      afx_msg void OnTimer (UINT nidevent);
      afx_msg void OnLButtonUp (UINT nflags, CPoint point);
      afx_msg void OnLButtonDown (UINT nflags, CPoint point);
      afx_msg int OnCreate (lpcreatestruct lpcreatestruct);
      afx_msg BOOL onerasebkgnd (cdc* pDC);
        
    • declares a class member variable definition: ///define font variable
      CFont funderline;
         Define the cursor variable
      hcursor hhand;
         Determines whether the button presses the
      bool Blbtndown;
      Determines whether the mouse is on a button
      bool bhighlight;

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.