我写了一段程序,用来读取D盘的相关文件和文件夹,利用listctrl进行显示,但是出现一个问题,点击listctrl中的某一项时,该项的图标消失,点击其他项时,该项的图标又显示出来了,有人碰到过这种情况吗,是怎么解决的?
///////////////////////////////////////////////////////////////////////////////
BOOL CTestDlg::OnInitDialog()
{
CDialog::OnInitDialog(); 。。 // TODO: Add extra initialization here m_strCurFilePath = L"C:\\"; m_nImageList.Create(32,32,ILC_COLOR32, 0,0);
         m_nListctrl.SetImageList(&m_nImageList, LVSIL_NORMAL); GetAllFilesOfOneFolder(m_strCurFilePath); return TRUE;  // return TRUE  unless you set the focus to a control
}//////////////////////////////////////////////////////////////////////////////
void CTestDlg::GetAllFilesOfOneFolder(CString strFilePath)
{
m_nListctrl.DeleteAllItems(); if (L"" == strFilePath)
{
return;
} if ("\\" != strFilePath.Right(1))
{
strFilePath += "\\";
} //set current folder path as file path and then redraw the static control 
m_strCurFilePath = strFilePath;
strFilePath += "*.*"; CFileFind fileFind;
BOOL bResult = fileFind.FindFile(strFilePath); SHFILEINFO shFileInfo;
int nCount = 0; while (bResult)
{
bResult = fileFind.FindNextFile();
CString strFileName = fileFind.GetFileName(); if (!fileFind.IsDots() && !fileFind.IsSystem() && !fileFind.IsHidden())
{
CString strFilePath = m_strCurFilePath + strFileName; SHGetFileInfo(strFilePath,NULL, &shFileInfo, sizeof(SHFILEINFO), SHGFI_DISPLAYNAME | SHGFI_ICON);
int nIndex = m_nImageList.Add(shFileInfo.hIcon); m_nListctrl.InsertItem(nCount, shFileInfo.szDisplayName, nIndex); nCount++;
}
}
}