MFC资源管理器树视图里 findfile(str)函数 执行前 参数文件路径str为什么后面加了个/*
voidCLeftView::OnInitialUpdate(){CTreeView::OnInitialUpdate();SHFILEINFOFileInfo;m_Tr...
void CLeftView::OnInitialUpdate()
{
CTreeView::OnInitialUpdate();
SHFILEINFO FileInfo;
m_TreeImageList=(HIMAGELIST)SHGetFileInfo("C:\\",//添加系统图标
0,
&FileInfo,
sizeof(SHFILEINFO),
SHGFI_SYSICONINDEX|SHGFI_SMALLICON);
GetTreeCtrl().SetImageList(CImageList::FromHandle(m_TreeImageList),TVSIL_NORMAL);
GetTreeCtrl().ModifyStyle(0,GetTreeCtrl().GetStyle() | TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT | TVS_SINGLEEXPAND );
HTREEITEM RootItem=GetTreeCtrl().InsertItem("我的电脑",TVI_ROOT);
char buff[1024]={0};
GetLogicalDriveStrings(1024,buff);
char* pTemp=buff;
while(*pTemp!=0)
{
CString str;
switch(::GetDriveType(pTemp))
{
case DRIVE_FIXED:
str = "可移动磁盘";
break;
case DRIVE_REMOVABLE:
str = "可移动磁盘";
break;
case DRIVE_CDROM:
str = "光驱";
break;
default:
str = "未知磁盘";
break;
}
str = str+"("+pTemp+")";//如可移动磁盘(C:\)等
SHGetFileInfo(pTemp,
0,
&FileInfo,
sizeof(SHFILEINFO),
SHGFI_SYSICONINDEX|SHGFI_SMALLICON);
HTREEITEM SubItem=GetTreeCtrl().InsertItem(str,FileInfo.iIcon,FileInfo.iIcon,RootItem,TVI_LAST);
char* newbuff= new char[1024];
strcpy(newbuff,pTemp);
GetTreeCtrl().SetItemData(SubItem,(DWORD)newbuff);
pTemp=pTemp+4;
}
g_hWnd2=m_hWnd;
}
void CLeftView::ExpandItem(CString str, HTREEITEM rootItem)//
{
CString tempstr=str;
str+="/*"; <<<<<<--------------疑问代码!!
CFileFind finder;
SHFILEINFO FileInfo;
BOOL BeWorking=finder.FindFile(str);
while(BeWorking)
{
BeWorking=finder.FindNextFile();
if(finder.IsDots())
{
continue;
}
CString filename=finder.GetFileName();
if(!finder.IsDirectory())//略去非目录
{
continue;
}
CString filepath=finder.GetFilePath();
SHGetFileInfo(filepath,
0,
&FileInfo,
sizeof(SHFILEINFO),
SHGFI_SYSICONINDEX|SHGFI_SMALLICON);
HTREEITEM SubItem=GetTreeCtrl().InsertItem(filename,FileInfo.iIcon,FileInfo.iIcon,rootItem,TVI_LAST);
char* newbuff =new char[1024];
strcpy(newbuff,filepath.GetBuffer(0));
GetTreeCtrl().SetItemData(SubItem,(unsigned long)newbuff);
}
} 展开
{
CTreeView::OnInitialUpdate();
SHFILEINFO FileInfo;
m_TreeImageList=(HIMAGELIST)SHGetFileInfo("C:\\",//添加系统图标
0,
&FileInfo,
sizeof(SHFILEINFO),
SHGFI_SYSICONINDEX|SHGFI_SMALLICON);
GetTreeCtrl().SetImageList(CImageList::FromHandle(m_TreeImageList),TVSIL_NORMAL);
GetTreeCtrl().ModifyStyle(0,GetTreeCtrl().GetStyle() | TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT | TVS_SINGLEEXPAND );
HTREEITEM RootItem=GetTreeCtrl().InsertItem("我的电脑",TVI_ROOT);
char buff[1024]={0};
GetLogicalDriveStrings(1024,buff);
char* pTemp=buff;
while(*pTemp!=0)
{
CString str;
switch(::GetDriveType(pTemp))
{
case DRIVE_FIXED:
str = "可移动磁盘";
break;
case DRIVE_REMOVABLE:
str = "可移动磁盘";
break;
case DRIVE_CDROM:
str = "光驱";
break;
default:
str = "未知磁盘";
break;
}
str = str+"("+pTemp+")";//如可移动磁盘(C:\)等
SHGetFileInfo(pTemp,
0,
&FileInfo,
sizeof(SHFILEINFO),
SHGFI_SYSICONINDEX|SHGFI_SMALLICON);
HTREEITEM SubItem=GetTreeCtrl().InsertItem(str,FileInfo.iIcon,FileInfo.iIcon,RootItem,TVI_LAST);
char* newbuff= new char[1024];
strcpy(newbuff,pTemp);
GetTreeCtrl().SetItemData(SubItem,(DWORD)newbuff);
pTemp=pTemp+4;
}
g_hWnd2=m_hWnd;
}
void CLeftView::ExpandItem(CString str, HTREEITEM rootItem)//
{
CString tempstr=str;
str+="/*"; <<<<<<--------------疑问代码!!
CFileFind finder;
SHFILEINFO FileInfo;
BOOL BeWorking=finder.FindFile(str);
while(BeWorking)
{
BeWorking=finder.FindNextFile();
if(finder.IsDots())
{
continue;
}
CString filename=finder.GetFileName();
if(!finder.IsDirectory())//略去非目录
{
continue;
}
CString filepath=finder.GetFilePath();
SHGetFileInfo(filepath,
0,
&FileInfo,
sizeof(SHFILEINFO),
SHGFI_SYSICONINDEX|SHGFI_SMALLICON);
HTREEITEM SubItem=GetTreeCtrl().InsertItem(filename,FileInfo.iIcon,FileInfo.iIcon,rootItem,TVI_LAST);
char* newbuff =new char[1024];
strcpy(newbuff,filepath.GetBuffer(0));
GetTreeCtrl().SetItemData(SubItem,(unsigned long)newbuff);
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询