PicListDlg.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // PicListDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "IDE.h"
  5. #include "PicListDlg.h"
  6. #include "Afxcoll.h"
  7. #include <io.h>
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CPicListDlg dialog
  15. CPicListDlg::CPicListDlg(CWnd* pParent /*=NULL*/)
  16. : CDialog(CPicListDlg::IDD, pParent)
  17. {
  18. //{{AFX_DATA_INIT(CPicListDlg)
  19. m_strPicName = _T("");
  20. //}}AFX_DATA_INIT
  21. }
  22. void CPicListDlg::DoDataExchange(CDataExchange* pDX)
  23. {
  24. CDialog::DoDataExchange(pDX);
  25. //{{AFX_DATA_MAP(CPicListDlg)
  26. DDX_LBString(pDX, IDC_LIST_PIC, m_strPicName);
  27. //}}AFX_DATA_MAP
  28. }
  29. BEGIN_MESSAGE_MAP(CPicListDlg, CDialog)
  30. //{{AFX_MSG_MAP(CPicListDlg)
  31. ON_LBN_DBLCLK(IDC_LIST_PIC, OnDblclkListPic)
  32. //}}AFX_MSG_MAP
  33. END_MESSAGE_MAP()
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CPicListDlg message handlers
  36. BOOL CPicListDlg::DirSearch(CString strPath, CString strFileName)
  37. {
  38. BOOL bResult = FALSE;
  39. long hDir;
  40. struct _finddata_t fDir;
  41. int nDone;
  42. strPath += "*.*";
  43. hDir = _findfirst( (char *)(LPCTSTR)strPath, &fDir );
  44. if( -1L != hDir )
  45. {
  46. while( !( nDone = _findnext(hDir, &fDir) ) )
  47. {
  48. if( !strcmp(fDir.name, "..") ) continue;
  49. if( (_A_SUBDIR == fDir.attrib) )
  50. {
  51. CString str = fDir.name;
  52. if( !str.Compare(strFileName) )
  53. {
  54. bResult = TRUE;
  55. }
  56. }
  57. }
  58. }
  59. return bResult;
  60. }
  61. void CPicListDlg::FileSearch(CListBox* pList, CString strPath, CString strFileName, int nLayer)
  62. {
  63. long hfile;
  64. struct _finddata_t fFile;
  65. CString strCurr = strPath + "\\" + strFileName;
  66. int nDone=0;
  67. hfile = _findfirst( (char *)(LPCTSTR)strCurr, &fFile );
  68. if( -1L != hfile )
  69. {
  70. while( !( nDone = _findnext(hfile, &fFile) ) )
  71. {
  72. if( !strcmp(fFile.name,"..") ) continue;
  73. if( (_A_SUBDIR == fFile.attrib) )
  74. {
  75. strCurr = strPath + "\\" + fFile.name;
  76. CString str = fFile.name;
  77. FileSearch(pList, strCurr, "*.*", nLayer + 1);
  78. pList->AddString( str );
  79. }
  80. else
  81. {
  82. CString str = fFile.name;
  83. if( str.Right(4).Compare("view") ) continue;
  84. CString strTemp = str.Left(str.GetLength()-5);
  85. if( !DirSearch(strPath + "\\", strTemp ) )
  86. {
  87. pList->AddString( str.Left(str.GetLength()-5) );
  88. }
  89. }
  90. }
  91. _findclose(hfile);
  92. }
  93. }
  94. BOOL CPicListDlg::OnInitDialog()
  95. {
  96. CDialog::OnInitDialog();
  97. CListBox* pList = (CListBox*)GetDlgItem(IDC_LIST_PIC);
  98. // ÉèÖû­Ã浱ǰÎļþ¼Ð
  99. char picDir[128];
  100. strcpy(picDir, g_strDirectory);
  101. strcat(picDir, "\\");
  102. strcat(picDir, _PICTUREDIR);
  103. FileSearch( pList, CString(picDir), "*.*", 0 );
  104. return TRUE; // return TRUE unless you set the focus to a control
  105. // EXCEPTION: OCX Property Pages should return FALSE
  106. }
  107. void CPicListDlg::OnDblclkListPic()
  108. {
  109. UpdateData(true);
  110. OnOK();
  111. }
  112. void CPicListDlg::OnOK()
  113. {
  114. CDialog::OnOK();
  115. }