Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Multiple controls to ON_EN_CHANGE

0 views
Skip to first unread message

Vince

unread,
Nov 3, 2003, 7:36:00 PM11/3/03
to
afx_msg void OnEditChange();

ON_EN_CHANGE(IDC_EDIT1, OnEditChange)
ON_EN_CHANGE(IDC_EDIT2, OnEditChange)

When messages from multiple controls are sent to the same
message handler, is it possible within the handler to
determine which control sent the message?

Thanks.

Scott McPhillips [MVP]

unread,
Nov 3, 2003, 8:57:34 PM11/3/03
to
Vince wrote:

ON_CONTROL_RANGE(EN_CHANGE, IDC_EDIT1, IDC_EDIT2, OnEditChange)

void CMyDialog::OnEditChange( UINT nID )

nID is the ID of the control that sent the message.

--
Scott McPhillips [VC++ MVP]

Roy Fine

unread,
Nov 3, 2003, 8:58:33 PM11/3/03
to

"Vince" <vma...@netzero.com> wrote in message
news:0a0001c3a26b$9f03e9a0$a101...@phx.gbl...

You will get nothing when you use the ON_EN_CHANGE, but you can use the
ON_CONTROL_RANGE macro, and the associated message handler prototype has a
single argument - a UINT that receives the ID corresponding to the control
that caused the message to be sent. If the control IDs for the controls of
interest were assigned sequentially, or otherwise could be specified by a
range, then the Message Map entry might look like this:

BEGIN_MESSAGE_MAP( ... )
...
ON_CONTROL_RANGE(EN_CHANGE,IDC_EDIT1,IDC_EDIT6,MyRangeHandler)
...
END_MESSAGE_MAP()


On the other hand, if you can not specify the controls as a contiguous
inclusive range, then you could either override the OnCmdMsg method in the
CView derived class and handle the message notifications there, or you could
use the ON_CONTROL_RANGE - but code it for single controls, or smaller sets
of controls. The later may look like this:
BEGIN_MESSAGE_MAP( ... )
...
ON_CONTROL_RANGE(EN_CHANGE,IDC_EDIT1,IDC_EDIT1,MyRangeHandler)
ON_CONTROL_RANGE(EN_CHANGE,IDC_EDIT2,IDC_EDIT2,MyRangeHandler)
ON_CONTROL_RANGE(EN_CHANGE,IDC_EDIT3,IDC_EDIT3,MyRangeHandler)
ON_CONTROL_RANGE(EN_CHANGE,IDC_EDIT4,IDC_EDIT4,MyRangeHandler)
ON_CONTROL_RANGE(EN_CHANGE,IDC_EDIT5,IDC_EDIT5,MyRangeHandler)
ON_CONTROL_RANGE(EN_CHANGE,IDC_EDIT6,IDC_EDIT6,MyRangeHandler)
...
END_MESSAGE_MAP()


And the override of the OnCmdMsg function might look like this:

/* *************************************************** */
BOOL CEditChangeNotifyView::OnCmdMsg(UINT nID,
int nCode,
void* pExtra,
AFX_CMDHANDLERINFO* pHandlerInfo){
if(nCode == EN_CHANGE) switch(nID){
case IDC_EDIT1:
case IDC_EDIT2:
case IDC_EDIT3:
case IDC_EDIT4:
case IDC_EDIT5:
case IDC_EDIT6:
MyRangeHandler(nID);
return 1;
break;
default:
break;
}
return CView::OnCmdMsg(nID,nCode,pExtra,pHandlerInfo);
}

And the single handler for all cases would look something like this:

/* *************************************************** */
void CEditChangeNotifyView::Handle_My_EN_CHANGE(UINT nID){
/* Do Something based on nID */
}


regards
roy fine


0 new messages