The list control MFC CListCtrl

  • CListCtrl get selected a row

PS = the POSITION m_list.GetFirstSelectedItemPosition ();
 int NSEL = m_list.GetNextSelectedItem (PS); // index of the selected row to which (based 0)

//
if(m_list.GetSelectedCount() <1)
  return;
int nSel = m_list.GetSelectionMark();

 

  • CListCtrl control remains highlighted when losing focus

1. Add Variable header file m_nSelItem

int m_nSelItem;

2. ListCtrl control is added NM_KILLFOCUS (lose focus) and NM_SETFOCUS (obtained focus) message

manually add the code as follows:

header file, add a statement
    afx_msg void OnNMKillfocusList (NMHDR * pNMHDR, LRESULT * pResult );
    afx_msg OnNMSetfocusList void (* pNMHDR the NMHDR, LRESULT pResult *);

source file, add the mapping

    ON_NOTIFY (NM_KILLFOCUS, IDC_LISTCTRL, OnNMKillfocusList)
    ON_NOTIFY (NM_SETFOCUS, IDC_LISTCTRL, OnNMSetfocusList)

the source file, add the function

void CPageListView :: OnNMKillfocusList (NMHDR * pNMHDR , LRESULT pResult *)
{
    // the TODO: in this addition control notification handler code
    m_nSelItem m_ListCtrl.GetSelectionMark = ();
    m_ListCtrl.SetItemState (m_nSelItem, LVIS_DROPHILITED, LVIS_DROPHILITED);

    * pResult = 0;
}

:: OnNMSetfocusList CPageListView void (* pNMHDR the NMHDR, LRESULT pResult *)
{
    // the TODO: In this addition control notification handler code
    m_ListCtrl.SetItemState (m_nSelItem, FALSE, LVIF_STATE);

    * pResult = 0;
}

Note: Always Show Selection Attribute must be set to FALSE


----------------
Original link: https: //blog.csdn.net/guoxiaobo2010/article/details/21730955

 

Guess you like

Origin www.cnblogs.com/htj10/p/11705231.html