
Was 1.3 1.4 should display in the primary directory, run into the secondary directory now
My code is as follows:
//two icon is added to the imagelist
M_imageList. Create (32, 32, ILC_COLOR32, 2, 2);
M_imageList. Add (AfxGetApp () - & gt; LoadIconW (IDI_ICON_FOLDER));//folder icon
M_imageList. Add (AfxGetApp () - & gt; LoadIconW (IDI_ICON_FILE));//file icon
M_ctrlFileTree. SetImageList (& amp; M_imageList TVSIL_NORMAL);
//display the file hierarchy structure to the tree control
Void CDataBaseQueryDlg: : LoadTree (cstrings strCurdir, HTREEITEM hItem)
{
//traverse the file
If (strCurdir==L "")
return;
The else {
(1) if (strCurdir. Right! L="//")
StrCurdir +=L "//";
StrCurdir +=L "*. *";
}
CFileFind finder.
Cstrings strPath;
int i=0;
BOOL bWorking=finder. FindFile (strCurdir);
While (bWorking)
{
BWorking=finder. FindNextFileW ();
StrPath=finder. GetFilePath ();
int count=0;
If (finder. IsDirectory () & amp; & ! Finder. IsDots ())
{
HFolder=m_ctrlFileTree. InsertItem (finder. GetFileName (), 0, 0, hRoot, TVI_LAST);
count++;
LoadTree (strPath, hFolder);
}
Else if (! Finder. IsDirectory () & amp; & ! Finder. IsDots ())
{
If (count!=0)
HFile=m_ctrlFileTree. InsertItem (finder. GetFileName (), 1, 1, hRoot, TVI_LAST);
The else
HFile=m_ctrlFileTree. InsertItem (finder. GetFileName (), 1, 1, hFolder, TVI_LAST);
}
}
}
//open the need to display a directory tree structure
Void CDataBaseQueryDlg: : OnBnClickedBtnFolder ()
{
//TODO: add the control notification handler code
LPMALLOC pMalloc;//define a pointer to the IMalloc
If (: : SHGetMalloc (& amp; PMalloc)!=NOERROR)
return;
Would be szDisplayName [MAX_PATH];
Would be szBuffer [MAX_PATH];
BROWSEINFO BROWSEINFO;//dialog box structural
BrowseInfo. HwndOwner=this - & gt; M_hWnd;
BrowseInfo. PidlRoot=NULL;//set the root directory for the desktop
BrowseInfo. PszDisplayName=szDisplayName;
BrowseInfo. LpszTitle=L "select file directory search";//dialog title
BrowseInfo. UlFlags=BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
BrowseInfo. LPFN=NULL;
BrowseInfo. LParam=0;
LPITEMIDLIST LPITEMIDLIST=SHBrowseForFolderW (& amp; BrowseInfo);
If (lpItemIDList!=NULL)
{
If (: : SHGetPathFromIDListW (lpItemIDList, szBuffer))//get the directory path
{
If (=='\ 0' szBuffer [0])
return;
M_strFile=szBuffer;
The UpdateData (FALSE);
}
The else {
AfxMessageBox (L "can't get the selected file!" , MB_ICONSTOP | MB_OK);
return;
}
PMalloc - & gt; Free (lpItemIDList);
PMalloc - & gt; Release ();
}
HRoot=m_ctrlFileTree. InsertItem (m_strFile, 0, 0).
LoadTree (m_strFile hFolder);
}
Else if feeling is LoadTree function of prose has a problem, the great god, please advise, thank you!!!!!!