MFC中为ListControl控件添加NM_CLICK消息选择控件中的文件并获取文件路径和文件名字

  • 版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
    http://www.blogbus.com/shijuanfeng-logs/100675062.html

    void CListDialogDlg::OnClickListCtrl(NMHDR* pNMHDR, LRESULT* pResult)
        {
           // TODO: Add your control notification handler code here
            NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
           CString str;
           str.Format(_T(“Item index: %d,SubItem:%d”), pNMListView->iItem,

                pNMListView->iSubItem);
           MessageBox(str);
           *pResult = 0;
        }

    我改写后的,可以转为该路径下图像的代码

    void CRelCtrlDlg::OnNMClickListPhoto(NMHDR *pNMHDR, LRESULT *pResult)
    {
     // TODO: Add your control notification handler code here
     NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
     CString str;
     str = m_ListCtrl.GetItemText( pNMListView->iItem, pNMListView->iSubItem ) ;
     str =  “\\”  + str;
     str = m_szPath + str;
     char *fileName = (LPSTR)(LPCTSTR)str;
     IplImage* img = cvLoadImage(fileName);

     *pResult = 0;
    }

你可能感兴趣的:(MFC)