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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
basantConnect With a Mentor Commented:
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
 
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
2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

 
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
 
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
All Courses

From novice to tech pro — start learning today.