15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Intercepting Reflected Messages

Steve Mark -- steve@otms.com
Wednesday, November 13, 1996

Environment: WinNT 4.0 SP1, VC++ 4.2b

I've derived a class from CComboBox and used ClassWizard to handle the
CBN_SELCHANGE event.  The message map entry
ON_CONTROL_REFLECT(CBN_SELCHANGE, OnSelchange) is entered into the derived
classes message map and OnSelchange gets called just fine.  However, I also
need to know when this event occurs, for a specific control, in the CDialog
class that uses it.  I've read through help and tried to handle the event
in the CDialog class, but it never gets called.  Is this possible to do
(handle the event in the control class and in the dialog class)?

Thanks for your time and help

Steve


_________________________________________
Steven Mark
Principal Consultant, On-The-Mark Systems
Tel: 510.648.9514       Fax: 510/648/9507
steve@otms.com



Mike Morel -- mmorel@mushroomsoft.com
Friday, November 15, 1996

[Mini-digest: 2 responses]

The following is from MFC For Yourself, October 1996.  It describes =
ON_NOTIFY_REFLECT_EX, but there is also a ON_CONTROL_REFLECT_EX.  =
ClassWizard does not handle these macros, so you must add them yourself.

Message reflection is a very powerful feature which allows a control to =
handle its own messages.  The normal windows default is that the parent =
of a control receives all of its notifications.  Using message =
reflection, you can put more logic into the control class, which makes =
it easier to create re-usable controls.
However, there are times when, even when you've used message reflection, =
you want the parent to get a control's notification also, to perform =
some additional processing.

For instance, our class CDBListView is a view class which contains an =
embedded CDBListCtrl as a child control.  Using message reflection, =
CDBListCtrl handles the LVN_ITEMCHANGED message, and moves the current =
record in its CRecordset.  But there may be a need for a class derived =
from CListView to know when this happens, also.
Using message reflection, once the control handles the message, it is =
gone.  However, there is a macro available to change this behavior.  =
Instead of using ON_NOTIFY_REFLECT to reflect the message, use =
ON_NOTIFY_REFLECT_EX.

You must change the prototype of the handler function also.  Functions =
used to handle normal reflected messages return type void.  But =
ON_NOTIFY_REFLECT_EX handlers return type BOOL.  If the function returns =
TRUE, the message will go no further, just as in normal message =
reflection.  But if it returns FALSE, the control's parent will get a =
crack at the message also.

Here's how it looks in our CDBListCtrl Message Map

BEGIN_MESSAGE_MAP(CDBListCtrl, CListCtrl)
	//{{AFX_MSG_MAP(CDBListCtrl)
	ON_NOTIFY_REFLECT_EX(LVN_ITEMCHANGED, OnItemChanged)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

BOOL CDBListCtrl::OnItemChanged(NMHDR* pNMHDR, LRESULT* pResult)=20
{
	// return TRUE to "swallow" the notification, FALSE to let the parent =
window at it
}

Mike Morel
Mushroom Software
Home of MFC For Yourself
http://www.mushroomsoft.com


----------
From: 	Steve Mark[SMTP:steve@otms.com]
Sent: 	Wednesday, November 13, 1996 5:49 PM
To: 	mfc-l@netcom.com
Subject: 	Intercepting Reflected Messages

Environment: WinNT 4.0 SP1, VC++ 4.2b

I've derived a class from CComboBox and used ClassWizard to handle the
CBN_SELCHANGE event.  The message map entry
ON_CONTROL_REFLECT(CBN_SELCHANGE, OnSelchange) is entered into the =
derived
classes message map and OnSelchange gets called just fine.  However, I =
also
need to know when this event occurs, for a specific control, in the =
CDialog
class that uses it.  I've read through help and tried to handle the =
event
in the CDialog class, but it never gets called.  Is this possible to do
(handle the event in the control class and in the dialog class)?

Thanks for your time and help

Steve


_________________________________________
Steven Mark
Principal Consultant, On-The-Mark Systems
Tel: 510.648.9514       Fax: 510/648/9507
steve@otms.com




-----From: "C.Zhang" 

Hi, Steve

Just because you implemented a message handler in your CComboBox derived
class, the message handler in CDialog class will not be called again.
But you can override the OnChildNotify in your CComboBox derived class
and return FALSE on message CBN_SELCHANGE so that CDialog class message
handler will be called again.




Alberto Massari -- alby@belva.infomus.dist.unige.it
Monday, November 18, 1996

At 14.49 13/11/96 -0800, you wrote:
>Environment: WinNT 4.0 SP1, VC++ 4.2b
>
>I've derived a class from CComboBox and used ClassWizard to handle the
>CBN_SELCHANGE event.  The message map entry
>ON_CONTROL_REFLECT(CBN_SELCHANGE, OnSelchange) is entered into the derived
>classes message map and OnSelchange gets called just fine.  However, I also
>need to know when this event occurs, for a specific control, in the CDialog
>class that uses it.  I've read through help and tried to handle the event
>in the CDialog class, but it never gets called.  Is this possible to do
>(handle the event in the control class and in the dialog class)?

Use ON_CONTROL_REFLECT_EX macro, that allows your callback function to
forward the message to the parent wnd. The declaration of your function is
slightly different, but you can find its documentation in Technical Notes.

        Alberto
----------------------------
    |\      _,,,--,,_
    /,`.-'`'   ._  \-;;,_
   |,4-  ) )_   .;.(  `'-'
  '---''(_/._)-'(_\_)    
------------------------------------------------------------------
Alby@MusArt.dist.unige.it is: 	Alberto Massari

Laboratorio di Informatica Musicale
D.I.S.T. Dipartimento di Informatica, Sistemistica e Telematica
Universita' di Genova
Via all'Opera Pia 13,
I - 16145 Genova ITALIA		http://MusArt.dist.unige.it/alby/
------------------------------------------------------------------





| Вернуться в корень Архива |