CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Hex CEdits

  1. #1
    Join Date
    Jun 1999
    Posts
    2

    Hex CEdits

    Hello,

    i wanted to create a CEdit control which takes in as input only 0 through 9 and a/A through f/F.

    i believe i should simply trap the CEdit's WM_CHAR message, right and do the following...


    void CHexEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
    {
    // TODO: Add your message handler code here and/or call default
    UINT mynChar;
    if(isdigit(nChar) || nChar == 'a' || nChar == 'A' || nChar == 'b' || nChar == 'B' \
    || nChar == 'c' || nChar == 'C' || nChar == 'd' || nChar == 'D' \
    || nChar == 'e' || nChar == 'E' || nChar == 'f' || nChar == 'F')
    {
    mynChar = nChar;
    CEdit::OnChar(mynChar, nRepCnt, nFlags);
    }
    else
    mynChar = 0;
    CEdit::OnChar(mynChar, nRepCnt, nFlags);
    }




    Unfortunately, this does not work.

    So, i tried the following...


    void CHexEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
    {
    // TODO: Add your message handler code here and/or call default
    UINT mynChar;
    if((nChar >= 48 && nChar <=57) || (nchar >= 65 && nChar <=70) || (nchar >= 97 && nChar <=102))
    {
    mynChar = nChar;
    CEdit::OnChar(mynChar, nRepCnt, nFlags);
    }
    else
    mynChar = 0;
    CEdit::OnChar(mynChar, nRepCnt, nFlags);
    }





    This does not work too!

    Any suggestions?

    Regards
    Rajeev


  2. #2
    Join Date
    Jun 1999
    Posts
    23

    Re: Hex CEdits

    Hi

    Try this.

    void CHexEditView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
    {
    if( (nChar >= '0' && nChar <= '9') ||
    (nChar >= 'A' && nChar <= 'F') ||
    (nChar >= 'a' && nChar <= 'f') )
    {
    CEditView::OnChar(nChar, nRepCnt, nFlags);
    }
    }



  3. #3
    Join Date
    Apr 1999
    Posts
    306

    Re: Hex CEdits

    Use the way Mattew Cross show you and do not forget to Subclass it like this:
    SubclassDlgItem(IDC_HEX_EDIT, this);
    if you do not do this your overriden function will not be executed.

    Regards,
    ric


  4. #4
    Join Date
    Jun 1999
    Posts
    2

    Re: Hex CEdits

    Where does the SubClassDlgItem function need to be called?

    -Rajeev


  5. #5
    Join Date
    May 1999
    Location
    Oregon, USA
    Posts
    302

    Re: Hex CEdits

    Yet another option is to grab the CSmartEdit class from the edit controls
    section of this site. It is described in an article called SmartEdit control at
    http://www.codeguru.com/editctrl/smartedit.shtml. It uses a similar
    technique to what others have described. I have used that class frequently
    and it works well.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured