Sunteți pe pagina 1din 9

Creates a spin button control and attaches it to a CSpinButtonCtrl object..

virtual BOOL Create(DWORD dwStyle,const RECT& rect,CWnd* pParentWnd,UINT nID ); Parameters: dwStyle :Specifies the spin button control's style. Apply any combination of spin button control styles to the control. These styles are described in Up-Down Control Styles in the Windows SDK. rect : Specifies the spin button control's size and position. It can be either a CRect object or a RECT structure pParentWnd : A pointer to the spin button control's parent window, usually a CDialog. It must not be NULL. nID : Specifies the spin button control's ID.

CSpinButtonCtrl::CreateEx Creates a control (a child window) and associates it with the CSpinButtonCtrl object. virtual BOOL CreateEx( DWORD dwExStyle, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID ); Parameters: dwExStyle : Specifies the extended style of the control being created. For a list of extended windows styles, see the dwExStyle parameter for CreateWindowEx in the Windows SDK.

dwStyle: Specifies the spin button control's style. Apply any combination of spin button control styles to the control. These styles are described in Up-Down Control Styles in the Windows SDK. rect :A reference to a RECT structure describing the size and position of the window to be created, in client coordinates of pParentWnd. pParentWnd :A pointer to the window that is the control's parent. nID :The control's child-window ID.

CSpinButtonCtrl::CSpinButtonCtrl
Constructs a CSpinButtonCtrl object. CSpinButtonCtrl( );

Using CSpinButtonCtrl The spin button control (also called an up-down control) provides a pair of arrows that the user can click to adjust a value. This value is called the current position. The position stays within the range of the spin button. When the user clicks the up arrow, the position moves toward the maximum; and when the user clicks the down arrow, the position moves toward the minimum. The spin button control is represented in MFC by class CSpinButtonCtrl. When you click a spin button control, the control sends a WM_VSCROLL message to the parent window by default. If the control layout is horizontal instead of vertical, the control sends a WM_HSCROLL message to the parent window.

Spin Button Styles Many of the settings for a spin button (CSpinButtonCtrl) are controlled by styles. You can set the following styles using the Properties window in the dialog editor.

y y

Orientation Either Vertical or Horizontal. Controls the orientation of the arrow buttons. Associated with the UDS_HORZ style. Alignment One of Unattached, Left, or Right. Controls the location of the spin button. Left and Right position the spin button next to the buddy window. The width of the buddy window is decreased to accommodate the spin button. Associated with the UDS_ALIGNLEFT and UDS_ALIGNRIGHT styles. Auto Buddy Automatically selects the previous window in Z-order as buddy window to the spin button. In a dialog template, this is the control which precedes the spin button in the tab order. Associated with the UDS_AUTOBUDDY style. Set Buddy Integer Causes the spin control to increment and decrement the caption of the buddy window as the current position changes. Associated with the UDS_SETBUDDYINT style. No Thousands Does not insert the thousands separator in the value in the caption of the buddy window. Associated with the UDS_NOTHOUSANDS style. Wrap Causes the position to "wrap" as the value is incremented or decremented beyond the range of the control. Associated with the UDS_WRAP style. Arrow Keys Causes the spin button to increment or decrement the position when the UP ARROW and DOWN ARROW keys are pressed. Associated with the UDS_ARROWKEYS style.

Spin Button Member Functions


There are several member functions available for the spin control (1.CSpinButtonCtrl). Use these functions to change the following attributes of the spin button.
y

Acceleration You can adjust the rate at which the position changes when the user holds down the arrow button. To work with acceleration, use the (2.SetAccel) and (3.GetAccel) member functions. Base You can change the base (either 10 or 16) used to display the position in the caption of the buddy window. To work with the base, use the(4. GetBase) and (5.SetBase) member functions. Buddy Window You can dynamically set the buddy window. To query or change which control is the buddy window, use the (6.GetBuddy) and ( 7. SetBuddy) member functions.

Position You can query and change the position. To work directly with position, use the (8.GetPos) and (9.SetPos) member functions. Since the caption of the buddy control may have changed (for example, in the case that the buddy is an edit control), GetPos retrieves the current caption and adjusts the position accordingly. Range You can change the maximum and minimum positions for the spin button. By default, the maximum is set to 0, and the minimum is set to 100. Since the default maximum is less than the default minimum, the actions of the arrow buttons is counter-intuitive. Typically, you will set the range using the (10.SetRange) member function. To query the range use (11.GetRange).

1. CSpinButtonCtrl Class Provides the functionality of the Windows common spin button control. class CSpinButtonCtrl : public CWnd Remarks: A "spin button control" (also known as an up-down control) is a pair of arrow buttons that the user can click to increment or decrement a value, such as a scroll position or a number displayed in a companion control. The value associated with a spin button control is called its current position. A spin button control is most often used with a companion control, called a "buddy window." This control (and therefore the CSpinButtonCtrl class) is available only to programs running under Windows 95/98 and Windows NT version 3.51 and later. To the user, a spin button control and its buddy window often look like a single control. You can specify that a spin button control automatically position itself next to its buddy window, and that it automatically set the caption of the buddy window to its current position. You can use a spin button control with an edit control to prompt the user for numeric input. Clicking the up arrow moves the current position toward the maximum, and clicking the down arrow moves the current position toward the minimum. By default, the minimum is 100 and the maximum is 0. Any time the minimum setting is greater than the maximum setting (for example, when the default settings are used), clicking the up arrow decreases the position value and clicking the down arrow increases it.

A spin button control without a buddy window functions as a sort of simplified scroll bar. For example, a tab control sometimes displays a spin button control to enable the user to scroll additional tabs into view. For more information on using CSpinButtonCtrl, see Controls and Using CSpinButtonCtrl. 2. CSpinButtonCtrl::SetAccel Sets the acceleration for a spin button control. BOOL SetAccel( Parameters: int nAccel, UDACCEL* pAccel );

nAccel :Number of UDACCEL structures specified by pAccel. pAccel :Pointer to an array of UDACCEL structures, which contain acceleration information. Elements should be sorted in ascending order based on the nSec member.

3.CSpinButtonCtrl::GetAccel Retrieves acceleration information for a spin button control. UINT GetAccel(int nAccel,UDACCEL* pAccel) const; Parameters: nAccel :Number of elements in the array specified by pAccel. pAccel :Pointer to an array of UDACCEL structures that receives acceleration information. 4. CSpinButtonCtrl::GetBase Retrieves the current base for a spin button control. UINT GetBase( ) const; 5.CSpinButtonCtrl::SetBase

Sets the base for a spin button control. int SetBase(int nBase ); Parameters nBase :New base value for the control. It can be 10 for decimal or 16 for hexadecimal.

6.CSpinButtonCtrl::GetBuddy Retrieves a pointer to the current buddy window. CWnd* GetBuddy( ) const; 7.CSpinButtonCtrl::SetBuddy Sets the buddy window for a spin button control. CWnd* SetBuddy( CWnd* pWndBuddy); Parameters pWndBuddy :Pointer to the new buddy window. 8.CSpinButtonCtrl::GetPos Retrieves the current position of a spin button control. int GetPos( ) const; int GetPos32(LPBOOL lpbError = NULL) const; Parameters: lpbError :A pointer to a boolean value that is set to zero if the value is successfully retrieved or non-zero if an error occurs. If this parameter is set to NULL, errors are not reported. 9.CSpinButtonCtrl::SetPos Sets the current position for a spin button control.

int SetPos(int nPos); int SetPos32(int nPos); Parameters: nPos :New position for the control. This value must be in the range specified by the upper and lower limits for the control. 10.CSpinButtonCtrl::SetRange Sets the upper and lower limits (range) for a spin button control. void SetRange( short nLower, short nUpper ); void SetRange32( int nLower,int nUpper); Parameters: nLowerand nUpper:Upper and lower limits for the control. For SetRange, neither limit can be greater than UD_MAXVAL or less than UD_MINVAL; in addition, the difference between the two limits cannot exceed UD_MAXVAL. SetRange32 places no restrictions on the limits; use any integers. 11.CSpinButtonCtrl::GetRange Retrieves the upper and lower limits (range) for a spin button control. DWORD GetRange( ) const; void GetRange( int &lower, int& upper ) const; void GetRange32( int &lower, int &upper) const; Parameters: lower :Reference to an integer that receives the lower limit for the control. upper :Reference to an integer that receives the upper limit for the control.

BOOL CSpinDlg::OnInitDialog() {

CDialog::OnInitDialog(); // TODO: Add extra initialization here CSpinButtonCtrl *SpinCtrl = new CSpinButtonCtrl; SpinCtrl->Create(WS_CHILD | WS_VISIBLE, CRect(60, 10, 80, 35), this, 0x128); return TRUE; } By default, a spin control appears with an up and a down pointing arrows. If you want the arrows to be horizontally directed, change the value of the Orientation property from Vertical (the default) to Horizontal .If you are programmatically creating the control, add the UDS_HORZ style to it. Here is an example: SpinCtrl->Create(WS_CHILD | WS_VISIBLE | UDS_HORZ, CRect(60, 10, 80, 35), this, 0x128); Using the Arrow Keys We mentioned already that the value of the spin changes as the user clicks, or holds the mouse on, one arrow of the control. In the same way, if you want the user to be able to increment or decrement the value of the control

using the up and down arrow keys of the keyboard, at design time, set the Arrow Keys property to True at design time. If you are programmatically creating the control, add the UDS_ARROWKEYS style.

S-ar putea să vă placă și