Link to home
Start Free TrialLog in
Avatar of hshliang
hshliang

asked on

How to tell the difference between an user entry from a program change in content of an Edit control?

I am writing a program that has an Edit control. It can be changed by both the user and the program itself (by SetWindowText). When the user changes it, I want to check if it fits another criteria and reverse it if it fails. However, when the program changes it, I will let it change without checking the criteria. I try to use OnEditChange to catch the change and then check for the criteria, but when it is changed by the program, it get checked the same way.
How can I distinquish whether the OnChange is called by a user change or a program change?
Avatar of hshliang
hshliang

ASKER

Edited text of question.
Hi,

Whenevr there is the change in the text of the edit box, that OnChange() function gets called. It may be programatically or user change. The work around for ur problem may be maintaining a flag. That flag will represent whether user is changing the data or Ur program. Whenever program changes the text by SetWindowText(), before that call set that flag, and check that flag in OnChange(). and reset it back. Something like that u have to do. Okay.

Try it out.

VinExpert
Thank you for the suggestion, actually the questions arises because SetWindowText is called in one of the DDX in the DoDataExchange, and it took me a while to debug it and found out the problem. Hence it is very prone to debug in future if we use flags, as there may be many more SetWindowText (like AfxSetWindowText in the intrinsic funtions of MFC) that are called without me knowing when and where. Any other better ways??
Avatar of Zoppo
Hi hshliang,

you could derive your own class from CEdit and implement message handlers for the WM_CHAR and the WM_KEYDOW/WM_KEYUP messages to find out when a user changed its content.

hope that helps,

ZOPPO
ASKER CERTIFIED SOLUTION
Avatar of Vinayak Kumbar
Vinayak Kumbar

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
I finally decide to rewrite a subclass to catch the OnChar. I guess this is the best way. Although I have to rewrite a lot as I am running an array of controls. And to put a derived class in an Array was a bit of a hassle to me.