NewFolderDlg.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #include "stdafx.h"
  2. #include "ylgl.h"
  3. #include "NewFolderDlg.h"
  4. #include "ChoosePhotoSkin2.h"
  5. #ifdef _DEBUG
  6. //#define new DEBUG_NEW //wangwenbin modify 2014-04-27
  7. #undef THIS_FILE
  8. static char THIS_FILE[] = __FILE__;
  9. #endif
  10. CNewFolderDlg::CNewFolderDlg(CWnd* pParent)
  11. : CDialog(CNewFolderDlg::IDD, pParent)
  12. , m_strFolderName(_T(""))
  13. , m_pVFolder(NULL)
  14. {
  15. }
  16. CNewFolderDlg::~CNewFolderDlg()
  17. {
  18. }
  19. void CNewFolderDlg::DoDataExchange(CDataExchange* pDX) // DDX/DDV support
  20. {
  21. CDialog::DoDataExchange(pDX);
  22. }
  23. BEGIN_MESSAGE_MAP(CNewFolderDlg, CDialog)
  24. ON_WM_DESTROY()
  25. ON_BN_CLICKED(IDOK, OnOK)
  26. ON_BN_CLICKED(IDCANCEL, OnCancel)
  27. END_MESSAGE_MAP()
  28. BOOL CNewFolderDlg::OnInitDialog()
  29. {
  30. CDialog::OnInitDialog();
  31. if(m_pVFolder == NULL)
  32. return FALSE;
  33. CString strName = _T("新建文件夹");
  34. int nIdx = 0;
  35. while(1)
  36. {
  37. if(nIdx > 0 )
  38. strName.Format(_T("新建文件夹(%d)"), nIdx+1);
  39. if(!CheckFileNameIsSame(strName))
  40. break;
  41. ++nIdx;
  42. }
  43. ((CEdit*)GetDlgItem(IDC_FOLDERNAME_EDIT))->SetWindowText(strName);
  44. this->CenterWindow (g_pMainWnd);
  45. UpdateData(FALSE);
  46. return TRUE;
  47. }
  48. void CNewFolderDlg::OnOK()
  49. {
  50. ((CEdit*)GetDlgItem(IDC_FOLDERNAME_EDIT))->GetWindowText(m_strFolderName);
  51. if(m_strFolderName == _T(""))
  52. {
  53. MessageBox(_T("请输入文件夹名"));
  54. return;
  55. }
  56. //是否有同名文件
  57. if(CheckFileNameIsSame(m_strFolderName))
  58. {
  59. MessageBox(_T("文件名不能相同"));
  60. return;
  61. }
  62. //检测是否有特殊字符
  63. if(CheckSpecialChar(m_strFolderName))
  64. {
  65. MessageBox(_T("文件名不得含有下列字符:\n\\/:*?\"<>|"));
  66. return;
  67. }
  68. CDialog::OnOK();
  69. }
  70. void CNewFolderDlg::OnCancel()
  71. {
  72. CDialog::OnCancel();
  73. }
  74. /************************************************************************/
  75. /*
  76. 函数: CheckFolderName
  77. 描述: 检测特殊字符如:\/:*?"<>|;
  78. 参数:
  79. CString& str 字符串
  80. 返回:
  81. 注意: 0没有特殊字符,1有
  82. */
  83. /************************************************************************/
  84. int CNewFolderDlg::CheckSpecialChar(CString& str)
  85. {
  86. char szStr[] = _T("\\/:*?\"<>|");
  87. int nSize = strlen(szStr);
  88. BOOL bIsFind = FALSE;
  89. int i = 0;
  90. while(i<nSize)
  91. {
  92. if(str.Find(szStr[i]) != -1)
  93. {
  94. bIsFind = TRUE;
  95. break;
  96. }
  97. ++i;
  98. }
  99. if(bIsFind)
  100. return 1;
  101. return 0;
  102. }
  103. /************************************************************************/
  104. /*
  105. 函数: CheckFileNameIsSame
  106. 描述: 检测相同的文件名
  107. 参数:
  108. const CString& strName 文件名
  109. 返回:
  110. 注意: 1有相同文件名, 0没有相同文件名
  111. */
  112. /************************************************************************/
  113. int CNewFolderDlg::CheckFileNameIsSame(const CString& strName)
  114. {
  115. std::vector<SFolderInfo*>::iterator iter = m_pVFolder->begin(); //文件夹
  116. for(;iter != m_pVFolder->end();)
  117. {
  118. SFolderInfo* p = (*iter);
  119. if(p != NULL && p->strName == strName)
  120. return 1;
  121. ++iter;
  122. }
  123. return 0;
  124. }
  125. void CNewFolderDlg::OnDestroy()
  126. {
  127. m_pVFolder = NULL;
  128. CDialog::OnDestroy();
  129. }