Use the cfilefind class to find a file and obtain the file icon.

Source: Internet
Author: User

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 "/>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.