Solved

Detect user input

Posted on 2000-02-19
2
800 Views
Last Modified: 2013-12-03
I created a dialog box with a few edit controls. One way to detect if user edits the text in a particular edit box is to write a handler that handle EN_CHANGE message. That means if I have 10 edit controls in a dialog box, I have to create 10 handlers. Is there any other way ? I'm using MFC.

I created an CIPAddressCtrl controls. The only message posted by the control when user edits the content of the IP control is IPN_FIELDCHANGED. CIPAddressCtrl is derived from CWnd. There must be a way to detect  EN_CHANGE. How can I do this?
0
Comment
Question by:kctan100
2 Comments
 
LVL 1

Expert Comment

by:ScottyDawg
ID: 2539503
What is your environment? If you are using Visual C++ you can use the ON_CONTROL_RANGE macro to map a single notification code from mulitple controls with contiguous IDs.
0
 
LVL 11

Accepted Solution

by:
mikeblas earned 50 total points
ID: 2540361
> CIPAddressCtrl is derived from CWnd.
 > There must be a way to detect  EN_CHANGE. How can I do this?

Why "must" there be a way?  EN_CHANGE is sent by edit controls. CIPAddressCtrl isn't an edit control. It just doesn't send EN_CHANGE! Why would you assume that every CWnd in the world would send EN_CHANGED?

Like ScottyDawg told you, you can use ON_CONTROL_RANGE to get one notification type from all controls into a single handler. The only trick is that your edit controls must have numerically adjacent and contigious IDs.

If we can assume that your ten edits are given IDs 101 to 110, and the first one is ID_EDIT_FIRST and the last is ID_EDIT_LAST, then you can code this message map entry:

   ON_CONTROL_RANGE(EN_CHANGE, ID_EDIT_FIRST, ID_EDIT_LAST, OnEditChangedHandler)

To correspond with that entry, you can write this handler function:

void CYourDialog::OnEditChangedHandler(UINT nID)
{
   ASSERT(nID >= ID_EDIT_FIRST && nID <= ID_EDIT_LAST);

   //... handle it here
   // the ID of the control sending the notification is
   // in nID for you
}

If you want to do this for your IP Address controls, just use the ON_NOTIFY_RANGE macro. If we have the same assumptions for your CIPAddressCtrl objects, then we can use:

   ON_NOTIFY_RANGE(IPN_FIELDCHANGED, ID_EDIT_FIRST, ID_EDIT_LAST, OnIPAddressHandler)

For that entry, you'll need a slightly different handler:

void CYourDialog::OnIPAddressHandler(UINT id, NMHDR * pNotifyStruct, LRESULT *result)
{
   LPNMIADDRESS* pNMIAddress = (LPNMIADDRESS*) pNotifyStruct;

   // ...handle it here.  The ID of the control sending the notify
   // is in id, and the NMIADDRESS for the change the user made
   // is at pNIMAddress...

   *result = 0;  
}

The ClassWizard doesn't support ranged notifications, so you'll need to code these yourself.

..B ekiM

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now