我把源码上传到http://u.115.com/file/t187b15d56语法没问题就是不知为什么没效果,求改正

解决方案 »

  1.   

    void CTestDlg::Findfile(CString strl, HTREEITEM h)
    {
    CTreeCtrl*pTree=(CTreeCtrl*)GetDlgItem(IDC_TREE);
    //下面进行搜索实现文件遍历
    CFileFind filefind;
    CString filepath;
    CString filename = strl;
    tvinsert.hParent=h;
    tvinsert.item.iImage=0;
    tvinsert.item.iSelectedImage=0;

    BOOL flag=filefind.FindFile(filename );//查找文件
    while(flag)
    {
    flag=filefind.FindNextFile();
    if(filefind.IsDots())
    continue;
    else
    if(filefind.IsDirectory())//是目录则需要对目录继续遍历
    {
    filename=filefind.GetFileName();
    tvinsert.item.pszText=strdup(filename);
    tvinsert.hParent=h;
    hDad=pTree->InsertItem(&tvinsert);
    Findfile(filefind.GetFilePath()+"\\*.*",hDad);//递归查找文件
    }
    else
    {
    tvinsert.hParent=h;
    filename=filefind.GetFileName();//得到文件名
    tvinsert.item.pszText=strdup(filename);
    pTree->InsertItem(&tvinsert);//插入一项
    }
    }
    }
      

  2.   

    给个例子:char    FolderPath[MAX_PATH];
    __int64 FolderSize=0;
    int     FilesContained=0;
    int     FoldersContained=0;
    ////
    void FolderWalkRecurse(LPDIRWALKDATA pDW)
    {
    char szCurrDir[MAX_PATH];
    HANDLE hFind;
    char tmp[MAX_PATH];// set new path
    sprintf(szCurrDir,"%s%s",FolderPath,"*.*");
    hFind=FindFirstFile(szCurrDir,&pDW->FindData);
    pDW->fOK=(hFind!=INVALID_HANDLE_VALUE);
    while(pDW->fOK) // found 
    {  // till found 
    pDW->fIsDir=pDW->FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
    GetFilePart(FolderPath,tmp);// dir for recurse!
    sprintf(tmp,"%s",pDW->FindData.cFileName);
    if(strcmp(tmp,".") && strcmp(tmp,"..")) //not
    {
    if(pDW->fIsDir)
    {
    FoldersContained++;
    }
    else
    {
    FolderSize+=(pDW->FindData.nFileSizeHigh<<32) +
    pDW->FindData.nFileSizeLow;
    FilesContained++;
    }
    }
    pDW->fOK=FindNextFile(hFind,&pDW->FindData);
    }
    if(hFind!=INVALID_HANDLE_VALUE) FindClose(hFind);// handle bad
    if(pDW->fRecurse)
    {// handle OK.get the first child directory
    sprintf(szCurrDir,"%s%s",FolderPath,"*.*");
    hFind=FindFirstChildDir(szCurrDir,&pDW->FindData);
    pDW->fOK=(hFind!=INVALID_HANDLE_VALUE);
    while (pDW->fOK)
    { // change into the child directory
    sprintf(szCurrDir,"%s%s\\",FolderPath,pDW->FindData.cFileName);
    strcpy(FolderPath,szCurrDir);
    // AfxMessageBox(CString("enter Directory")+FolderPath,MB_OK);
    FolderWalkRecurse(pDW);// Perform the recursive walk.
    // change back to child's parent directory//
    GetPathPart(FolderPath);
    // AfxMessageBox(CString("leave Directory ")+FolderPath,MB_OK);
    pDW->fOK=FindNextChildDir(hFind,&pDW->FindData);
    }
    if (hFind!=INVALID_HANDLE_VALUE) FindClose(hFind);
    }
    }
    ////
    void FolderWalk(char *RootPath,BOOL fRecurse)

    DIRWALKDATA DW;
    // set new path
    strcpy(FolderPath,RootPath);
    // call the recursive function to walk the subdirectory
    DW.fRecurse=fRecurse;
    FolderWalkRecurse(&DW);
    }、、
    typedef struct
    {
    HWND            hwndTreeLB;
    BOOL            fIsList;
    BOOL            fRecurse;
    BOOL fOK;
    BOOL fIsDir;
    WIN32_FIND_DATA FindData;  
    }DIRWALKDATA, * LPDIRWALKDATA;
      

  3.   

    BOOL CTestDlg::OnInitDialog()
    {
    CDialog::OnInitDialog();

    // Add "About..." menu item to system menu.
    m_imageList.Create(16,16,0,8,8);
    hIcon=AfxGetApp()->LoadIcon(IDI_ICON1);
    m_imageList.Add(hIcon);
    CTreeCtrl*pTree=(CTreeCtrl*)GetDlgItem(IDC_TREE);
    pTree->SetImageList(&m_imageList,TVSIL_NORMAL);
    //开始显示树形视图控件
    tvinsert.hParent=NULL;
    tvinsert.hInsertAfter=TVI_LAST;
    tvinsert.item.mask=TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_TEXT;
    tvinsert.item.hItem=NULL;
    tvinsert.item.state=0;
    tvinsert.item.stateMask=0;
    tvinsert.item.cchTextMax=6;
    tvinsert.item.iSelectedImage=1;
    tvinsert.item.cChildren=0;
    tvinsert.item.lParam=0;
    //显示第一层
    tvinsert.item.pszText="D:\\";
    tvinsert.item.iImage=0;
    tvinsert.item.iSelectedImage=0;
    hDad=pTree->InsertItem(&tvinsert);
    CString filepath="D:\\*.*";
    // IDM_ABOUTBOX must be in the system command range.
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000);

    CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
    CString strAboutMenu;
    strAboutMenu.LoadString(IDS_ABOUTBOX);
    if (!strAboutMenu.IsEmpty())
    {
    pSysMenu->AppendMenu(MF_SEPARATOR);
    pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    }
    }

    // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE); // Set big icon
    SetIcon(m_hIcon, FALSE); // Set small icon

    // TODO: Add extra initialization here
    Findfile("D:\\*.*",hDad); return TRUE;  // return TRUE  unless you set the focus to a control
    }