为什么双击事件检测在MFC列表框的空白区域(Why double click event detec

2019-10-19 05:03发布

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.

Answer 1:

我认为这是不正常的进程。 我测试过在VS2010您的情况。 在我的测试MFC应用程序发送LBN_DBLCLK当我双击的空白区域。 如果你不是真的想知道原因,这weired情况下,你可以检查是否发生在空白区域或不双击事件。 我认为这是为节省您的时间更好的办法。

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'

    }

}

我希望这将帮助你一点。



文章来源: Why double click event detecting on empty area of listBox in mfc
标签: mfc