Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to make the textbox to accept only Hexa decimal values?And also it should take only two characters in it?
Posted
Comments
Sandeep Mewara 9-Jun-11 4:37am    
Whats the issue here? You can always check what is present in it and act accordingly. Further you can use other events to trap/tack the key pressed.
Sergey Alexandrovich Kryukov 9-Jun-11 4:37am    
What is "Hexa decimal"? :-)
--SA
Sergey Alexandrovich Kryukov 9-Jun-11 4:39am    
What is VC8.0? Platform, please. Raw Windows, MFC?
--SA

there are many way to do this.
one resusable way is that.
Create your class (CHexEdit) derived from CEdit
override the PreTranslateMessage() function in CHexEdit class
do following kind of checking in it

if( pMsg->message == WM_CHAR )
{
    if(( pMsg->wParam  != 'A' ) )// It allows to enter only 'A' in your edit box
    {
        pMsg->wParam = 0;
    }
}


instead of if(( pMsg->wParam != 'A' ) ) you need to write your own condition checking for allowing characters only between 0 and 9 and 'a' and 'f' and 'A' and 'F' to support hexadecimal

now you have to create control meber variable of your edit control.its class type should be HexEdit instead of CEdit
 
Share this answer
 
If you want to use MFC, the best option in this case would be masked edit control.
Here is an article which explains everything:
Masked Edit Control[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900