winapiwtl

How to get notification of child CListViewCtrl receiving focus?


Using WTL, I have a parent window with two CListViewCtrl child windows. I need to detect when a CListViewCtrl gets the focus. I tried handling WM_COMMAND, and checking if LBN_SETFOCUS is sent, but I don't get any messages for that.

Maybe clicking in a CListViewCtrl doesn't cause it to "get focus", but I'm not sure how to know which CListViewCtrl is currently active, ie if I have an item selected in one list, and then I click on the other list, the first list keeps its selection, but it is now a lighter color.

The issue is, if I select an item in listview A, then select an item in listview B, if I go back and click on the selected item in listview A, I don't get a LVN_ITEMCHANGED message because the selected item did not change.

Any way to make this work without having to subclass CListViewCtrl, and handling the WM_SETFOCUS to send a custom message to the parent? That seems heavy handed.


Solution

  • LBN_SETFOCUS is a ListBox notification. The equivalent ListView notification is NM_SETFOCUS, which is delivered in WM_NOTIFY, not in WM_COMMAND.