小问题,各位都帮忙看看
wenlz 2003-10-17 05:19:32 //m_lcDirDetails:CListCtrl控件
//strList:CStringList类,存放选定的目录
//功能:计算m_strList中的目录下的文件的个数和文件大小并显示在CListCtrl中
m_lcDirDetails.DeleteAllItems();
POSITION pos;
//for(pos=m_strList.GetHeadPosition();pos!=NULL;);
pos=m_strList.GetHeadPosition();//此两句用于代替
while(pos!=NULL) //上面的for语句
{
int nItem;
HANDLE hFind;
WIN32_FIND_DATA dataFind;
BOOL bMoreFiles=TRUE;
CString str,strFind;
str=m_strList.GetAt(pos);
nItem=m_lcDirDetails.InsertItem(0,str);
strFind=m_strMainDir + "\\"+str+"\\*.*";
hFind=FindFirstFile(strFind,&dataFind);
int nFileCount=0;
double nFileSize=0;
while(hFind!=INVALID_HANDLE_VALUE&&bMoreFiles==TRUE)
{
if(dataFind.dwFileAttributes==FILE_ATTRIBUTE_ARCHIVE)
{
nFileCount++;
nFileSize+=(dataFind.nFileSizeHigh*MAXDWORD+dataFind.nFileSizeLow);
}
bMoreFiles=FindNextFile(hFind,&dataFind);
}
FindClose(hFind);
str.Format("%ld",nFileCount);
m_lcDirDetails.SetItemText(nItem,1,str);
str.Format("%8.2f",nFileSize/1024.0);
m_lcDirDetails.SetItemText(nItem,2,str);
m_strList.GetNext(pos);
}
请问:为何上述代码中,用注释掉的for语句会死循环而进程死掉,改为上述代码中的有后注释的while语句则没问题?