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?
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.

hshliangAuthor Commented:
Edited text of question.
0
Vinayak KumbarSr Program ManagerCommented:
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
0
hshliangAuthor Commented:
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??
0
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

ZoppoCommented:
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
0
Vinayak KumbarSr Program ManagerCommented:
Hi,

Whenever u are going use SetWindowText() maintain that flag. That is enough, u need not worry about the internal calls. Or u can derive ur own class from CEdit(as Zoppo says) sat CMyEdit. Add the control variable to that edit box of CMyEdit. And map the message WM_CHAR to that class. Now whenever user presses a character it comes to the OnChar function and then goes to the OnEnChange() function, Again to differentiate u may have to maintain a flag i think.

Try it out.

VinExpert
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
hshliangAuthor Commented:
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.
0
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.