Buddy, Can You Spare Some EN_CHANGE?

Dear Dr. GUI:

I am using Visual C++ 4.1 on Windows 95 and Windows NT.

I was trying to use the EN_CHANGE of an edit box since I wanted to display the characters that are changed in the edit box somewhere else in my dialog. But for some reason at runtime, that event is being generated even before the dialog is being displayed. Why is that happening? Aren't events supposed to be trapped/generated after the dialog is initialized or displayed and something changes in the edit box?

The on-line documentation says: "The EN_CHANGE notification message is sent when the user has taken an action that may have altered text in an edit control." Am reading this wrong?

Please help!!

Thanks.

Vikram Naik

Dr. GUI replies:

In medical school, Dr. GUI learned it as you did. But a few real-life tests showed that Dr. GUI had learned wrong. (Remember when doctors prescribed smoking to help with weight loss?)

Regardless of what the documentation says, the EN_CHANGE notification is sent whenever the text in the edit control is changed, not just when the user changes it. For instance, when you initialize it with SetWindowText, the notification message is sent. (In fact, this happens whether the text is actually changed or not.) This is the correct way for this to work: You want your parent to know when the edit control's contents have changed regardless of how they've changed. It's a feature!

By the way, MFC has some special code to prevent notifications from being sent through the message map mechanism when you're updating controls in a window by calling UpdateData. So if you test this with an MFC application (as Dr. GUI did), you'll find that you DON'T get the notification function call on the initial update.

Just be sure you're prepared to handle the change notification when it comes—because it WILL come!