zoukankan      html  css  js  c++  java
  • MFC CTreeCtrl运用

    CTreeCtrl运用
    删除无效资源
    递归的运用
    自写遍历目录函数
    递归遍历所有子目录
    
    
    一、删除无效资源
        1、打开资源文件
        2、找到无效链接删掉
    二、自写遍历目录函数
        CFileFind findfile;
        int nfound=findfile.FindFile(dirpath); 
         
    while(nfound)//遍历文件
        {
          nfound=findfile.FindNextFile();
         }
    三、递归遍历所有子目录
     int FindAll()
    {
       CFileFind findfile;
        int nfound=findfile.FindFile(dirpath); 
         
    while(nfound)//遍历文件
        {
          nfound=findfile.FindNextFile();
          FindAll();
         }
    }
    
    
    
    //代码示例
    //dirpath L"C:\Windows\SYSTEM32\"
    int CDialog_TreeCtrl_Test::findAll(CString dirpath,HTREEITEM parentItem)
    {
    
        static int  j=0;
        dirpath+=L"//*.*";
        //遍历D盘目录
        CTreeCtrl* ptree=(CTreeCtrl*)GetDlgItem(IDC_TREE1);
    
        CFileFind findfile;
        int nfound=findfile.FindFile(dirpath); 
         
    while(nfound)//遍历文件
        {
            nfound=findfile.FindNextFile();
            ////递归调用
            WCHAR ws[1256]=L"";
            wcscpy(ws,findfile.GetFilePath().GetString());
            
            
    if (findfile.IsDots())
            {
    
                continue;
    
            }
    if (findfile.IsDirectory())
    {            
    
       //添加数据和图标
    SHFILEINFO finfo;
    SHGetFileInfo(findfile.GetFilePath(),0,&finfo,sizeof(finfo),SHGFI_ICON |SHGFI_TYPENAME );
    //添加文件项目和图标         
    HTREEITEM hitem=ptree->InsertItem(findfile.GetFileName(),imagesmall.Add(finfo.hIcon) ,0,parentItem);
     //递归调用
    findAll(findfile.GetFilePath(),hitem);
    
    
            }
    
        }
  • 相关阅读:
    Memcached 缓存服务器介绍
    hibernate ——联合主键
    hibernate ——关联关系
    Spring与Struts整合
    spring-DataSource
    hibernate ——helloWorld程序(annotation配置)
    hibernate ——helloWorld程序(XML配置)
    Struts2 知识体系
    Encoding filter 编码过滤器
    jQuery.ajax() 函数详解
  • 原文地址:https://www.cnblogs.com/whzym111/p/6226091.html
Copyright © 2011-2022 走看看