123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- #include "stdafx.h"
- #include "ylgl.h"
- #include "NewFolderDlg.h"
- #include "ChoosePhotoSkin2.h"
- #ifdef _DEBUG
- //#define new DEBUG_NEW //wangwenbin modify 2014-04-27
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- CNewFolderDlg::CNewFolderDlg(CWnd* pParent)
- : CDialog(CNewFolderDlg::IDD, pParent)
- , m_strFolderName(_T(""))
- , m_pVFolder(NULL)
- {
-
- }
- CNewFolderDlg::~CNewFolderDlg()
- {
-
- }
- void CNewFolderDlg::DoDataExchange(CDataExchange* pDX) // DDX/DDV support
- {
- CDialog::DoDataExchange(pDX);
- }
- BEGIN_MESSAGE_MAP(CNewFolderDlg, CDialog)
- ON_WM_DESTROY()
- ON_BN_CLICKED(IDOK, OnOK)
- ON_BN_CLICKED(IDCANCEL, OnCancel)
- END_MESSAGE_MAP()
- BOOL CNewFolderDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- if(m_pVFolder == NULL)
- return FALSE;
- CString strName = _T("新建文件夹");
- int nIdx = 0;
- while(1)
- {
- if(nIdx > 0 )
- strName.Format(_T("新建文件夹(%d)"), nIdx+1);
- if(!CheckFileNameIsSame(strName))
- break;
- ++nIdx;
- }
- ((CEdit*)GetDlgItem(IDC_FOLDERNAME_EDIT))->SetWindowText(strName);
- this->CenterWindow (g_pMainWnd);
- UpdateData(FALSE);
- return TRUE;
- }
- void CNewFolderDlg::OnOK()
- {
- ((CEdit*)GetDlgItem(IDC_FOLDERNAME_EDIT))->GetWindowText(m_strFolderName);
- if(m_strFolderName == _T(""))
- {
- MessageBox(_T("请输入文件夹名"));
- return;
- }
- //是否有同名文件
- if(CheckFileNameIsSame(m_strFolderName))
- {
- MessageBox(_T("文件名不能相同"));
- return;
- }
- //检测是否有特殊字符
- if(CheckSpecialChar(m_strFolderName))
- {
- MessageBox(_T("文件名不得含有下列字符:\n\\/:*?\"<>|"));
- return;
- }
- CDialog::OnOK();
- }
- void CNewFolderDlg::OnCancel()
- {
- CDialog::OnCancel();
- }
- /************************************************************************/
- /*
- 函数: CheckFolderName
- 描述: 检测特殊字符如:\/:*?"<>|;
- 参数:
- CString& str 字符串
- 返回:
- 注意: 0没有特殊字符,1有
- */
- /************************************************************************/
- int CNewFolderDlg::CheckSpecialChar(CString& str)
- {
- char szStr[] = _T("\\/:*?\"<>|");
- int nSize = strlen(szStr);
- BOOL bIsFind = FALSE;
- int i = 0;
- while(i<nSize)
- {
- if(str.Find(szStr[i]) != -1)
- {
- bIsFind = TRUE;
- break;
- }
- ++i;
- }
- if(bIsFind)
- return 1;
- return 0;
- }
- /************************************************************************/
- /*
- 函数: CheckFileNameIsSame
- 描述: 检测相同的文件名
- 参数:
- const CString& strName 文件名
- 返回:
- 注意: 1有相同文件名, 0没有相同文件名
- */
- /************************************************************************/
- int CNewFolderDlg::CheckFileNameIsSame(const CString& strName)
- {
- std::vector<SFolderInfo*>::iterator iter = m_pVFolder->begin(); //文件夹
- for(;iter != m_pVFolder->end();)
- {
- SFolderInfo* p = (*iter);
- if(p != NULL && p->strName == strName)
- return 1;
- ++iter;
- }
- return 0;
- }
- void CNewFolderDlg::OnDestroy()
- {
- m_pVFolder = NULL;
- CDialog::OnDestroy();
- }
|