?
Solved

Detect user input

Posted on 2000-02-19
2
Medium Priority
?
827 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 200 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

770 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