2014-01-07 36 views
1
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. 
+1

當我點擊空白區域時,我從未收到Dbl點擊事件。你確定你在談論一個ListBox而不是一個List View? – xMRi

+0

是的,它只是列表框 – Suri

回答

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' 

    } 

} 

我希望這會對你有所幫助。

+0

,但是如果在列表中選擇了一個項目並且用戶雙擊了空白區域,它將在項目被選中時執行,但是我們不應該執行代碼,因爲用戶沒有點擊項目不是? – Suri

+0

@Suri我認爲你的解釋是正確的。我編輯了我的答案。謝謝你的評論。 – hyun

+1

另一個解決方案可能是從Clistbox驅動一個類並處理那裏的座標。謝謝你的解決方案也正確。 – Suri