|
-
June 29th, 2016, 08:12 AM
#1
Format Edit Control with Spin Control, Leading Zeros
I have an MFC Edit Control with a Spinner and it works pretty good but I want to format the number to a fixed length with leading zeros like this: 000, 001, 012, 123.
I tried to use the Spin Control event UDN_DELTAPOS to read the Edit Controls Member Variable CString and modify it with leading zeros as necessary.
Unfortunately, when this event happens, this Member Variable still contains the OLD value and not the new one.
Is there an event that happens AFTER the Spin Control finishes its work?
Any other suggestions?
I am also limiting the spinner like this:
OnInitDialog()
{
//This part works
//Set range of spin control
CSpinButtonCtrl* SpinControl;
SpinControl = (CSpinButtonCtrl*)GetDlgItem(IDC_spnActual);
SpinControl->SetRange( MinActual, MaxActual );
}
Thanks,
Ken
-
June 29th, 2016, 09:02 AM
#2
Re: Format Edit Control with Spin Control, Leading Zeros
You could try handling EN_CHANGE or EN_UPDATE notifications.
Victor Nijegorodov
-
July 4th, 2016, 05:37 AM
#3
Re: Format Edit Control with Spin Control, Leading Zeros
A spin control also sends WM_VSCROLL to its parent. So, if you want to customize what is displayed in the buddy edit control, first remove UDS_SETBUDDYINT style (in the resource editor, put Set Buddy Integer property to False) then handle WM_VSCROLL message in the parent dialog class.
Here is an example:
Code:
class CDemoDialog : public CDialog
{
// ...
CSpinButtonCtrl m_spinCtrl;
afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
};
Code:
void CDemoDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_SPIN_DEMO, m_spinCtrl);
// ...
}
BEGIN_MESSAGE_MAP(CDemoDialog, CDialog)
// ...
ON_WM_VSCROLL()
END_MESSAGE_MAP()
// ...
void CDemoDialog::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
if ((pScrollBar->GetSafeHwnd() == m_spinCtrl.m_hWnd)
&& (SB_THUMBPOSITION == nSBCode))
{
CString strText;
strText.Format(_T("%04d"), nPos); // format with leading zeros
m_spinCtrl.GetBuddy()->SetWindowText(strText);
}
CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|