// PicListDlg.cpp : implementation file // #include "stdafx.h" #include "IDE.h" #include "PicListDlg.h" #include "Afxcoll.h" #include #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CPicListDlg dialog CPicListDlg::CPicListDlg(CWnd* pParent /*=NULL*/) : CDialog(CPicListDlg::IDD, pParent) { //{{AFX_DATA_INIT(CPicListDlg) m_strPicName = _T(""); //}}AFX_DATA_INIT } void CPicListDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CPicListDlg) DDX_LBString(pDX, IDC_LIST_PIC, m_strPicName); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CPicListDlg, CDialog) //{{AFX_MSG_MAP(CPicListDlg) ON_LBN_DBLCLK(IDC_LIST_PIC, OnDblclkListPic) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CPicListDlg message handlers BOOL CPicListDlg::DirSearch(CString strPath, CString strFileName) { BOOL bResult = FALSE; long hDir; struct _finddata_t fDir; int nDone; strPath += "*.*"; hDir = _findfirst( (char *)(LPCTSTR)strPath, &fDir ); if( -1L != hDir ) { while( !( nDone = _findnext(hDir, &fDir) ) ) { if( !strcmp(fDir.name, "..") ) continue; if( (_A_SUBDIR == fDir.attrib) ) { CString str = fDir.name; if( !str.Compare(strFileName) ) { bResult = TRUE; } } } } return bResult; } void CPicListDlg::FileSearch(CListBox* pList, CString strPath, CString strFileName, int nLayer) { long hfile; struct _finddata_t fFile; CString strCurr = strPath + "\\" + strFileName; int nDone=0; hfile = _findfirst( (char *)(LPCTSTR)strCurr, &fFile ); if( -1L != hfile ) { while( !( nDone = _findnext(hfile, &fFile) ) ) { if( !strcmp(fFile.name,"..") ) continue; if( (_A_SUBDIR == fFile.attrib) ) { strCurr = strPath + "\\" + fFile.name; CString str = fFile.name; FileSearch(pList, strCurr, "*.*", nLayer + 1); pList->AddString( str ); } else { CString str = fFile.name; if( str.Right(4).Compare("view") ) continue; CString strTemp = str.Left(str.GetLength()-5); if( !DirSearch(strPath + "\\", strTemp ) ) { pList->AddString( str.Left(str.GetLength()-5) ); } } } _findclose(hfile); } } BOOL CPicListDlg::OnInitDialog() { CDialog::OnInitDialog(); CListBox* pList = (CListBox*)GetDlgItem(IDC_LIST_PIC); // 设置画面当前文件夹 char picDir[128]; strcpy(picDir, g_strDirectory); strcat(picDir, "\\"); strcat(picDir, _PICTUREDIR); FileSearch( pList, CString(picDir), "*.*", 0 ); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CPicListDlg::OnDblclkListPic() { UpdateData(true); OnOK(); } void CPicListDlg::OnOK() { CDialog::OnOK(); }