Link to home
Start Free TrialLog in
Avatar of mikexpert
mikexpert

asked on

Create custom CEdit controls that validate input as you type

Hi Experts,
 
I'm trying to extend CEdit so that I can modify its OnChar or OnKeyDown functions - so that I can perform input validation and not allow invalid input.  However, I think I'm going about this all wrong - these functions are not being called for my subclass when I type keys as I expected.  Am I right in assuming that member variables which are controls are not tied directly through my object?  Everything in windows is a message right?  Is there no way to go about this in a java-swing sort of way?
 
I've seen countless examples of how to do input validation with DDX and DDV calls - but I would much rather just create my own classes that already have all this behavior built into them - and have MFC use my classes and interact with them as objects...
 
Any suggestions or is this not possible with MFC?
 
Thanks,
Mike
SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mikexpert
mikexpert

ASKER

Hi krbatge,

I'm sorry for waiting so long with this..  I still haven't got this working.  I did exactly as you said - but my onChar function doesn't get called.  If I look in classwizard, my member variable is of type CFilteredEdit... (changed the name to CFilteredEdit from CValidatingEdit because I deleted CValidatingEdit after many tries...)

So I must still be missing something.. I've got a member variable tied to this control ID and it has a classwizard generated code snippet for OnChar like this:

void CFilteredEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
     if(nChar!='a')
          CEdit::OnChar(nChar, nRepCnt, nFlags);
}

the breakpoint on the if is never reached and I can type any characters...

Any ideas?
Thanks again!

Mike
Also, I notice my CFilteredEdit class dosn't show up in ClassWizard....
Yep - I realized the problem....  Starting fresh after a break from a problem does tend to help sometimes.  Since my class wasn't recognized by ClassWizard, I created a new one and this one worked.  So many thanks for your help everyone!

Mike