WEB开发网
开发学院软件开发VC 增强Edit控件为日期输入控件 阅读

增强Edit控件为日期输入控件

 2006-07-23 11:18:36 来源:WEB开发网   
核心提示: 字符消息处理:void CMyEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags){// TODO: Add your message handler code here and/or callint oldpos=LOWORD(GetSe

字符消息处理:

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));
        }
    }
    
}

击键消息处理:

上一页  1 2 3 4  下一页

Tags:增强 Edit 控件

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接