Take clistctrl as an example. Use the cfilefind class to find a file and retrieve the file icon to fill it in clistctrl.
The main code is as follows:
Int ctestdlg: oninitdialog (void) {// obtain the control pointer clistctrl * plst_ctl = (clistctrl *) getdlgitem (idc_list1 ); // idc_list1 is the ID of the clistctrl control // Add an icon (store the icon in the cimagelist object and associate it with the clistcrtl Control) // m_imagelist_ B .create (32,32, ilc_color32 | ilc_mask, 0, 0); // large icon m_imagelist_s.create (16, 16, ilc_color32 | ilc_mask,); // small icon // plst_ctl-> setimagelist (& m_imagelist_ B, lvsil_normal ); // large icon plst_ctl-> setimagelist (& m_imagelist_s, lvsil_small); cfilefind findfile; // search for all files in the Windows directory int nfound = findfile. findfile (L "C: \ WINDOWS \\//*. * "); int I = 0; while (nfound) {nfound = findfile. findnextfile (); // if it is a folder, skip if (findfile. isdirectory () {continue;} shfileinfo finfo; // obtain the file information. The main icon is Icon shgetfileinfo (findfile. getfilepath (), 0, & finfo, sizeof (finfo), shgfi_icon); // Add a file project and an icon // m_imagelist_ B .add (finfo. hicon); // Add the icon resource plst_ctl-> insertitem (I ++, findfile to imagelist. getfilename (), m_imagelist_s.add (finfo. hicon);} findfile. close (); // release resource return 0 ;}
Running result:
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/45/B2/wKiom1Ppt1-hofzgAACScc2hoIs646.jpg "Title =" result.jpg "alt =" wKiom1Ppt1-hofzgAACScc2hoIs646.jpg "/>