| Norman Bullen 2004-10-21, 3:59 am |
| Xref: TK2MSFTNGP08.phx.gbl microsoft.public.windowsce.embedded.vc:36853 microsoft.public.pocketpc.developer:84210 microsoft.public.vstudio.general:24599 microsoft.public.win32.programmer.ui:55707
JohnL wrote:
> I am using Microsoft Visual C++ 6.0 to develop a dialog-based Win32
> application.
>
> I would like to show all the files and subdirectories of C drive with a Tree
> Control (CTreeCtrl), just like the windows file explorer does. I use
> FindFirstFile to seach the files and subdirectories, and then insert them to
> the tree control. However, I found the process is very time-consuming: it
> takes me more than 30 seconds to finish the whole process. Could anybody
> help me to speed it?
>
> Thanks in advance.
>
> John
>
> Sample:
>
> void CFileOpenDlg::EnumDirs(LPCTSTR pszPath, LPCTSTR pszFilter, HTREEITEM
> hItemParent)
> {
> WIN32_FIND_DATA fd;
> HANDLE hFind;
> BOOL bFind;
> HTREEITEM hItem = TVI_LAST;
> CString strSearch(pszPath),
> strBase(pszPath);
>
> strSearch += pszFilter;
>
> hFind = FindFirstFile(strSearch, &fd);
> bFind = (hFind != INVALID_HANDLE_VALUE);
>
> while(bFind)
> {
> if(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
> {
> CString strSub(strBase);
>
> hItem = m_treeFolder.InsertItem(fd.cFileName, 2, 3, hItemParent, hItem);
>
> if(hItem)
> {
> m_treeFolder.SetItemData(hItem, 1);
>
> strSub += fd.cFileName;
> strSub += _T("\\");
>
> EnumDirs(strSub, pszFilter, hItem);
> }
> }
>
> bFind = FindNextFile(hFind, &fd);
>
> }
> }
>
>
>
>
In addition to all the other suggestions, here's another.
Don't use recursion.
When you find a directory, add it to the end (or the front -it really
makes no difference) of an initially-empty list. When you finish
scanning a directory, scan the next one on the list. If there aren't any
more, you must be finished.
Norm
--
--
To reply, change domain to an adult feline.
|