void RenameFile_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
TCHAR szPath[MAX_PATH]={0},
szOldName[MAX_PATH]={0},
szNewName[MAX_PATH]={0},
int nCount=0,i=0;
HWND hwndListBox = GetDlgItem(hwnd,IDC_LIST);
TCHAR* s=NULL;
switch(id)
{
case IDC_BUTTON_LOADFILES:
//Get the path;
Edit_GetText( GetDlgItem(hwnd,IDC_EDIT_PATH),szPath,MAX_PATH );
_tcscat(szPath,TEXT("//*"));
//File files under the path
FillListBox(hwndListBox,DDL_ARCHIVE|DDL_READWRITE,szPath);
break;
case IDOK:
//1.read filename in listbox
//2.clear [*] after the file name such as 123[1].gif
//update the listbox
nCount = ListBox_GetCount( hwndListBox);
for(i=0;i<nCount;i++)
{
ListBox_GetText(hwndListBox,i,szOldName);//szOldName:123[1].gif
_tcscpy(szNewName,szOldName);//保留原来的文件名
//1.cut the extension
//2.find [] and delete it
//从szOldName + _tcslen(szOldName) -4开始,向szOldName中copy 1个/0,即清除szOldname的后4位
_tcsncpy(szNewName + _tcslen(szNewName) -4 ,"/0",1);//szNewName :123[1]
//取出[1]来
s = _tcschr(szNewName,'['); //这时 s= [1]
if(s == 0)
continue;//忽略没有[的文件,回到for
//将szOldName的后s位去掉
_tcsncpy(szNewName + _tcslen(szNewName)-_tcslen(s) ,"/0",1); //szNewName :123
//连上原来的扩展名
_tcsncat(szNewName,TEXT(".gif"),4);
//连上完整的路径!!c:/123
Edit_GetText( GetDlgItem(hwnd,IDC_EDIT_PATH),szPath,MAX_PATH );
_tcscat(szPath,TEXT("//"));
_tcscat(szPath,szNewName);
_tcscpy(szNewName,szPath);
Edit_GetText( GetDlgItem(hwnd,IDC_EDIT_PATH),szPath,MAX_PATH );
_tcscat(szPath,TEXT("//"));
_tcscat(szPath,szOldName);
_tcscpy(szOldName,szPath);
MoveFile(szOldName,szNewName);
}
Edit_GetText( GetDlgItem(hwnd,IDC_EDIT_PATH),szPath,MAX_PATH );
_tcscat(szPath,TEXT("//*"));
FillListBox(hwndListBox,DDL_ARCHIVE|DDL_READWRITE,szPath);
break;
case IDCANCEL:
EndDialog(hwnd,id);
break;
}
}