Use the spin and edit controls to control the increment or decrement of the decimal in edit with spin

Source: Internet
Author: User

1. In response to the spin message, is the point spin the upper and lower key headers of the message, in this message change the value is 0.1 steps to increase or decrease.
2. Use UpdateData (FALSE) to update the variables of the associated double type of edit.

Create steps

1, first create a new dialog window, in the new window, right-click the mouse, add classes, such as: Cspinandeditdlg.

2. Then drag the Spin control and Edit controlcontrols to the dialog window by using the Toolbox.

set in the Spin property
Alignment:right Align
Auto Buddy:true
Set Buddy integer:true (PS: Can not be selected)

"Ctrl+d" Sets the tab order of Edit and spin (for example, edit is 1,spin 2) (PS: If the tab order is not set, spin will not show)

3. Double-click the Spin control controls togenerate the following code in CSPINANDEDITDLG. cpp.

SpinAndEditDlg.h

1 #pragmaOnce2 //PS: Test spin button up and down3 4 //Cspinandeditdlg dialog Box5 6 classCspinandeditdlg: PublicCDialogEx7 {8 declare_dynamic (CSPINANDEDITDLG)9 Ten  Public: OneCspinandeditdlg (cwnd* pparent = NULL);//Standard Constructors A     Virtual~Cspinandeditdlg (); -  -     //dialog box Data the     enum{IDD =Idd_dlg_spin_edit}; -  - protected: -     Virtual voidDoDataExchange (cdataexchange* PDX);//DDX/DDV Support +  - Declare_message_map () +  Public: Aafx_msgvoidOnDeltaposSpin1 (NMHDR *pnmhdr, LRESULT *pResult); at     //double m_dnum; -afx_msgvoidOnBnClickedButton1 (); -     DoubleM_dnum; -};
View Code

SpinAndEditDlg.cpp

1 //SpinAndEditDlg.cpp: Implementing Files2 //3 4#include"stdafx.h"5#include"LoadDllDemo.h"6#include"SpinAndEditDlg.h"7#include"afxdialogex.h"8 #defineDMax 10.09 #defineDMin 0.0Ten  One //Cspinandeditdlg dialog Box A  - implement_dynamic (Cspinandeditdlg, CDialogEx) -  theCspinandeditdlg::cspinandeditdlg (cwnd* pparent/*=null*/) - : CDialogEx (Cspinandeditdlg::idd, pparent) -, M_dnum (0) - { +  -M_dnum =0.5; + } A  atcspinandeditdlg::~Cspinandeditdlg () - { - } -  - voidCspinandeditdlg::D Odataexchange (cdataexchange*PDX) - { in CDialogEx::D odataexchange (PDX); -     //DDX_Text (PDX, idc_edit1, m_dnum); to DDX_Text (PDX, idc_edit1, m_dnum); + ddv_minmaxdouble (PDX, M_dnum, DMin, dMax); - } the  *  $ Begin_message_map (Cspinandeditdlg, CDialogEx)Panax NotoginsengOn_notify (Udn_deltapos, Idc_spin1, &cspinandeditdlg::ondeltaposspin1) -On_bn_clicked (Idc_button1, &cspinandeditdlg::onbnclickedbutton1) the End_message_map () +  A  the //CSPINANDEDITDLG message handlers +  -  $ voidCspinandeditdlg::ondeltaposspin1 (NMHDR *pnmhdr, LRESULT *PResult) $ { -Lpnmupdown Pnmupdown = reinterpret_cast<lpnmupdown>(PNMHDR); -     //TODO: Add control notification handler code here the     if(!UpdateData (TRUE)) -     {WuyiM_dnum =0; the UpdateData (FALSE); -         return; Wu     } -     if(Pnmupdown->idelta = =-1)//If this value is-1, the spin up arrow is clicked About     { $M_dnum = M_dnum +0.1; -     } -     Else if(Pnmupdown->idelta = =1)//If this value is, the description hits the down arrow of the spin -     { AM_dnum = M_dnum-0.1; +     } the     if(M_dnum > DMax | | m_dnum <dMin) -     { $ UpdateData (TRUE); the     } the UpdateData (FALSE); the*presult =0; the } -  in  the voidCspinandeditdlg::onbnclickedbutton1 () the { About UpdateData (TRUE); the M_dnum; the}
View Code

Use the spin and edit controls to control the increment or decrement of the decimal in edit with spin

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.