The use of Spin control in MFC

When writing a tool, you need to fine-tune the latitude and longitude, and the latitude and longitude are presented in the format of degrees, minutes and seconds. Thought of using the control  Spin Control  to achieve. Now make a brief review of the usage of this control.

Create a new MFC dialog-based application, the project is named  Spinctrl , add an edit box control and a Spin Control to the interface to achieve the effect: first enter a value into the edit box, and then use  Spin Control to achieve fine-tuning.

The interface performance is shown in Figure 1-1 .

 

Figure 1-1  Schematic diagram of the Spin Control use case

Edit box add value variable   CString  m_editNum1 ;

Spin Control adds control variable  CSpinButtonCtrl  m_Spin ;

Two controls are bound in the initialization function:

[cpp]  view plain copy  
  1. int itemp = _wtoi(m_editNum1);    
  2. m_Spin.SetBuddy(GetDlgItem(itemp));   
  3. m_Spin.SetRange(0,100);  

Add message response event to control Spin Control

[cpp]  view plain copy  
  1. void CSpinctrlDlg::OnDeltaposSpin1(NMHDR *pNMHDR, LRESULT *pResult)  
  2. {  
  3. LPNMUPDOWN pNMUpDown = reinterpret_cast<LPNMUPDOWN>(pNMHDR);  
  4. // TODO: Add control notification handler code here  
  5. UpdateData(true);  
  6. CString ss;  
  7. if (pNMUpDown->iDelta == -1)  // If this value is -1, it means the down arrow of Spin is clicked  
  8. {  
  9. double a;  
  10. a=wcstod(m_editNum1,NULL)-1;  
  11. ss.Format(_T("%.1f"),a);  
  12. }  
  13. else if (pNMUpDown->iDelta == 1)  // If this value is 1, it means the Spin's up arrow is clicked   
  14. {  
  15. double a;  
  16. a=wcstod(m_editNum1,NULL)+1;  
  17. ss.Format(_T("%.1f"),a);  
  18. }  
  19. m_editNum1=ss;  
  20. UpdateData(false);  
  21. *pResult = 0;  
  22. }  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324757010&siteId=291194637
Recommended