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 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;
    

Downloads

Download demo project - 52 Kb
Download source - 14 Kb Date Posted: today's date in the format month day, year


Comments

  • beep and tab key

    Posted by Legacy on 06/06/2003 12:00am

    Originally posted by: Kim Kemp

    When then SEdit is activated and the tab key pressed it beeps and does not advance to the next control on a dialog. Any ideas how to fix this?

    Reply
  • new draw methode

    Posted by Legacy on 07/26/2002 12:00am

    Originally posted by: Bo Christensen

    Try this...

    // mainly drawing the black triangle on lower button
    BOOL CSpinEdit::DrawLowerBtn( CDC* pDC)
    {
    BOOL bResult = TRUE;
    BOOL bMustReleaseDC = FALSE;

    CRect rect;
    if (!GetLowerBtnRect( rect)) return FALSE;

    if (!pDC)
    {
    pDC = GetDC();
    if (pDC) bMustReleaseDC = TRUE;
    }

    pDC->DrawFrameControl(rect,DFC_SCROLL,DFCS_SCROLLDOWN |( m_bUpperBtnPushed == FALSE ? 0 : DFCS_PUSHED ) );

    if (bMustReleaseDC)
    ReleaseDC(pDC);

    return bResult;
    }

    regards
    BO Christensen

    Reply
  • I would like accelerator support

    Posted by Legacy on 08/29/2001 12:00am

    Originally posted by: Andrew Truckle

    Is there a way of adding accelerator support to the class. Perhaps something similiar to the native spin control...???

    Andrew

    Reply
  • Showing disabled control in grey....

    Posted by Legacy on 07/19/2001 12:00am

    Originally posted by: Andrew Truckle

    Hi

    Your control is just what I require for my program - thank you!

    But I need one bit of functionality not present in your class. If I disable the control:

    m_spinToleranace.EnableWindow(FALSE);

    Although it disables it so that it doesn't work, it doesn't dim the control and it looks confusing on my dialogue.

    Can you add this functionality for me?

    Thank you in advance.

    Andrew Truckle

    PS. Your email link bounced!!!

    Reply
  • find src and demo of updated ctrl at http://ahaa007.at.china.com

    Posted by Legacy on 06/30/2001 12:00am

    Originally posted by: huangchaoyi

    find src and demo of updated ctrl at http://ahaa007.at.china.com
    

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • "Security" is the number one issue holding business leaders back from the cloud. But does the reality match the perception? Keeping data close to home, on premises, makes business and IT leaders feel inherently more secure. But the truth is, cloud solutions can offer companies real, tangible security advantages. Before you assume that on-site is the only way to keep data safe, it's worth taking a comprehensive approach to evaluating risks. Doing so can lead to big benefits.

  • Mobile is introducing sweeping changes throughout your workplace. As a senior stakeholder driving mobile initiatives in your organization, you may be lost in a sea of technologies and claims from vendors promising rapid delivery of applications to your employees, customers, and partners. To help explain some of the topics you will need to be aware of, and to separate the must-haves from the nice-to-haves, this reference guide can help you with applying a mobile strategy in the context of application …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds