[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Detect user input

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

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…
If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

650 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