HCURSOR CMFCTreeDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CMFCTreeDlg::InitListCtrl(){ //设置图标 m_imgNormal.Create(MAKEINTRESOURCE(IDB_NORMAL), 48,48,RGB(0,0,0)); m_imgSmall.Create(MAKEINTRESOURCE(IDB_NORMAL),16,16, RGB(0,0,0)); //加载进到LIST m_wndList.SetImageList(&m_imgNormal,LVSIL_NORMAL); m_wndList.SetImageList(&m_imgSmall,LVSIL_SMALL); //初始化列 m_wndList.InsertColumn(0,"名称",LVCFMT_LEFT,100); m_wndList.InsertColumn(1,"长度",LVCFMT_LEFT,100); } void CMFCTreeDlg::OpenFilePath(CString Path){ if(m_wndList.GetItemCount()>0){ m_wndList.DeleteAllItems(); } //打开文件路径 必须后面加*.* CString strPath=Path; CFileFind find; bool bFind=find.FindFile(strPath+"*.*"); while(bFind){ //查找文件夹下层路径 bFind=find.FindNextFile(); if(find.IsDirectory()){ m_wndList.InsertItem(0,find.GetFileName(), 0); }else{ int nItem=m_wndList.InsertItem(0,find.GetFileName(),1); DWORD dwLen=find.GetLength(); CString strLen; strLen.Format("%d",dwLen); m_wndList.SetItemText(nItem,1,strLen); //文件夹文件分类 LVITEM item={0}; item.iItem=nItem; item.mask=LVIF_PARAM; item.lParam=1; m_wndList.SetItem(&item); } } m_wndList.RedrawItems(0,m_wndList.GetItemCount()); find.Close(); } void CMFCTreeDlg::ShowList(){ strPath="D:\\"; OpenFilePath(strPath); //在LIST里面添加数据 int nItem=m_wndList.InsertItem(0,"Test1",0); m_wndList.SetItemText(nItem,1,"100k"); nItem=m_wndList.InsertItem(1,"Test2",1); m_wndList.SetItemText(nItem,1,"200k"); } void CMFCTreeDlg::OnBTNNormal() { m_wndList.ModifyStyle(LVS_SMALLICON|LVS_LIST|LVS_REPORT, LVS_ICON); } void CMFCTreeDlg::OnBTNSmall() { m_wndList.ModifyStyle(LVS_LIST|LVS_REPORT|LVS_ICON, LVS_SMALLICON); } void CMFCTreeDlg::OnBTNList() { m_wndList.ModifyStyle(LVS_SMALLICON|LVS_REPORT|LVS_ICON, LVS_LIST); } void CMFCTreeDlg::OnBTNReport() { m_wndList.ModifyStyle(LVS_SMALLICON|LVS_LIST|LVS_ICON, LVS_REPORT); } void CMFCTreeDlg::OnDel() { //获取当前被选中项 int nItem=m_wndList.GetNextItem(-1,LVNI_SELECTED); if(nItem==-1){ AfxMessageBox("请选择删除项"); return; } //删除被选中项 m_wndList.DeleteItem(nItem); //重新排列 m_wndList.Arrange(LVA_DEFAULT); } int CALLBACK SortFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) { return 1; } void CMFCTreeDlg::OnSort() { m_wndList.SortItems(SortFunc,0); } void CMFCTreeDlg::OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult) { //List 消息响应双击 还有很多可以去查询MSDN LPNMLISTVIEW pNMList=(LPNMLISTVIEW)pNMHDR; *pResult = 0; if(-1==pNMList->iItem){ return; } CString strText=m_wndList.GetItemText(pNMList->iItem,0); strPath+=strText+"\\"; OpenFilePath(strPath); } void CMFCTreeDlg::OnEndlabeleditList(NMHDR* pNMHDR, LRESULT* pResult) { LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR; //List 消息响应单击修改文件名 还有很多可以去查询MSDN //文件重命名 *pResult = 0; m_wndList.SetItemText(pDispInfo->item.iItem,0,pDispInfo->item.pszText); *pResult = 0; }
程序下载:http://pan.baidu.com/s/1sjHbTaH