为什么在mfc中双击listBox的空白区域进行事件检测
我认为这是一个不正常的过程。我已经在VS2010中测试了您的情况。在我的MFC测试中,当我双击空白区域时,应用程序发送了为什么在mfc中双击listBox的空白区域进行事件检测,mfc,Mfc,我认为这是一个不正常的过程。我已经在VS2010中测试了您的情况。在我的MFC测试中,当我双击空白区域时,应用程序发送了LBN\u DBLCLK。如果您真的不想知道出现这种情况的原因,您可以检查双击事件是否发生在空白区域。我认为这是节省时间的更好方法 case 1 : I have a MFC dialog box having a LisBox. I have added two items in listbox. Whenever i am double clicking on empty
LBN\u DBLCLK
。如果您真的不想知道出现这种情况的原因,您可以检查双击事件是否发生在空白区域。我认为这是节省时间的更好方法
case 1 : I have a MFC dialog box having a LisBox.
I have added two items in listbox.
Whenever i am double clicking on empty area of list box i.e. not double clicking
on either of two item.
Double click is detecting on empty area of listbox.
case 2: When i created a small MFC test application with listbox. it iis detecting double click only on item, not on empty area.
I compared all properties of both cases but couldn't figure out what is the problem.
Anyone has idea what is going wrong in case 1.
编辑:对于另一种情况
当其中一个列表框项已被选中时,它如何处理\u LBN\u DBLCLK上的处理程序?
我认为会有一些可用的方法来解决这个问题,但我使用下面的代码,这也是一种有用的方法
void CMfcDlgTestDlg::OnLbnDblclkList2()
{
// TODO: Add your control notification handler code here
CListBox* list = (CListBox*)(GetDlgItem(IDC_LIST2));
int cur_sel = list->GetCurSel();
if (cur_sel == -1)
{
return;
}
}
我希望这能对您有所帮助。当我点击空白区域时,我从未收到Dbl点击事件。你确定你说的是列表框而不是列表视图吗?是的,它只是列表框,但如果在列表中选择了一个项目,用户双击空白区域,它将在项目被选中时执行,但我们不应该执行代码,因为用户没有点击项目吗?@Suri我认为你的解释是正确的。我已经编辑了我的答案。感谢您的评论。另一个解决方案可能是从Clistbox驱动一个类并在那里处理坐标。谢谢你的解决方案也是正确的。@Suri是的,你的解决方案非常出色。非常感谢。
void CMfcDlgTestDlg::OnLbnDblclkList2()
{
// TODO: Add your control notification handler code here
CListBox* list = (CListBox*)(GetDlgItem(IDC_LIST2));
CPoint cursor;
cursor.x = GetCurrentMessage()->pt.x;
cursor.y = GetCurrentMessage()->pt.y;
list->ScreenToClient(&cursor);
BOOL is_outside = FALSE;
UINT item_index = list->ItemFromPoint(cursor, is_outside);
if(is_outside)
{
//mouse clicked on empty area
return ;
}
else
{
// do something with 'item_index'
}
}