Solved

Detect user input

Posted on 2000-02-19
2
817 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
[X]
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
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

724 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