void CGODlg::OnBnClickedImportFolderButton()
{
// TODO: 在此添加控件通知处理程序代码
//先清空结果列表
((CListBox*)GetDlgItem(IDC_RESULT_LIST))->ResetContent();
//读取文件夹目录
char dirPath[MAX_PATH];
BROWSEINFO bi;
ITEMIDLIST *pidl;
bi.hwndOwner = this->m_hWnd;
bi.pidlRoot = NULL;
bi.pszDisplayName = (LPWSTR)dirPath;
bi.lpszTitle = _T("请选择棋谱所在的文件夹");
bi.ulFlags = BIF_RETURNONLYFSDIRS;
bi.lpfn = NULL;
bi.lParam = 0;
bi.iImage = 0;
pidl = SHBrowseForFolder(&bi);
if(pidl == NULL)
return;
if(!SHGetPathFromIDList(pidl,(LPWSTR)dirPath))
return;
//读取文件夹下的所有棋谱文件(SGF文件)
CFileFind ff;
CString filePath;
CString szDir;
szDir.Format(_T("%s"),dirPath);//= CString(dirPath);
if(szDir.Right(1) != "//")
szDir += "//";
szDir += "*.*";
BOOL res = ff.FindFile(szDir);
//设置结果列表水平滚动条宽度
CDC* pDC = ((CListBox*)GetDlgItem(IDC_RESULT_LIST))->GetDC();
//TEXTMETRIC tm;
//pDC->GetTextMetrics(&tm);
int maxWidth = 0;
CSize sz;
CString result;
while( res )
{
res = ff.FindNextFile();
if(ff.IsDirectory() && !ff.IsDots())
{
continue;
}
else if(!ff.IsDirectory() && !ff.IsDots())
{
filePath = ff.GetFilePath();
if(filePath.Right(3).CompareNoCase(_T("sgf"))!=0) //如果不是sgf文件则跳过
continue;
result= filePath;
((CListBox*)GetDlgItem(IDC_RESULT_LIST))->AddString(result);
sz = pDC->GetTextExtent(result);
//sz.cx += tm.tmAveCharWidth;
if (sz.cx > maxWidth)
maxWidth = sz.cx;
}
}
((CListBox*)GetDlgItem(IDC_RESULT_LIST))->SetHorizontalExtent(maxWidth);
ff.Close();
}