下面的程序实现:
(1)按下键盘左键减少数值并用控件显示
(2)按下键盘右键增加数值并用控件显示
其中的刷新就用到了局部刷新,只刷新显示数字的控件
BOOL CEditTestDlg::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN)
{
if (pMsg->wParam == VK_RIGHT)
{
tmp++;
m_value.Format(_T("%d"),tmp);
GetDlgItem(IDC_EDIT1)->SetWindowText(m_value);
return TRUE;
}
if (pMsg->wParam == VK_LEFT)
{
tmp--;
m_value.Format(_T("%d"),tmp);
GetDlgItem(IDC_EDIT1)->SetWindowText(m_value);
return TRUE;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
以前一直使用UpdateData()函数更新,但是这次发现GetDlgItem()更适合现在的情况,只更新该控件而不会刷新其他数据。
参考:http://www.cnblogs.com/skywatcher/p/3750059.html