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.
答案 0 :(得分:2)
我认为这是异常过程。我已经在 VS2010 中测试了您的情况。在我的MFC测试应用程序中,当我双击空白区域时发送了LBN_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;
}
}
编辑:另一种情况
当已经选择了一个列表框项目时,它如何处理ON_LBN_DBLCLK
处理程序?
我认为会有一些可用的方法来解决这个问题,但是我使用下面的代码并且它也是有用的方法。
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'
}
}
我希望这对你有所帮助。