0

I want event on modifying MFCedit box, i.e. when I try to write or delete any letter.

I am getting the event on killing the focus but that's not required.

I want event while modifying the content of edit box.

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
Rahul Jape
  • 11
  • 1
  • This is fairly basic stuff. Have you Googled for a tutorial about the `CEdit` class? There are events for handling the `EN_CHANGE` and these are exposed in the IDE. – Andrew Truckle Apr 21 '21 at 07:28
  • 1
    Does this answer your question? [How do I get notification from a \`CEdit\` box?](https://stackoverflow.com/questions/11062217/how-do-i-get-notification-from-a-cedit-box) – acraig5075 Apr 21 '21 at 07:53
  • @acraigh5075 Good catch. I forgot about double clicking the control. Useful when you want this event handler (as it is the default handler). – Andrew Truckle Apr 21 '21 at 12:57

2 Answers2

2

To add to the existing answer(s), this can be done by adding the EN_CHANGE event handler for the control. This is a straightforward task using the IDE in Visual Studio.

There are a few approaches to this.


Method 1: Right-click the EDIT control and add an event handler:

Context Menu

Click Add Event Handler... on the context menu and then locate the handler to add it:

Add Handler

Make sure your dialog class is selected and that the EN_CHANGE message type is selected and then click OK to add the boiler plate code to your class. Now you can do what you need to do.


Method 2: Using the Properties Panel

Properties Panel

Make sure that the control is selected and that the Properties Panel is visible on screen.

  1. Click the Control Events (lightning icon) and you will see a list of events for the EDIT control.
  2. Locate EN_CHANGE and click the drop-down arrow.

You'll see a item to select there which will add the event handler for you.


Method 3: Using Class Wizard

Right-click the DIALOG resource (not the EDIT control) and select Class Wizard...

Context Menu

Then you can add the control using the Class Wizard:

Class Wizard

To do this:

  1. Select the EDIT control ID on the list on the left.
  2. Select the EN_CHANGE event handler.
  3. Click the Add Handler... button.

As you can see, there are several ways to add the EN_CHANGE event handler.

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
  • This doesn't explain **what** to do, just **how** to do it. Using an IDE whose MFC support is flaky at best. There hasn't been a Class Wizard in Visual Studio 2002, 2003, 2005, and 2008, i.e. for close to a decade. Likewise, the resource editor has been broken for *years* now on multi-monitor systems with different DPI settings for different displays. – IInspectable Apr 21 '21 at 15:20
  • Disagree. All my screen shots are from VC2019. There is a Class Wizard!!!!!! – Andrew Truckle Apr 21 '21 at 15:32
  • And your other comments are unrelated to the issue at hand. And as I stated at the start of my answer, it was IN ADDITION to exist. Thank you. – Andrew Truckle Apr 21 '21 at 15:33
  • I listed the Visual Studio versions that didn't ship with an MFC Class Wizard. 2019 is not on that list. 2019 is on the list of versions with a completely broken, unusable dialog editor, though. The list of Visual Studio versions with working MFC support is this: Everything up to and including Visual C++ 6.0, VS 2010, 2012, and 2015. That's all. – IInspectable Apr 21 '21 at 15:47
  • I have no desire to argue my friend. Sorry if I miss understood you. – Andrew Truckle Apr 21 '21 at 15:58
1

Changes to the contents of an edit control are reported to clients through an EN_CHANGE notification. The CEdit documentation explains how to wire up class members to notification callbacks. In this case you'll want to add an ON_EN_CHANGE entry to your message map.

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
IInspectable
  • 46,945
  • 8
  • 85
  • 181