Basic knowledge
Custom ON_NOTIFY message
A programming system term.
ON_NOTIFY [1]: Handle WM_NOTIFY messages in MFC applications
The function CWnd :: OnNotify handles the notification message. The default implementation is to check the message map of the notification message handler and then call it. (checks the message map for notification handlers to call.)
Generally speaking, you don't need to override OnNotify. You can write a handler function, and then add a message mapping entry for the function to the message mapping table of your own window class.
ClassWizard, through the ClassWizard property page or WizardBar toolbar, can create an ON_NOTIFY message mapping entry, and provide you with a framework for processing functions.
The syntax of the ON_NOTIFY message mapping macro is as follows:
ON_NOTIFY (wNotifyCode, id, memberFxn)
The parameters in italics are replaced with:
wNotifyCode
The notification message code to be processed, such as LVN_KEYDOWN.
id
The ID of the control that sent the notification message.
memberFxn
Member function to be called after the notification message is sent.
Your member function must be declared as follows:
afx_msg void memberFxn (NMHDR * pNotifyStruct, LRESULT * result);
The parameters in italics are:
pNotifyStruct
A pointer to the notification message structure, the type is declared as above.
result
A pointer to a variable whose value is to be set before the function returns.
Code example
Now specify that you want the member function OnKeydownList1 to handle the LVN_KEYDOWN message of the CListCtrl control with IDC_LIST1. You can add the following to your message mapping table through ClassWizard:
ON_NOTIFY (LVN_KEYDOWN, IDC_LIST1, OnKeydownList1)
In the above example, the functions provided by ClassWizard are:
void CMessageReflectionDlg :: OnKeydownList1 (NMHDR * pNMHDR, LRESULT * pResult)
{
LV_KEYDOWN * pLVKeyDow = (LV_KEYDOWN *) pNMHDR;
// TODO: Add your control notification handler
// code here
* pResult = 0;
}
ClassWizard automatically generates the appropriate type of pointer. You can access the announcement message structure through pNMHDR or pLVKeyDow.
-Above from Baidu
1. Define NOTIFY message
#define NM_MOUSEUP (NM_FIRST-25)
2. Define the structure (arbitrary structure)
typedef struct tagNMLVSELFDEFINEDATA
{
NMHDR hdr;
int iStatus;
PVOID myData;
} NMLVSELFDEFINEDATA, * LPNMLVSELFDEFINEDATA;
3. Send NOTIFY message
NMLVSELFDEFINEDATA dispinfo = {0};
dispinfo.hdr.code = NM_MOUSEUP;
dispinfo.hdr.hwndFrom = m_hWnd;
dispinfo.hdr.idFrom = GetDlgCtrlID ();
dispinfo.iStatus = -1;
dispinfo.myData = NULL;
:: SendMessage (this-> GetParent ()-> m_hWnd, WM_NOTIFY, GetDlgCtrlID (), (LPARAM) & dispinfo);
4. Receive control ON_NOTIFY message
BEGIN_MESSAGE_MAP (TF_PhotoGroupDlg, CDialog)
// {{AFX_MSG_MAP (TF_PhotoGroupDlg)
ON_NOTIFY (NM_MOUSEUP, IDC_LIST_PHOTO, OnMouseUpListPhoto)
//}} AFX_MSG_MAP
END_MESSAGE_MAP ()
5..h set OnMouseUpListPhoto
// {{AFX_MSG (TF_PhotoGroupDlg)
afx_msg void OnMouseUpListPhoto (NMHDR * pNMHDR, LRESULT * pResult);
//}} AFX_MSG
DECLARE_MESSAGE_MAP ()
6.CPP setting message
void TF_PhotoGroupDlg :: OnMouseUpListPhoto (NMHDR * pNMHDR, LRESULT * pResult)
{
}
End.