Fine-tune button spinbutton and instance

Source: Internet
Author: User

The spinbutton is a simple slide. It is often used together with an editing control called "buddy window". They can work well with each other, to respond to user input. In this example, three RGB color components are adjusted to control the color display of the compositing. The completed interface is as follows:

(1) create a dialog box-based application. Add three static texts, three edit boxes (idc_edit_red, idc_edit_green, idc_edit_blue), and three spinbuttion controls (idc_edit_red, idc_edit_green, idc_edit_blue ). Configure the dialog box initialization in the oninitdialog method of cspinbuttondlg as follows:

// Set the red Parameter

Cspinbuttonctrl * pspinred = (cspinbuttonctrl *) getdlgitem (idc_spin_red); // control variable of the red spinbutton
Assert (pspinred! = NULL );
Pspinred-> setbuddy (getdlgitem (idc_edit_red); // set the red sibling window. The BIND of the two is changed.
Pspinred-> setrange (0,255); // you can specify the upper and lower limits of the red edit box.
Pspinred-> setpos (128); // you can specify the default value.

 

Cspinbuttonctrl * pspingreen = (cspinbuttonctrl *) getdlgitem (idc_spin_green); // green spinbutton control variable
Assert (pspingreen! = NULL );
Pspingreen-> setbuddy (getdlgitem (idc_edit_green); // set the green sibling window. The BIND of the two is changed.
Pspingreen-> setrange (0,255); // you can specify the upper and lower limits of the green edit box.
Pspingreen-> setpos (128); // you can specify the default value.

 

Cspinbuttonctrl * pspinblue = (cspinbuttonctrl *) getdlgitem (idc_spin_blue); // green spinbutton control variable
Assert (pspinblue! = NULL );
Pspinblue-> setbuddy (getdlgitem (idc_edit_blue); // set the green sibling window. The BIND of the two is changed.
Pspinblue-> setrange (0,255); // you can specify the upper and lower limits of the green editing box.
Pspinblue-> setpos (128); // you can specify the default value.

(2) Right-click the edit box and add three variables m_red, m_green, and m_blue to the three edit boxes. Right-click the Class View and add the void rgbcolorchange (void) function to the dialog box class to change the color based on the RGB color components. The function body is as follows:

Void cspinbuttondlg: rgbcolorchange (void)
{
Updatedata (true); // copy the value from the control to the variable
Cbrush colorbrush;
Colorref clrgb;
Clrgb = RGB (m_red, m_green, m_blue); // construct the color value in rgb888 format
Cclientdc * pclientdc;

Pclientdc = new cclientdc (this );
Colorbrush. createsolidbrush (clrgb );
Crect rect (0, 80,120,160,200 );

Pclientdc-> fillrect (rect, & colorbrush); // fill the rectangular area with a paint brush
Delete pclientdc;
}

(3) add en_change event processing to the three color edit boxes by right-clicking the edit box control and adding event handler, and selecting the corresponding event message and function. Note that no event processing is added for the spinbutton. You can simply add events to the edit box.

Void cspinbuttondlg: onenchangeeditred ()
{
Rgbcolorchange ();
}

Void cspinbuttondlg: onenchangeeditgreen ()
{
Rgbcolorchange ();
}

Void cspinbuttondlg: onenchangeeditblue ()
{
Rgbcolorchange ();
}

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.