列目錄到listctrl (YP2002CN 來看)
rokia 2002-07-14 07:39:00
bool COTXDir::ShowDirectory(CString szFolder)
{
if(szFolder.GetAt(szFolder.GetLength()-1)!='\\')
szFolder+="\\";
WIN32_FIND_DATAA wFind;
CString szFolder0=szFolder;
szFolder.Insert(szFolder.GetLength(), "*.*");
BOOL bFind = TRUE;
HANDLE hFind = FindFirstFile(szFolder, &wFind);
CString strBack;
strBack.LoadString(IDS_FS_BACK);
if(hFind==INVALID_HANDLE_VALUE)
{
/*
CString str1;
str1.LoadString(IDS_DRIVERNOTREADY);
CString str2;
str2.LoadString(IDS_WARNING);
OTXMessageBox(m_hWnd, str1, str2, MB_OK);
//AfxSetResourceHandle(hInst);
*/ return false;
}
nNetStep=0;
_tcscpy(lpCurrentPath,szFolder0.GetBuffer(szFolder0.GetLength()));
_tcscpy(lpDisplayPath,szFolder0.GetBuffer(szFolder0.GetLength()));
m_NameEdit.SetTxt("");
m_NameEdit.SetTxt(szFolder0);
m_List.DeleteAllItems();
CString strPath=szFolder;
bInRoot=(strPath.Find('\\')==strPath.ReverseFind('\\'))||
(((!szFolder0.CompareNoCase(strDesktop))&&(nLastDrvSelect==0)))||
((!szFolder0.CompareNoCase(strMyDoc))&&(nLastDrvSelect==1));
nDirCount=0;
CString szFileName, szExt, szSize, szType;
int i;
TRACE(szFileName);
/////////@@@@@@@@@@@@@@@@@@@@@ 主要是這一段 @@@@@@@@@@@@@@@@@@@////////
while(hFind && bFind)
{
if(*wFind.cFileName != '.')
{
szFileName = wFind.cFileName;
szExt = szFileName.Mid(szFileName.ReverseFind('\\') + 1, szFileName.GetLength());
if(wFind.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
int nPos=SortList(szFileName,0,nDirCount);
i = m_List.InsertItem(nPos, szFileName, m_pShellList->FindIconID("."));
nDirCount++;
m_List.SetItemText(i, 2, "Folder");
}
else
{
//display file
if((nDirMode==1)&&(beDisplayed(szFileName)))
{
HICON h_Large,h_Small;
int iCount;
if(!szFileName.Right(3).CompareNoCase("exe"))
{
CString filename=szFolder0;
filename+=szFileName;
::ExtractIconEx(filename,0,&h_Large,&h_Small,1);
if(h_Small)
{
m_pShellList->m_Small.Add(h_Small);
m_pShellList->m_Large.Add(h_Large);
iCount=m_pShellList->pszIDList.Add(szFileName);
}
else
{
iCount=m_pShellList->AddExtIcon(szExt);
}
}
else
{
iCount=m_pShellList->AddExtIcon(szExt);
}
int nPos=SortList(szFileName,nDirCount,m_List.GetItemCount());
i = m_List.InsertItem(nPos, szFileName,iCount);
szSize.Format("%d", wFind.nFileSizeHigh + wFind.nFileSizeLow);
m_List.SetItemText(i, 1, szSize);
}
}
}
bFind = FindNextFile(hFind, &wFind);
}
if(!bInRoot) m_List.InsertItem(0,strBack,0);
FindClose(hFind);
if (bFocusOnlist)m_List.SetItemState(0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
return true;
}
有謝亂,大家受累了