Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Entering hex data in an Edit Box

Status
Not open for further replies.

tmoody

Technical User
Oct 8, 2001
37
US
There must be an easy way to have the user enter hex data in an Edit Box. I have the variable delcared as a CString but that allow the user to enter naything. This was easy in C, so there must be an easy way in C++ using MFC.
 
MFC has a validation mechanism, you could write your own DDV routine which fits in with this architecture:

void DDV_Hex(CDataExchange* pDX, CString val)
{
if (pDX->m_bSaveAndValidate)
{
for (int i = 0; i<val.GetLength(); i++)
{
char c = val;
if (!((c>='0' && c<='9') || (c>='a' && c<='f') || (c>='A' && c<='F')))
{
pDX->Fail();
return;
}
}
}
}

And put it into DoDataExchange() like this:

void CTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTestDlg)
DDX_Text(pDX, IDC_EDIT1, m_edit1);
DDV_Hex(pDX,m_edit1);
//}}AFX_DATA_MAP
} :) Click here if this helped! :)
vvvvvvvvv
 
Thanks Dave, I'm almost there. Apparently my Edit Box still wants an integer but I'm much closer. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top