Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Detect user input

Posted on 2000-02-19
2
811 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…

856 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