CSpinEdit that Displays Additional Text | CodeGuru

CSpinEdit that Displays Additional Text

Click here for larger image The CSpinEdit is an alternative control for standard CSpinButtonCtrl, but has new features:  Supports spinning data with mouse wheel Automatically increases data when pressing the upper button, but decreases if pressing the lower button The spinned data type can be integer , float or double You can specify the decimal […]

Written By
CodeGuru Staff
CodeGuru Staff
Jan 25, 2001
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More




Click here for larger image

The CSpinEdit is an alternative control for standard CSpinButtonCtrl, but has
new features: 

  • Supports spinning data with mouse wheel
  • Automatically increases data when pressing the upper button, but decreases if pressing the lower button
  • The spinned data type can be integer , float or double
  • You can specify the decimal digits
  • If you provide valid extra-text parameter, the string will be displayed on the control on the left side of numeric data
  • The SpinEdit uses inplaced edit control to edit spinned data

Usage

Follow these steps in order to use the CSpinEdit control.

  1. Include the following files in your project
    seedit.h
    seedit.cpp
    spinedit.h
    spinedit.cpp
    
  2. Add a Custom Control to dialog
  3. Set the class to "SPINEDITCTRL"
  4. Add a member variable after the line "//}}AFX_DATA" to the dialog class
    CSpinEdit m_SpinEdit;
    
  5. Add the following weight line in the method "DoDataExchange "
    in the implementation file.
    void CSpinDlg::DoDataExchange(CDataExchange* pDX)
    {
     CDialog::DoDataExchange(pDX);
     //{{AFX_DATA_MAP(CSpinDlg)
     DDX_Radio(pDX, IDC_RADIOINT, m_nDataType);
     DDX_Text(pDX, IDC_EDITSTEP, m_dbStep);
     DDX_Text(pDX, IDC_EDITPOINT, m_bPos);
     DDX_Text(pDX, IDC_EDITMIN, m_dbMin);
     DDX_Text(pDX, IDC_EDITMAX, m_dbMax);
     DDX_Text(pDX, IDC_EDITEXTRATEXT, m_strExtraText);
     DDX_Check(pDX, IDC_CHECKTEXT, m_bNeedText);
     //}}AFX_DATA_MAP
     DDX_SpinEditControl(pDX, IDC_SPINEDIT, m_SpinEdit);
    }
    
  6. The initialization and parameters setting of the control is like
    common controls.

Dynamically Creating a CSpinEdit in a View

  1. Include the following files in your project:
    seedit.h
    seedit.cpp
    spinedit.h
    spinedit.cpp
    
  2. Add a member variable to your view( suppose the view is CSpinEditCtrlView in the demo )
    CSpinEdit *m_pSpinEdit;
    
  3. Initialize it in the view’s constructor
    m_pSpinEdit = NULL;
  4. 4. Create the control in the menu command handler
    void CSpinEditCtrlView::OnSpinDynamic()
    {
     // TODO: Add your command handler code here
     if( m_pSpinEdit != NULL )return;
    
     m_pSpinEdit = new CSpinEdit;
    
     CRect rect(100,100,300,130);
    
     m_pSpinEdit->Create( this,
                             rect,
                             ID_SPINEDIT,
                             WS_VISIBLE );
    
     m_pSpinEdit->SetParams( SE_DOUBLE,
                                2, 0, 0, 0, 100, 0.01,
                                TRUE, "example" );
    }
    
  5. You can access the value via
    double dbCurValue = m_pSpinEdit->GetCurValue();
    

    Unfortunately, you have to cast the result to integer type if you expect integer value.

  6. Delete it in the view’s destructor:
    if( m_pSpinEdit != NULL )
     delete m_pSpinEdit;
    
Advertisement

Downloads

Download demo project – 52 Kb

Download source – 14 Kb

Date Posted: today’s date in the format month day, year

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.