We want to do an ActiveX editbox that keep track on the number of characters written. We have done one that count the characters (m_nCharsTyped). It works well until we select more than one character and press backspace ('\b'), then m_nCharsTyped is just decreased by one.
void CNummerCtrl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
if(nChar == '\b' && m_nCharsTyped > 0){
COleControl::OnChar(nChar, nRepCnt, nFlags);
m_nCharsTyped--;
}
else if(m_nCharsTyped >= m_MaxNumberofCharacters)
DoErrorAction();
else if(nChar>='0' && nChar<='9'){
COleControl::OnChar(nChar, nRepCnt, nFlags);
m_nCharsTyped++;
}
else
DoErrorAction();
void CNummerCtrl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
if(nChar == '\b' && m_nCharsTyped > 0){
COleControl::OnChar(nChar, nRepCnt, nFlags);
m_nCharsTyped--;
}
else if(m_nCharsTyped >= m_MaxNumberofCharacters)
DoErrorAction();
else if(nChar>='0' && nChar<='9'){
COleControl::OnChar(nChar, nRepCnt, nFlags);
m_nCharsTyped++;
}
else
DoErrorAction();