我使用KeyDown消息处理函数,可是得不到选择项得item

解决方案 »

  1.   

    为什么不响应LVN_ITEMCHANGED呢
    pNMListView->iItem即为所选项
      

  2.   

    可是向列表中添加一行时,也触发了LVN_ITEMCHANGED事件。我需要得是用键盘改变选择一行时触发事件。
      

  3.   

    在PreTranslateMessage中处理,LVN_ITEMCHANGED中处理不太合适,呵呵
    BOOL CQuery3View::PreTranslateMessage(MSG* pMsg) 
    {
    // TODO: Add your specialized code here and/or call the base class
    if (pMsg->hwnd==m_emailList.m_hWnd) 
    {
    int nItem;
    POSITION pos;
    HTREEITEM hItem;
    hItem = m_emailTree.GetSelectedItem();
    CString strSQL;
    if (pMsg->message==WM_KEYUP) 
    {
    switch(pMsg->wParam) 
    {
    case VK_DOWN:
    pos=m_emailList.GetFirstSelectedItemPosition();
    while (pos) 
    {
    nItem=m_emailList.GetNextSelectedItem(pos);
    }
    if (hItem==m_hRecvBox) 
    {
    strSQL.Format("select * from recvbox where id=%d",m_emailList.GetItemData(nItem));
    ReadContent(&m_adoRecordSet,strSQL);
    }
    if (hItem==m_hSendBox)
    {
    strSQL.Format("select * from sendbox where id=%d",m_emailList.GetItemData(nItem));
    ReadContent(&m_adoRecordSet,strSQL);
    }
    if (hItem==m_hRecyBox) 
    {
    strSQL.Format("select * from recybox where id=%d",m_emailList.GetItemData(nItem));
    ReadContent(&m_adoRecyboxRecordSet,strSQL);
    }
    break;
    case VK_UP:
    pos=m_emailList.GetFirstSelectedItemPosition();
    while (pos) 
    {
    nItem=m_emailList.GetNextSelectedItem(pos);
    }
    if (hItem==m_hRecvBox) 
    {
    strSQL.Format("select * from recvbox where id=%d",m_emailList.GetItemData(nItem));
    ReadContent(&m_adoRecordSet,strSQL);
    }
    if (hItem==m_hSendBox)
    {
    strSQL.Format("select * from sendbox where id=%d",m_emailList.GetItemData(nItem));
    ReadContent(&m_adoRecordSet,strSQL);
    }
    if (hItem==m_hRecyBox) 
    {
    strSQL.Format("select * from recybox where id=%d",m_emailList.GetItemData(nItem));
    ReadContent(&m_adoRecyboxRecordSet,strSQL);
    }
    break;
    default:
    break;
    }
    }
    }
    return CFormView::PreTranslateMessage(pMsg);
    }
      

  4.   

    PreTranslateMessage if(pMsg->wParam==VK_UP || pMsg->wParam==VK_DOWN)
    {
    POSITION pos = m_ctlList.GetFirstSelectedItemPosition();
    int index = -1;
    if(pos)
    {
        index = m_ctlList.GetNextSelectedItem(pos); 
                                    ……
    }
    }