VS2015,
CListCtrl initialization. Note that the View property of the control needs to be set to report!!!!
BOOL Cloadfileserverdlg::oninitdialog ()
{
......
Plistctr.deleteallitems (); Plistctr.insertcolumn (0, _t ("file name"), Lvcfmt_center, -); Plistctr.insertcolumn (1, _t ("File Type"), Lvcfmt_center, -); Plistctr.insertcolumn (2, _t ("File Size"), Lvcfmt_center, $); Plistctr.insertcolumn (3, _t ("Storage Path"), Lvcfmt_left, -);
......
}
//list out FilesvoidCloadfileserverdlg::getfilelist (Char*szpath) //parameter is a folder path, such as: "C:\\users\\foreverroad\\desktop\\serverimg" {Plistctr.deleteallitems (); CFileFind Finder; //set up the CString object to retrieve the matching stringCString Strwildcard (szpath); Strwildcard+ = _t ("\\*.*"); //File Internal SearchBOOL bworking =Finder. FindFile (Strwildcard); intI//For positioningcharacter, as subscript intindex =0;//For list indexCString FontName, Lasttype, filepath,filename,filesize;//Storing cut results while(bworking) {bworking=Finder. FindNextFile (); FileName=Finder. GetFileName ();
//Assuming the folder is full of pictures, get the picture file length imageSize=Finder. GetLength (); if(FileName! = _t (".") && filename! = _t ("..") ) {filepath=Finder. GetFilePath (); for(i =0; i < filename. GetLength (); i++) { if(Filename[i] = ='.') {FontName= filename. Mid (0, i); Lasttype= filename. Mid (i+1, filename. GetLength ()); FileSize. Format (_t ("%d"), imagesize/1024x768); FileSize+="k"; Plistctr.insertitem (index, fontname); Plistctr.setitemtext (Index,1, Lasttype); Plistctr.setitemtext (Index,2, FileSize); Plistctr.setitemtext (Index,3, filepath); }} Index++; }} finder. Close ();}
Folder internal content, from CMD view:
Program Run Result:
mfc--get all the files under the folder and display them on the CListCtrl