Control settings
Set the group attribute on the Edit Control (note)
Set on the Spin Control
Auto Buddy is true
Set buddy integer to true
Alignment is right align
Add in oninitdialog ()
Cspinbuttonctrl * pspinctrl = (cspinbuttonctrl *) getdlgitem (idc_spin1 );
Pspinctrl-> setrange (0,128); // after these are set in the control property, this step is generally done.
Pspinctrl-> setbuddy (getdlgitem (idc_edit_weight ));
Pspinctrl-> setbase (10 );
Pspinctrl-> setpos (100 );
When edit changes, the value of spinctrl also changes.
Void ccomdlgdlg: onchangeeditweight ()
{
M_ulweight = getdlgitemint (idc_edit_weight );
Cspinbuttonctrl * pspinctrl = (cspinbuttonctrl *) getdlgitem (idc_spin1 );
Pspinctrl-> setpos (m_ulweight );
}
///////////////////////////////////////
General applications:
Set attributes:
Auto Buddy (automatically take the associated control as the first one in the tab order)
Set buddy interger (enable the control to set the value of the associated control, which can be in decimal or hexadecimal format)
Wrap (loop when the value exceeds the range)
Arrow keys (the control can be increased or decreased when the up and down direction keys are pressed)
Set the control value range in the oninitdialog function:
Setrange (0,255 );
, Rotate button control
"Rotate button controls" (also known as up and down controls) are a pair of Arrow buttons. You can click them to increase or decrease
Value, such as a scroll position or a number displayed in the corresponding control. A rotation control is usually accompanied by
This control is called the "partner window ".
A rotating button control can be automatically positioned next to its partner window and looks like a single control.
Generally, a rotate button control is used with an edit control to prompt users to enter numbers. Click up
The arrow moves the current position to the maximum value, and click the downward arrow to move the current position to the minimum value. Default
The minimum value is 100, and the maximum value is 0. When you click the up arrow, the value is reduced, and click the down arrow to increase.
It, which looks like reversing, so we also need to use the member function cspinbuttonctrl: setrange to change
The maximum and minimum values.
(1) The style commonly used for rotating button controls
The commonly used rotation button controls have the following styles:
|
Uds_horz |
The arrow of the control points to the left and right, rather than to the top and bottom. |
|
Uds_wrap |
If the increase or decrease of the control exceeds the end or start, the value can be "cyclically ". |
|
Uds_arrowkeys |
When you press the up or down arrow keys, the control can be increased or decreased. |
|
Uds_setbuddyint |
Enables the control to set the value of the partner window. The value can be in decimal or hexadecimal format. |
|
Uds_nothousands |
Do not add thousands of delimiters to every three decimal digits. |
|
Uds_autobuddy |
The previous window in Z-order is automatically selected as the control partner window. |
|
Uds_alignright |
Hover the button window to the right of the partner window. The width of the partner window is reduced to adapt to the width of the control. |
|
Uds_alignleft |
Hover the button window to the right of the partner window. The partner window is moved to the right and its width is reduced to fit the width of the control. |
You can also set these styles in the rotate Button Control Properties dialog box. The Styles attributes are described as follows:
|
. Orientation |
Control placement direction: vedical (vertical), hofizontal (horizontal, same as uds_horz ). |
|
. Alignment |
Controls in the partner window: Unattached (irrelevant), right (right, same as uds_alignright), left (left, same as uds_allgnleft ). |
|
. Auto Buddy |
Same as uds_autobuddy. |
|
. Set buddy integer |
The same as uds_setbuddyint. |
|
. No thousands |
Same as uds_nothousands. |
|
. Wrap |
Same as uds_wrap. |
|
. Arrow Keys |
The same as uds_arrowkeys. |
|
. Hot track |
Mouse hotspot tracking. |
(2) Basic operations for rotating button controls
The basic operations include base, range, location setting, and acquisition. They are described as follows:
Set and obtain the base number
The member function setbase is used to set its base. Its prototype is as follows:
Int setbase (INT nbase );
This member function is used to set the base number of a rotating button control. This base value determines that the number displayed in the partner window is in decimal format.
It is a hexadecimal number. The hexadecimal number is always unsigned; the decimal number is signed. If successful, the previous base value is returned,
If an invalid base number is given, a non-zero value is returned. The parameter nbase indicates the new base of the control.
This function corresponds to a member function that obtains the base number of a rotating button control: uint getbase () const;
Set and obtain the range and current position
The setpos and setrange functions are used to set the current position and range of a rotating button control. The prototype is as follows:
Int setpos (INT NPOs );
The NPOs parameter indicates the new position of the control. This value must be within the range specified by the upper and lower limits of the control.
Void setrange (INT nlower, int nupper );
Void setrange32 (INT nlower, int nupper );
The nlower and nupper parameters indicate the upper and lower limits of the control. Any boundary value cannot be greater than or less than ud_maxval.
Ud_minval. In addition, the difference between two boundary values must not exceed ud_maxval. The member function setrange32 is
Rotate the button control to set the 32-bit range.
The member functions corresponding to the preceding functions include:
Int getpos () const;
DWORD getrange () const;
Void getrange (Int & Lower, Int & upper) const;
Void getrange32 (Int & Lower, Int & upper) const;
Other member functions
Cwnd * setbuddy (cwnd * pwndbuddy );
This member function is used to set a companion window for a rotating control. Returns a pointer to the previous partner window. Parameters
Pwndbuddy indicates a pointer to the new partner window.
Bool setaccel (INT naccel, udaccel * paccel );
This member function is used to set the acceleration of a rotating button control. If the operation succeeds, a non-zero value is returned; otherwise, 0 is returned. Parameter naccel table
Indicates the number of udaccel structures specified by paccel. paccel points to a udaccel structure array, which contains the acceleration
Information. Its structure is as follows:
Typedef struct {
Uint nsec; // The number of seconds before the position changes.
Uint ninc; // location increment.
} Udaccel, far * lpudaccel;
The member functions corresponding to the preceding functions include:
Cwnd * getbuddy () const;
Uint getaccel (INT naccel, udaccel * paccel) const;
(3) Notification Message for rotating button controls
There is only one notification message for the rotating button control: udn_deltapos, which indicates that the control's position will change.
Classwizard can be used to map this message. In this message processing function, there is a nm_updown structure that needs to be performed.
The structure is as follows:
Typedef struct _ nm_updown {
Nmhdr; // other notification code information
Int IPOs; // current location
Int idelta; // the increase or decrease of the position. Click the up arrow and the value is negative.
} Nmupdown, far * lpnmupdown;