Message reflection for a more portable button
Michael R. Muller -- mmuller@esri.com
Friday, January 03, 1997
Environment: VC++ 4.2-flat, NT 4.0
I have a CButton derived owner-drawn button class that handles
its own BN_CLICKED message via ON_CONTROL_REFLECT(BN_CLICKED, OnClicked).
After the button executes something, I would to inform the parent
window(dlg) that the button has been clicked. Is there a preferred
method for this? The documentation states that it is possible to have
both the parent and the control process reflected messages, but I am
unable to find any examples or further doc that describes this. For now,
I have resorted to using something like...
void CMyButton::OnClicked()
{
// do something ...
...
// notify the parent that the button has been clicked
GetParent()->SendMessage(WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(),
BN_MYCLICKED), (LPARAM)(m_hWnd));
}
but this has the drawback of using a user-defined message (BN_MYCLICKED)
because using BN_CLICKED would just get reflected. Should I be looking
closer at OnNotify?
thanks in advance,
Michael Muller
mmuller@esri.com
Mike Morel -- mmorel@mushroomsoft.com
Saturday, January 04, 1997
This is from a Q & A in MFC For Yourself. October, 1996. The example is
for a list control, but should equally apply to a button:
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 class:
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()
CDBListCtrl::OnItemChanged
BOOL CDBListCtrl::OnItemChanged(NMHDR* pNMHDR, LRESULT* pResult)
{
*pResult = 0;
... do something...
return FALSE; // let the parent handle if desired
}
Mike Morel
mmorel@mushroomsoft.com
Mushroom Software
Home of MFC For Yourself
http://www.mushroomsoft.com
----------
From: Michael R. Muller[SMTP:mmuller@esri.com]
Sent: Friday, January 03, 1997 6:53 PM
To: MFC-L
Subject: Message reflection for a more portable button
Environment: VC++ 4.2-flat, NT 4.0
I have a CButton derived owner-drawn button class that handles
its own BN_CLICKED message via ON_CONTROL_REFLECT(BN_CLICKED, OnClicked).
After the button executes something, I would to inform the parent
window(dlg) that the button has been clicked. Is there a preferred
method for this? The documentation states that it is possible to have
both the parent and the control process reflected messages, but I am
unable to find any examples or further doc that describes this. For now,
I have resorted to using something like...
void CMyButton::OnClicked()
{
// do something ...
...
// notify the parent that the button has been clicked
GetParent()->SendMessage(WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(),
BN_MYCLICKED), (LPARAM)(m_hWnd));
}
but this has the drawback of using a user-defined message (BN_MYCLICKED)
because using BN_CLICKED would just get reflected. Should I be looking
closer at OnNotify?
thanks in advance,
Michael Muller
mmuller@esri.com
| Вернуться в корень Архива
|