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:
- int itemp = _wtoi(m_editNum1);
- m_Spin.SetBuddy(GetDlgItem(itemp));
- m_Spin.SetRange(0,100);
Add message response event to control Spin Control
- void CSpinctrlDlg::OnDeltaposSpin1(NMHDR *pNMHDR, LRESULT *pResult)
- {
- LPNMUPDOWN pNMUpDown = reinterpret_cast<LPNMUPDOWN>(pNMHDR);
- // TODO: Add control notification handler code here
- UpdateData(true);
- CString ss;
- if (pNMUpDown->iDelta == -1) // If this value is -1, it means the down arrow of Spin is clicked
- {
- double a;
- a=wcstod(m_editNum1,NULL)-1;
- ss.Format(_T("%.1f"),a);
- }
- else if (pNMUpDown->iDelta == 1) // If this value is 1, it means the Spin's up arrow is clicked
- {
- double a;
- a=wcstod(m_editNum1,NULL)+1;
- ss.Format(_T("%.1f"),a);
- }
- m_editNum1=ss;
- UpdateData(false);
- *pResult = 0;
- }