user333422
user333422

Reputation: 377

CListCtrl - how to find it is selected

I have got a CDialog Class, inside which there are two ClistCtrl classes. I want to find out which of the listCtrl's is selected at the moment. say, listCtrl A and B. Even when I move between A and B, suppose first I go to A and select a row. Then even when I go to B and select an item there, item in A remains selected as I don't come to know that I have gone in other list.

Any suggestions, how I can find this.

Upvotes: 0

Views: 1687

Answers (2)

user333422
user333422

Reputation: 377

I found a way of doing this. I can register for NM_Click notifications on both the lists When list A is selected, I set curSel of list B to -1 and vice versa.

Upvotes: 1

detunized
detunized

Reputation: 15289

If understand you correctly, you need to know which one of list boxes has a focus. You could do that by calling GetFocus(), it returns a pointer to the focused control.

The problem you might have though is when your dialog is not an active window and then focus would be somewhere else. In this case you should be tracking WM_SETFOCUS and WM_KILLFOCUS messages and keeping record of which of the list boxes was activated last. In MFC there are callbacks CWnd::OnSetFocus and CWnd::OnKillFocus that could be used to achieve that.

Upvotes: 1

Related Questions