CListCtrl - 如何找到它被选中
我有一个 CDialog 类,其中有两个 ClistCtrl 类。 我想知道当前选择了哪个 listCtrl。 比如说,listCtrl A 和 B。即使当我在 A 和 B 之间移动时,假设我首先转到 A 并选择一行。然后,即使当我转到 B 并在那里选择一个项目时,A 中的项目仍然被选中,因为我不知道我已经进入了其他列表。
任何建议,我如何找到这个。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果理解正确的话,您需要知道哪个列表框具有焦点。您可以通过调用 GetFocus() 来做到这一点,它返回指向焦点控件的指针。
但您可能遇到的问题是,当您的对话框不是活动窗口时,焦点将位于其他地方。在这种情况下,您应该跟踪
WM_SETFOCUS
和WM_KILLFOCUS
消息并记录最后激活的列表框。在 MFC 中,可以使用回调CWnd::OnSetFocus
和CWnd::OnKillFocus
来实现此目的。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
andWM_KILLFOCUS
messages and keeping record of which of the list boxes was activated last. In MFC there are callbacksCWnd::OnSetFocus
andCWnd::OnKillFocus
that could be used to achieve that.我找到了一种方法来做到这一点。我可以在两个列表上注册 NM_Click 通知
当选择列表 A 时,我将列表 B 的 curSel 设置为 -1,反之亦然。
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.