How to catch and assess an entry to an Edit control?

I am writing a program with at least two edit controls in a dialog window.
I want one control to accept only one letter.
Then it checks the entry letter and check against the content in another edit control to make some decisions.
It can either undo the entry or change the content of the OTHER control or even changes behaviour of the parent dialog (like disable some controls).
I try catching the entry in OnEditChange, what happens is if I undo the change with Undo() or SetWindowText(..) it calls the edit's OnEditChange again,
so it goes in circle and give unexpected result.
Any suggestion on how to get around this?  
hshliangAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chensuCommented:
It sounds that there is something wrong with your UI design. Why do you want to undo it? Invalid data?
0
basantCommented:
If u want to do your undo then
you can use one flag to detect when you called the undo and when windows called the undo here is the example.

BOOL g_var = FALSE

OnEditChage
{
   if( g_var )
   {
     g_var = FALSE;
     // add your code here
   }

}

Set this variable to TRUE when you want to enable it.
0
Vinayak KumbarSr Program ManagerCommented:
Hi,

Under such conditions it is always better to derive Ur own class from CEdit and map WM_CHAR message and check for it.

Try it out.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

hshliangAuthor Commented:
Thank you for all your suggestions.
I need to undo because the entry is not a valid one if the condition of another control is not satisfied.
To subclass a edit for this purpose will make it difficult to check the other edit control.
Is it possible to catch the char in the Dialog? I tried OnChar in the Dialog, but it does work. The complicated matter is the dialog is a page of a tab control of another parent dialog.
I think may be the flag is the best way.
0
basantCommented:

WM_CHAR message will be received by Dialog only when no edit child control have the focus which is not true in case of dialog boxes.

WM_CHAR will therefore be not sent to Dialog if an Edit box or a Button has the focus.

Therefore you have to manually catch
the events in each control and take action according to your need.
0
hshliangAuthor Commented:
Thank you, I have devised a way to change the acceptable letter, and change that according to the status of the other control and I am working on this approach.
I am using a subclass of CEdit and catch the char by OnChar and select the character that I want.
But how do I inform the parent dialog that an unaccepatble char is entered?
I know that with a self written control (OCX) I can use 'fire event'. But in a subclassed CEdit, how do I inform the parent that an unwanted char is entered?


0
chensuCommented:
>But how do I inform the parent dialog that an unaccepatble char is entered?

Post a user-defined message to the parent window.
0
basantCommented:
As Chensu Said
<Post a user-defined message to the parent window

You can do like this :

WPARAM wVal = 0; // you can send whatever you want
LPARAM lVal = 0; // you can send whatever you want
PostMessage( hParent,WM_USER + 1, wVal, lVal );

Put a entry in Your Dialog Class
BEGIN_MESSAGE_MAP
....
ON_MESSAGE( WM_USER+1, FunctionName)
END_MESSAGE_MAP


It is sometimes safe to Register ur
own messages using
Registermessage and then use
Put a entry in Your Dialog Class
BEGIN_MESSAGE_MAP
....
ON_REGISTERED_MESSAGE( WM_USER+1, FunctionName)
END_MESSAGE_MAP
0
hshliangAuthor Commented:
Good advice. Thank you.
How do I give you guys the credits?
0
chensuCommented:
You can accept basant's comment as an answer.
0
basantCommented:
Sorry there was a small error in my comment. I am correcting it now.

It is sometimes safe to Register ur
own messages using
int nRegMsg = Registermessage ( ...)

and then use
Put a entry in Your Dialog Class
BEGIN_MESSAGE_MAP
.....
ON_REGISTERED_MESSAGE( nRegMsg, FunctionName)
END_MESSAGE_MAP
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.