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