还有其他方法来获取选定的索引或在CLISTBOX中捕获鼠标单击事件吗? [英] Anyother way to get the selected index or capture mouse click event in a CLISTBOX ?

查看:201
本文介绍了还有其他方法来获取选定的索引或在CLISTBOX中捕获鼠标单击事件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此列表框是另一个对话框上的控件.

列表框定义:
LISTBOX IDC_LNGNAMEBOX,205,21,190,131,WS_VSCROLL | WS_HSCROLL |
ES_AUTOHSCROLL | WS_TABSTOP | LBS_NOTIFY | LBS_NOINTEGRALHEIGHT | LBS_MULTIPLESEL

数据交换:
CListBox m_LngNameList;
DDX_Control(pDX,IDC_LNGNAMEBOX,m_LngNameList);

MessageMap:
ON_LBN_SELCHANGE(IDC_LNGNAMEBOX,OnSelChangedLNGBox)
ON_LBN_DBLCLK(IDC_LNGNAMEBOX,OnMouseDBClick)

场景:
在多选列表框中,当我们单击任何选定的项目时,选择就消失了.我想使选择在用户单击后始终保持不变(至少总是选择任何一项).

Mysolution:
如果选择已更改,则如果选择已更改,则再次选择它.我已经完成了"OnSelChangedLNGBOX"功能.

问题:
当我们单击一个项目并释放鼠标(OnMouseUp)时,将调用ON_LBN_SELCHANGE.所以问题是当用户单击并按住项目时,该项目未选中,而我在OnSelChangedLNGBox中再次选择了它.这很烦人,看起来项目在闪烁,而且似乎与Windows不一致.在Windows中,如果您打开一个包含许多文档的文件夹,如果您单击鼠标下的已选择文档,则该文档仍保持选中状态,但未选中我的项目.

有问题吗?
我该如何解决?我正在尝试捕获PreTranslateMessage

This listbox is a control on another dialog.

ListBox Definition:
LISTBOX IDC_LNGNAMEBOX,205,21,190,131,WS_VSCROLL | WS_HSCROLL |
ES_AUTOHSCROLL | WS_TABSTOP | LBS_NOTIFY | LBS_NOINTEGRALHEIGHT | LBS_MULTIPLESEL

DataExchange:
CListBox m_LngNameList;
DDX_Control(pDX, IDC_LNGNAMEBOX, m_LngNameList);

MessageMap:
ON_LBN_SELCHANGE(IDC_LNGNAMEBOX, OnSelChangedLNGBox)
ON_LBN_DBLCLK(IDC_LNGNAMEBOX, OnMouseDBClick)

Scenario:
In a multiple selection listbox, when we click on any selected item, the selection goes of. I want to make the selection to stay always once the user clicks it (atleast any one item selected always).

Mysolution:
Whenever the selection changes if the item is already selected then select it again. I have done this is the "OnSelChangedLNGBOX" function.

Problem:
ON_LBN_SELCHANGE is called when we click an item and release the mouse (OnMouseUp). So the problem is when user clicks on item and holds it, the item is unselected and i am selecting back it again in OnSelChangedLNGBox. This is annoying, it looks like item is flickering, and also it doesn''t seem to be consistent with windows. In windows if you open any folder with many documents if you click on an already selected document on mouse down the document still stays selected, but my item is unselected.

Question?
How can i solve this? I am trying to capture the PreTranslateMessage

if (pMsg->message == WM_LBUTTONDOWN)
{
    SelectedItem = m_LngNameList.GetAnchorIndex();
}


但是这里选择的项目不是正确的项目,它与我在ON_LBN_SELCHANGE中获得的项目不同.


But here selected item is not the correct one, it is not the same as the one i am getting in ON_LBN_SELCHANGE. Help please?

推荐答案

看看这个 Codeproject文章 [ ^ ]讨论了不同的选择方式;单,多和扩展.这篇文章很旧,但仍然有效.
Have a look at this Codeproject article[^] discussing the different modes of selection; Single, Multiple and Extended. The article is old, but still valid.


这篇关于还有其他方法来获取选定的索引或在CLISTBOX中捕获鼠标单击事件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆