PRB: HDN_XXX Notifications Incorrectly Generated for CListView (281155)
The information in this article applies to:
- The Microsoft Foundation Classes (MFC)
This article was previously published under Q281155 SYMPTOMS
You use ClassWizard to add header control notification handlers such as HDN_ENDTRACK to a CListView, but the handlers do not get executed. This article provides a way to work around this problem.
CAUSE
The header control is a child window of the CListView. The header control uses WM_NOTIFY messages to send notifications to its parent, the CListView. For your code to trap HDN_XXX notification codes therefore, you must use ON_NOTIFY handlers in the CListView class. However, the ClassWizard incorrectly inserts a ON_NOTIFY_REFLECT handler instead of a ON_NOTIFY handler.
RESOLUTIONNOTE: You can use the following procedure for any HDN_XXX notification. This example uses HDN_ENDTRACK.
- Use the ClassWizard to add a handler to HDN_ENDTRACK for the CListView-derived view.
- In the CListView-derived class's message map, delete the following line:
ON_NOTIFY_REFLECT(HDN_ENDTRACK, OnEndtrack)
- Insert the following line just before the END_MESSAGE_MAP() macro:
ON_NOTIFY(HDN_ENDTRACK, 0, OnEndtrack) // 0 is the control ID of the Header control
The prototypes/handlers that are generated by the wizard would remain the same. That is, of the form:
afx_msg void OnEndtrack(NMHDR* pNMHDR, LRESULT* pResult);
and
void CAppView::OnEndtrack(NMHDR* pNMHDR, LRESULT* pResult)
{
HD_NOTIFY *phdn = (HD_NOTIFY *) pNMHDR;
// TODO: Add your control notification handler code here
*pResult = 0;
}
respectively.
REFERENCES
For additional information on the following topics, please see the MSDN Online Library Web page listed:
(c) Microsoft Corporation 2000, All Rights Reserved. Contributions by S. Ganesh, Microsoft Corporation.
Modification Type: | Major | Last Reviewed: | 10/22/2002 |
---|
Keywords: | kbDSupport kbHeaderCtrl kbListView kbprb KB281155 |
---|
|