sos:使用MFC中spin时遇到的
各位大侠:
小妹现有一段代码想实现微调按钮调整编辑框内的数字,每点击一次增加或减少0.5。采用如下代码实现时发现,当随机的在编辑框内输入数字时,再点击上下微调按钮时不能实现,查找不到原因。还请大侠们帮忙!
void Cterminal::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
int pos = nPos;
if (nSBCode == SB_ENDSCROLL)
{
return;
}
if(pScrollBar->GetDlgCtrlID() == IDC_SPIN1)
{
CString strValue;
strValue.Format("%3.2f",(float )pos/2.0);
((CSpinButtonCtrl*) pScrollBar)->GetBuddy()->SetWindowText(strValue);
}
if(pScrollBar->GetDlgCtrlID() == IDC_SPIN2)
{
CString strValue;
strValue.Format("%3.2f", (float)pos/2.0);
((CSpinButtonCtrl*) pScrollBar)->GetBuddy()->SetWindowText(strValue);
}
if(pScrollBar->GetDlgCtrlID() == IDC_SPIN3)
{
CString strValue;
strValue.Format("%3.2f",(float) pos/2.0);
((CSpinButtonCtrl*) pScrollBar)->GetBuddy()->SetWindowText(strValue);
}
CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}