[Small exercise EVC] fine-tuning button for common controls

Source: Internet
Author: User
The fine-tuning button is a simple scroll bar, which is often used together with an editing control called "buddy windows". They can work well with each other, the MFC class cspinbuttonctrl encapsulates the fine-tuning control. In this example, the edit box and the fine-tuning button are combined to input three colors of RGB.
1. Use EVC to create an MFC-based application spinuse;
2. Design Interface

The properties of the dialog box space are as follows:

ID) Description
Idc_edt_red Edit box, range: 0-255, corresponding variable: m_red
Idc_edt_green Edit box, range: 0-255, corresponding variable: m_green
Idc_edt_blue Edit box, range: 0-255, corresponding variable: m_blue
Idc_spin_red Fine-tune button. Select the SER buddy integer check box.
Idc_spin_green Fine-tune button. Select the SER buddy integer check box.
Idc_spin_blue Fine-tune button. Select the SER buddy integer check box.

3. Add the following code to the oninitdialog of cspinusedlg: cspinbuttonctrl * pspinred = (cspinbuttonctrl *) getdlgitem (idc_spin_red );
Assert (pspinred! = NULL );
Pspinred-> setbuddy (getdlgitem (idc_edt_red ));
Pspinred-> setrange (0,255 );
Pspinred-> setpos (128 );

Cspinbuttonctrl * pspingreen = (cspinbuttonctrl *) getdlgitem (idc_spin_green );
Assert (pspingreen! = NULL );
Pspingreen-> setbuddy (getdlgitem (idc_edt_green ));
Pspingreen-> setrange (0,255 );
Pspingreen-> setpos (128 );

Cspinbuttonctrl * pspinblue = (cspinbuttonctrl *) getdlgitem (idc_spin_blue );
Assert (pspinblue! = NULL );
Pspinblue-> setbuddy (getdlgitem (idc_edt_blue ));
Pspinblue-> setrange (0,255 );
Pspinblue-> setpos (128 );

4. Use the Class Wizard to add the onchange function in a color edit box. Add the following code. Void cspinusedlg: oncolorchange ()
{

Updatedata (true );
Cbrush colorbrush;
Colorref clrgb;

Clrgb = RGB (m_red, m_green, m_blue );
Cclientdc * pclientdc;
Pclientdc = new cclientdc (this );
Colorbrush. createsolidbrush (clrgb );
Crect rect (0, 100,200,200,300 );
Pclientdc-> fillrect (rect, & colorbrush );
Delete pclientdc;
// Todo: if this is a RichEdit control, the control will not
// Send this notification unless you override the cdialog: oninitdialog ()
// Function and call cricheditctrl (). seteventmask ()
// With the enm_change flag ored into the mask.

// Todo: add your control notification handler code here

}

5. Complete Compilation

Related Article

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.