hi @all
I want to handle the LVN_ITEMCHANGING notification for one of my CListCtrl (Report Style) to prevent change of item focus. According to MSDN, returning *pResult = TRUE from the LVN_ITEMCHANGING notification handler should prevent the change.
Problem: When I try to change the item focus by mouse and display a (Afx)MessageBox(...) within the LVN_ITEMCHANGING handler function, the message is received a 2nd time as soon as the mouse is moved.
This does not occur when either (a) I change the focus item with the cursor-keys on the keyboard or (b) I don't display a message box.
You can breakpoint in the notification handler and see, that the pNMListView data is excatly the same for the doubled message.
This is the relevant code:
I've also built a small demo project (dialog based) you may want to download and have a look into.Code:void CListCtrl_LVN_ITEMCHANGINGDlg::OnItemChangingList1(NMHDR* pNMHDR, LRESULT* pResult) { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; // check for change of LVIS_FOCUSED state if ( (pNMListView->uChanged == LVIF_STATE) && (pNMListView->uOldState == LVIS_FOCUSED) ) { // display message box AfxMessageBox("Item change not allowed."); // disallow itemchange *pResult = TRUE; } else { // allow itemchange *pResult = FALSE; } } void CListCtrl_LVN_ITEMCHANGINGDlg::OnItemChangingList2(NMHDR* pNMHDR, LRESULT* pResult) { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; // check for change of LVIS_FOCUSED state if ( (pNMListView->uChanged == LVIF_STATE) && (pNMListView->uOldState == LVIS_FOCUSED) ) { // play sound MessageBeep(MB_ICONEXCLAMATION); // disallow itemchange *pResult = TRUE; } else { // allow itemchange *pResult = FALSE; } }
Any suggestions are greatly appreciated! Thank you!
Oliver.


Reply With Quote
Bookmarks