📄 renamedlg.cpp
字号:
// RenameDlg.cpp : implementation file
//
#include "stdafx.h"
#include "resourceeditor.h"
#include "RenameDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CRenameDlg dialog
CRenameDlg::CRenameDlg(CWnd* pParent /*=NULL*/)
: CDialog(CRenameDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CRenameDlg)
m_strAdded = _T("");
m_strNewName = _T("");
m_strAdding = _T("");
//}}AFX_DATA_INIT
m_bDirFile = FALSE;
m_pParentNode = NULL;
m_pDirFileInfo = NULL;
m_strNewFullName = _T("");
m_strPathName = _T("");
m_eResType = MMI_RT_IMAGE;
}
void CRenameDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CRenameDlg)
DDX_Text(pDX, IDC_EDT_ADDED, m_strAdded);
DDV_MaxChars(pDX, m_strAdded, 128);
DDX_Text(pDX, IDC_EDT_NEW_NAME, m_strNewName);
DDV_MaxChars(pDX, m_strNewName, 128);
DDX_Text(pDX, IDC_EDT_ADDING, m_strAdding);
DDV_MaxChars(pDX, m_strAdding, 128);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CRenameDlg, CDialog)
//{{AFX_MSG_MAP(CRenameDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRenameDlg message handlers
void CRenameDlg::OnOK()
{
// TODO: Add extra validation here
UpdateData();
if( m_strNewName.IsEmpty() )
{
AfxMessageBox(_T("Please input the new file name!"));
return;
}
if(!m_bDirFile)
{
LPCTSTR pAdding = m_strAdding.GetBuffer(0);
LPCTSTR pFind = _tcsrchr(pAdding, _T('.'));
CMMIRes &mmires = g_theApp.m_MMIRes;
//CString strID = mmires.MakeImgID(m_strNewName);
CString strID;
BOOL bIsExsit = FALSE;
switch( m_eResType )
{
case MMI_RT_IMAGE:
strID = mmires.MakeImgID(m_strNewName);
bIsExsit = mmires.ImgIsExist(strID);
break;
case MMI_RT_ANIM:
strID = mmires.MakeAnimID(m_strNewName);
bIsExsit = mmires.AnimIsExist(strID);
break;
case MMI_RT_RING:
strID = mmires.MakeRingID(m_strNewName);
bIsExsit = mmires.RingIsExist(strID);
break;
default:
_ASSERTE( 0 );
}
if(bIsExsit)
{
m_strAdded = mmires.GetFileName(strID);
UpdateData(FALSE);
AfxMessageBox(_T("The file already exist, please reinput it!"));
m_strNewName = _T("");
UpdateData(FALSE);
return;
}
/*
if(pFind!=NULL && mmires.ImgIsExist(strID) )
{
m_strAdded = mmires.GetFileName(strID);
UpdateData(FALSE);
AfxMessageBox(_T("The file already exist, please reinput it!"));
m_strNewName = _T("");
UpdateData(FALSE);
return;
}
if(pFind==NULL && mmires.AnimIsExist(strID) )
{
m_strAdded = mmires.GetFileName(strID);
UpdateData(FALSE);
AfxMessageBox(_T("The file already exist, please reinput it!"));
m_strNewName = _T("");
UpdateData(FALSE);
return;
}*/
// make a full file name
m_strNewFullName = m_strPathName+m_strNewName;
UpdateData(FALSE);
if(pFind == NULL)//is a directory
{
m_strAdding.ReleaseBuffer();
//UpdateData(FALSE);
/* if(::CreateDirectory(m_strNewName,NULL))
{
CString strDir = m_strAdding;
strDir += _T("\\*.*");
WIN32_FIND_DATA wfd = { 0 };
HANDLE hFind = ::FindFirstFile( strDir, &wfd );
::FindNextFile(hFind, &wfd);
while( ::FindNextFile(hFind, &wfd) )
{
LPCTSTR pExt = _tcsrchr(wfd.cFileName, _T('.'));
if( pExt != NULL && _tcsicmp(pExt, ".bmp") == 0 )
{
::CopyFile(m_strAdding+"\\"+wfd.cFileName,m_strNewName+"\\"+wfd.cFileName,FALSE);
}
}
::FindClose(hFind);
}
else
{
LPTSTR pMsgBuf;
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
pMsgBuf,
0,
NULL );
AfxMessageBox( pMsgBuf );
LocalFree( pMsgBuf );
}
*/
}
else
{
m_strNewFullName += pFind;
m_strAdding.ReleaseBuffer();
UpdateData(FALSE);
/* if( !::MoveFile(m_strAdding, m_strNewName) )
{
LPTSTR pMsgBuf;
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
pMsgBuf,
0,
NULL );
AfxMessageBox( pMsgBuf );
LocalFree( pMsgBuf );
}
*/
}
}
else
{
CDirFileNode * pCNode = (CDirFileNode * )m_pDirFileInfo->GetChild(m_pParentNode);
while(pCNode != NULL)
{
if(_tcscmp(pCNode->szName, m_strNewName)==0)
{
//g_theApp.RenameFileName(pCNode->szName,m_strNewName);
m_strAdded = pCNode->szName;
UpdateData(FALSE);
AfxMessageBox(_T("The file already exist, please reinput it!"));
return;
}
pCNode = (CDirFileNode * )m_pDirFileInfo->GetNext(pCNode);
}
}
CDialog::OnOK();
}
BOOL CRenameDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if( pMsg->message == WM_CHAR )
{
_TCHAR cInput = pMsg->wParam;
if( cInput < _T('0') || cInput > _T('9') )
{
if( cInput < _T('a') || cInput > _T('z') )
{
if( cInput != VK_BACK && cInput != _T('_') &&
(cInput < _T('A') || cInput > _T('Z')) )
{
return TRUE;
}
}
}
}
return CDialog::PreTranslateMessage(pMsg);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -