VC增强Edit控件为日期输入控件
2007-10-07 20:23:16 来源:WEB开发网字符消息处理:
void CMyEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call
int oldpos=LOWORD(GetSel());
CString str;
GetWindowText(str);
if ( nChar>=''0'' && nChar<=''9'' )
{
if ( oldpos<4 || ( oldpos>4 && oldpos<7) || oldpos>7)
{
str.Delete(oldpos,1);
SetWindowText(str);
SetSel(FormatPos(oldpos,oldpos));
CEdit::OnChar(nChar, nRepCnt, nFlags);
if ( LOWORD(GetSel())==4 || LOWORD(GetSel())==7)
{
oldpos=LOWORD(GetSel());
SetSel(FormatPos(oldpos+1,oldpos+1));
}
}
else
if ( oldpos==4 || oldpos==7 )
{
oldpos+=1;
SetSel(FormatPos(oldpos,oldpos));
str.Delete(oldpos,1);
SetWindowText(str);
SetSel(FormatPos(oldpos,oldpos));
CEdit::OnChar(nChar, nRepCnt, nFlags);
}
}
else
if ( nChar==VK_BACK )
{
if ( (oldpos>0 && oldpos<5) || ( oldpos>5 && oldpos<8) || oldpos>8)
{
str.Insert(oldpos,'' '');
SetWindowText(str);
SetSel(FormatPos(oldpos,oldpos));
CEdit::OnChar(nChar, nRepCnt, nFlags);
}
else
if ( oldpos==5 || oldpos==8 )
{
SetSel(FormatPos(oldpos-1,oldpos-1));
}
}
}
击键消息处理:
更多精彩
赞助商链接