VC + + Control Usage Summary of the list control

Source: Internet
Author: User

1. New dialog box MFC, put a Listctrl on the dialog

Id:idc_path

View:report

2. Adding variables for Listctrl

Right-click Add Variable M_wndpath

3. Locate the OnInitDialog () function and add the following code:

//TODO: Add additional initialization code hereM_wndpath.deleteallitems ();//ClearM_wndpath.insertcolumn (0, _t ("Project"));//Adding ColumnsM_wndpath.insertcolumn (1, _t ("location Path")); M_wndpath.setcolumnwidth (0, Max);//Set column widthsM_wndpath.setcolumnwidth (1, -); M_wndpath.setredraw (FALSE);//Prevent repaintingintNIndex;//char| TCHAR Project Properties, Character set: Using multibyte character setsTCHAR path[max_path+1];//Tchar replaces char max_path longest pathNindex=m_wndpath.insertitem (0, _t ("Windows directory") );if(NIndex <0)returnTRUE; GetWindowsDirectory (Path,max_path);//get the Windows directoryM_wndpath.setitemtext (NIndex,1, Path); Lpitemidlist Pidl;//Desktop Csidl_desktopdirectory//used to get location information for certain specific folders of the systemif(SUCCEEDED (SHGetSpecialFolderLocation (null,csidl_desktopdirectory,&PIDL)))  {    if(SHGetPathFromIDList (Pidl, Path))//function is to convert the list of item markers to the document System path{NIndex=m_wndpath.insertitem (0, _t ("Desktop"));//Success returns 0        if(NIndex <0 )        {            returnTRUE; } m_wndpath.setitemtext (NIndex,1, Path); }}m_wndpath.setredraw (TRUE);//ShowreturnTRUE;//returns TRUE unless focus is set to the control

4.char is replaced by TCHAR, to use:

Project Properties, Character set: using multibyte character sets

Reference code:

M_wndpath.deleteallitems (); M_wndpath.insertcolumn (0,"Project"); M_wndpath.insertcolumn (1,"location Path"); M_wndpath.setcolumnwidth (0, Max); M_wndpath.setcolumnwidth (1, -); M_wndpath.setredraw (FALSE);intNIndex;Const intnfolder[]={csidl_altstartup,csidl_appdata,csidl_bitbucket,csidl_common_altstartup, csidl_common_desktopdirectory, Csidl_common_favorites,csidl_common_programs, Csidl_common_startmenu,csidl_common_startup,csidl_controls,csidl_ COOKIES, Csidl_desktop,csidl_desktopdirectory,csidl_drives,csidl_favorites,csidl_fonts, CSIDL_HISTORY,CSIDL_ Internet,csidl_internet_cache,csidl_nethood,csidl_network, Csidl_personal,csidl_printers,csidl_printhood,csidl_ Programs,csidl_recent, csidl_sendto,csidl_startmenu,csidl_startup,csidl_templates};ConstCString strfoldername[]={"Csidl_altstartup","Csidl_appdata","Recycling Station","Csidl_common_altstartup",    "csidl_common_desktopdirectory","csidl_common_favorites","Csidl_common_programs",    "Csidl_common_startmenu","Csidl_common_startup","Control Panel","csidl_cookies",    "Csidl_desktop","Desktop","My Computer","Favorite Folders","Font",    "Historical Records","csidl_internet","Csidl_internet_cache","Network Neighborhood","csidl_network",    "My Documents","Printer","Csidl_printhood","program Group","recently opened documents",    "Send","task bar Start Menu Directory","Startup directory","Temporary Documents" };Charpath[max_path+1];nindex=m_wndpath.insertitem (0,"Windows directory" );if(NIndex <0)returnTRUE; GetWindowsDirectory (Path,max_path); M_wndpath.setitemtext (NIndex,1, Path); NIndex=m_wndpath.insertitem (0,"System Directory" );if(NIndex <0)returnTRUE; GetSystemDirectory (Path,max_path); M_wndpath.setitemtext (NIndex,1, Path);intI,count=sizeof(Nfolder)/sizeof(int); for(i=0; i<count;i++) {lpitemidlist pidl;    Lpmalloc Pshellmalloc; if(SUCCEEDED (Shgetmalloc (&Pshellmalloc)))  {        if(SUCCEEDED (SHGetSpecialFolderLocation (NULL, nfolder[i],&PIDL)))  {            if(SHGetPathFromIDList (Pidl, Path)) {NIndex=m_wndpath.insertitem (0, Strfoldername[i]); if(NIndex <0) {Pshellmalloc-Free (PIDL); Pshellmalloc-Release (); returnTRUE; } m_wndpath.setitemtext (NIndex,1, Path); } Pshellmalloc-Free (PIDL); } Pshellmalloc-Release (); }}m_wndpath.setredraw (TRUE);

VC + + Control Usage Summary of the list control

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.