Click here to Skip to main content
15,881,730 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am wondering which one of this functions to use when a CEdit control and a CDateTimeCtrl control change events occures on an CRecordView parent view:
BOOL CMyView::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	return CRecordView::OnChildNotify(message, wParam, lParam, pLResult);
}

or
BOOL CMyView::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	return CRecordView::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}

or
BOOL CMyView::OnCommand(WPARAM wParam, LPARAM lParam) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	return CRecordView::OnCommand(wParam, lParam);
}

or
BOOL CMyView::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	return CRecordView::OnNotify(wParam, lParam, pResult);
}


I am using the same code when a change event occurs on some CEdit controls, so the best solution is use one of the above functions, but I don't know the deference between them (Which one fit in this situation ?)

I also have some CDateTimeCtrl controls

Help me please :((
Posted
Updated 28-Feb-11 7:48am
v2
Comments
Albert Holguin 28-Feb-11 14:27pm    
are you sure you want a change event in a cedit to trigger something on its parent? if anything, an event within the parent should trigger reading the cedit... for example reading the user input when the user presses an "enter" button
Niklas L 28-Feb-11 18:01pm    
This is quite common e.g. if you have something like a preview control.
Albert Holguin 28-Feb-11 19:25pm    
From a cedit though?
Albert Holguin 28-Feb-11 19:27pm    
...of course I'm not doubting that it can be done, controls are controls, just haven't come across this myself...
Niklas L 1-Mar-11 3:28am    
As an example, you can have use for this when the edit control should contain format specifiers, or regular expressions which extracts/transforms data from elsewhere and present the result in another control.

1 solution

According to the documentation on EN_CHANGE[^], it's sent as a command message. There is a special message map handler for edit control changes, ON_EN_CHANGE, which accepts a afx_msg void OnChangeMyEdit(); handler method.
 
Share this answer
 
Comments
Mr. Tomay 1-Mar-11 10:58am    
Your are right. But if I have for example a dozen of CEdit controls, I wont write a dozen of afx_msg void OnChangeMyEdit(); for each CEdit controls. Because they have a common code (the same code). The best solution is to handle any CEdit controls change event from the parent. But which function to use?
Niklas L 1-Mar-11 11:24am    
I think just I managed to comment my on post instead of your comment :) Please see below.
Niklas L 1-Mar-11 11:21am    
I would use ON_COMMAND_RANGE with the EN_CHANGE notification message. I.e. if I understand your problem correctly.

ON_COMMAND_RANGE(EN_CHANGE, ID_FIRST_EDIT_CONTROL, ID_LAST_EDIT_CONTROL,
OnEditChange)

with
afx_msg void OnEditChange(UINT id);
The one and only OnEditChange will be called for each CEdit in the given range, with it's control id as an argument if you need it.
Mr. Tomay 1-Mar-11 12:16pm    
Very interesting, I did know that ON_COMMAND_RANGE exists. I will try it (But the range may contain other control types). Should ID_FIRST_EDIT_CONTROL and ID_LAST_EDIT_CONTROL have continuous values in the resource.h ?
and what about CDateTimeCtrl controls, because they send a WM_NOTIFY. Does a such ON_NOTIFY_RANGE Exists ?
Niklas L 1-Mar-11 13:36pm    
Reserve a range in resource.h as you describe. You might have to modify _APS_NEXT_CONTROL_VALUE (I think it is) at the bottom of this file, so the resource editor in visual studio knows what the next value should be.

And yes, there is an ON_NOTIFY_RANGE. Good guess ;)

I think you're better off reserving a control range, without interference from other control id's.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900