-
June 16th, 1999, 08:52 PM
#1
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
-
June 17th, 1999, 03:17 AM
#2
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);
}
}
-
June 17th, 1999, 04:45 AM
#3
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
-
June 17th, 1999, 09:44 AM
#4
Re: Hex CEdits
Where does the SubClassDlgItem function need to be called?
-Rajeev
-
June 17th, 1999, 11:50 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|