It seems like the simplest thing (using Visual Studio):
- Place an edit control (MFC
CEdit) on a dialog - Right click and choose "Add variable..."
- Link the control to a variable (e.g. CString someText)
- Right click on the control again and choose "Add Event Handler..."
- Click the "Add and Edit" button so it adds an
EN_CHANGEevent handler - The class wizard generates a handler function like
OnEnChangeEdtSomeText()
Terrific - each time a character is typed, the handler function is invoked. However, on all other events I have ever handled with MFC controls, UpdateData() would exchange data between the control and a variable linked to it - the state of the control is reflected in the state of the linked variable after UpdateData() is called. Why not here? Clearly I have to use something else, and so far GetWindowText() seems to work fine for retrieving the text I can see in the CEdit control.
But why has the normal function of UpdateData() been destroyed? For example, if I type "foo" into my edit control, then click or tab away to kill focus, then return to type "bar", on none of the invocations of OnEnChangeEdtSomeText() (all 6 of them) does UpdateData() lead to any data whatsoever in the variable linked to it. Why not? Can I trust EN_CHANGE not to interfere with other data entry? Are there other notifications that will break what I had come to believe was the normal link between a control and a variable linked through a DDX... mechanism?
EN_CHANGEcan be raised, when the user didn't type a character (e.g. pasting from the clipboard with the mouse). It's not clear, what problem you are really trying to solve. This question is asking about your proposed solution only. - IInspectableUpdateDatato see exactly what it's doing and why it's failing. But callingUpdateDataon every character input is an abuse of the system - even if you get it working, I would recommend usingGetWindowTextas you're currently doing. - Mark RansomUpdateData()is not the right thing to use in this particular context - that's fine. But I'm really surprised that it seems to break completely as ifEN_CHANGEis some kind of kryptonite to it. SinceUpdateData()is used so liberally in the software I'm using, I'd like to understand what hidden traps there might be with it. - omataiDoDataExchangefunction) it's somewhat hard to help. - Jabberwocky