Although this will handle all the cases, it might be a bit slow.
AliR.
Ah, I noticed that some of the "control keys" were not behaving as they
should so that's when it occured to me to redefine OnChar instead on
OnKeyDown. Problem solved.
Now try pasting something invalid into the control.
Bah, there are so many situations to worry about! :)
:)
I recommend handling just EN_UPDATE - because it catches all
possibilities in one place. Here's a hex entry example I've posted
several times before:
void CHexEdit::OnUpdate()
{
CString str;
GetWindowText( str );
/* Access the string buffer directly */
LPSTR pBuff = str.GetBuffer( 10 );
bool bProblem = false;
for ( int indx = 0; indx < str.GetLength(); indx++ )
{
char nChar = pBuff[indx];
if ( ( ( nChar >= '0' ) && ( nChar <= '9') ) ||
( ( nChar >= 'A' ) && ( nChar <= 'F' ) ) ||
( ( nChar >= 'a' ) && ( nChar <= 'f' ) ) )
{
}
else
{
bProblem = true;
break;
}
}
str.ReleaseBuffer();
if ( bProblem )
{
int start, end;
/* Find the current caret position */
GetSel( start, end );
/* Restore the last good text that was entered */
SetWindowText( m_LastGood );
/* Restore the caret */
SetSel( start-1, end-1, true );
/* Let the user know */
MessageBeep( MB_OK );
}
else
{
/* Store the last good entry string in a
* member variable of the Hex edit class
*/
m_LastGood = str;
}
}
Dave