为什么双击事件检测在MFC中的listBox的空白区域 [英] Why double click event detecting on empty area of listBox in mfc

查看:164
本文介绍了为什么双击事件检测在MFC中的listBox的空白区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

推荐答案

我认为这是异常过程.我已经在 VS2010 中测试了您的情况.在我的MFC测试应用程序中,当我双击空白区域时发送了LBN_DBLCLK.如果您真的不想知道这种奇怪情况的原因,则只需检查是否在空白区域发生了双击事件.我认为这是节省时间的更好方法.

I think it is abnormal process. I've tested your situation in VS2010. In my MFC test application sent LBN_DBLCLK when I double clicked on empty area. If you do not really want to know the reason this weired situation, you can just check whether double click event is occurred on empty area or not. I think it is better way for saving your time.

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处理程序上进行处理? 我认为会有一些可用的方法来解决此问题,但是我使用下面的代码,它也是有用的方法.

EDIT : FOR ANOTHER CASE When one of list box item is already selected, how can it handle on ON_LBN_DBLCLK handler? I think there will be some available methods for solving this, however I use below code and it can be useful way, also.

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'

    }

}

我希望这会对您有所帮助.

I hope this will help you a little.

这篇关于为什么双击事件检测在MFC中的listBox的空白区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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