📄 playlistdlg.cpp
字号:
CString strFormat;
if(m_playlist.GetCount()+1<10)
strFormat.Format("0%d %s",m_playlist.GetCount()+1,strShortName);
else
strFormat.Format("%d %s",m_playlist.GetCount()+1,strShortName);
m_playlist.AddString(strFormat);
if(m_nPlayMode==MODE_RAND)
theApp.RandOrder();
else
theApp.SequenceOrder();
}
}
void CPlayListDlg::OnAddFolder()
{
// TODO: Add your command handler code here
LPMALLOC pMalloc;
if(SHGetMalloc(&pMalloc)==NOERROR){
BROWSEINFO bi;
char szBuffer[MAX_PATH];
LPITEMIDLIST pidl;
bi.hwndOwner=GetSafeHwnd();
bi.pidlRoot=NULL;
bi.pszDisplayName=szBuffer;
bi.lpszTitle=TEXT("选择文件夹");
bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
bi.lpfn = NULL;
bi.lParam=0;
pidl=SHBrowseForFolder(&bi);
if(pidl!=NULL){
if(SHGetPathFromIDList(pidl,szBuffer))
{
AddFolderFiles(szBuffer);
if(m_nPlayMode==MODE_RAND)
theApp.RandOrder();
else
theApp.SequenceOrder();
}
pMalloc->Free(pidl);
}
pMalloc->Release();
}
}
void CPlayListDlg::AddFolderFiles(CString strDir)
{
_chdir(strDir);
CString strPathName;
CString strShortName;
CString strFormat;
HANDLE hFind;
WIN32_FIND_DATA wfd;
hFind=FindFirstFile(_T("*.*"),&wfd);
if(hFind==INVALID_HANDLE_VALUE)
return;
if(!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)){
if(IsSupportFile(wfd.cFileName)){
strPathName.Format("%s\\%s",strDir,wfd.cFileName);
m_strPlayListArray.Add(strPathName);
strShortName=GetFileTitle(wfd.cFileName);
if(m_playlist.GetCount()+1<10)
strFormat.Format("0%d %s",m_playlist.GetCount()+1,strShortName);
else
strFormat.Format("%d %s",m_playlist.GetCount()+1,strShortName);
m_playlist.AddString(strFormat);
}
}
while(FindNextFile(hFind,&wfd)){
if(!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)){
if(IsSupportFile(wfd.cFileName)){
strPathName.Format("%s\\%s",strDir,wfd.cFileName);
m_strPlayListArray.Add(strPathName);
strShortName=GetFileTitle(wfd.cFileName);
if(m_playlist.GetCount()+1<10)
strFormat.Format("0%d %s",m_playlist.GetCount()+1,strShortName);
else
strFormat.Format("%d %s",m_playlist.GetCount()+1,strShortName);
m_playlist.AddString(strFormat);
}
}
}
FindClose(hFind);
}
void CPlayListDlg::OnDelSelect()
{
// TODO: Add your command handler code here
int n=m_playlist.GetCurSel();
if(n<0)
return;
m_strPlayListArray.RemoveAt(n,1);
CString strGet;
CString strFileTitle;
CString strFormat;
int nPos;
for(int i=n;i<m_playlist.GetCount()-1;i++){
m_playlist.GetText(i+1,strGet);
nPos=strGet.Find(" ",0);
strFileTitle=strGet.Right(strGet.GetLength()-nPos);
if(i+1<10)
strFormat.Format("0%d%s",i+1,strFileTitle);
else
strFormat.Format("%d%s",i+1,strFileTitle);
m_playlist.InsertString(i,strFormat);
m_playlist.DeleteString(i+1);
}
m_playlist.DeleteString(i);
if(m_nPlayMode==MODE_RAND)
theApp.RandOrder();
else
theApp.SequenceOrder();
/* m_playlist.ResetContent();
for(int i=0;i<m_strPlayListArray.GetSize();i++){
strFileTitle=GetFileTitle(m_strPlayListArray.GetAt(i));
if(i+1<10)
strFormat.Format("0%d %s",i+1,strFileTitle);
else
strFormat.Format("%d %s",i+1,strFileTitle);
m_playlist.AddString(strFormat);
}*/
}
void CPlayListDlg::OnDelAll()
{
// TODO: Add your command handler code here
m_strPlayListArray.RemoveAll();
m_playlist.ResetContent();
}
void CPlayListDlg::OnListNew()
{
// TODO: Add your command handler code here
CNewListDlg dlg;
SaveList(nCurrentList);
if(dlg.DoModal()==IDOK){
m_strPlayListArray.RemoveAll();
m_playlist.ResetContent();
}
}
void CPlayListDlg::OnListDel()
{
// TODO: Add your command handler code here
CDelListDlg dlg;
dlg.DoModal();
}
void CPlayListDlg::OnListOpen1()
{
SaveList(nCurrentList);
OpenList(0);
nCurrentList=0;
}
void CPlayListDlg::OnListOpen2()
{
SaveList(nCurrentList);
OpenList(1);
nCurrentList=1;
}
void CPlayListDlg::OnListOpen3()
{
SaveList(nCurrentList);
OpenList(2);
nCurrentList=2;
}
void CPlayListDlg::OnListOpen4()
{
SaveList(nCurrentList);
OpenList(3);
nCurrentList=3;
}
void CPlayListDlg::OnListOpen5()
{
SaveList(nCurrentList);
OpenList(4);
nCurrentList=4;
}
void CPlayListDlg::OnListOpen6()
{
SaveList(nCurrentList);
OpenList(5);
nCurrentList=5;
}
void CPlayListDlg::OnListOpen7()
{
SaveList(nCurrentList);
OpenList(6);
nCurrentList=6;
}
void CPlayListDlg::OnListOpen8()
{
SaveList(nCurrentList);
OpenList(7);
nCurrentList=7;
}
void CPlayListDlg::OnListOpen9()
{
SaveList(nCurrentList);
OpenList(8);
nCurrentList=8;
}
void CPlayListDlg::OnListOpen10()
{
SaveList(nCurrentList);
OpenList(9);
nCurrentList=9;
}
BOOL CPlayListDlg::OpenList(int nIndex)
{
if(nIndex<0||nIndex>=10)
return FALSE;
CString strFileName;
strFileName.Format("%s\\%s",strCurrentDir,fileList[nIndex].strFileName);
if(!IsFileExist(strFileName)){
DeleteList(nIndex);
return FALSE;
}
m_strPlayListArray.RemoveAll();
m_playlist.ResetContent();
ifstream infile(strFileName,ios::in);
if(!infile)
return FALSE;
TCHAR szTemp[MAX_PATH];
CString strTitle;
CString strFormat;
int i=0;
while(infile.getline(szTemp,MAX_PATH)){
if(lstrlen(szTemp)>0){
m_strPlayListArray.Add(szTemp);
strTitle=GetFileTitle(szTemp);
if(i+1<10)
strFormat.Format("0%d %s",i+1,strTitle);
else
strFormat.Format("%d %s",i+1,strTitle);
m_playlist.AddString(strFormat);
i++;
}
}
infile.close();
if(m_nPlayMode==MODE_RAND)
theApp.RandOrder();
else
theApp.SequenceOrder();
m_nNowPlaying=0;
::SendMessage(m_pParent->m_hWnd,WM_PLAY,(WPARAM)m_nPlayOrder[0],NULL);
if(i>0)
return TRUE;
return FALSE;
}
BOOL CPlayListDlg::SaveList(int nIndex)
{
if(nIndex<0||nIndex>=10)
return FALSE;
CString strFileName;
strFileName.Format("%s\\%s",strCurrentDir,fileList[nIndex].strFileName);
ofstream outfile(strFileName,ios::out);
if(!outfile)
return FALSE;
for(int i=0;i<m_strPlayListArray.GetSize();i++){
outfile<<m_strPlayListArray.GetAt(i);
outfile<<endl;
}
outfile.close();
return TRUE;
}
void CPlayListDlg::OnListSave()
{
// TODO: Add your command handler code here
SaveList(nCurrentList);
}
void CPlayListDlg::OnListRename()
{
// TODO: Add your command handler code here
CRenameDlg dlg;
dlg.DoModal();
}
BOOL CPlayListDlg::DeleteList(int nIndex)
{
CString strOldName;
for(int i=nIndex;i<9;i++){
if(!fileList[i+1].strFileName.IsEmpty()){
fileList[i].strMenu=fileList[i+1].strMenu;
CopyFile(fileList[i+1].strFileName,fileList[i].strFileName,FALSE);
}else{
DeleteFile(fileList[i].strFileName);
fileList[i].strFileName="";
fileList[i].strMenu="";
}
}
ofstream outfile("listname.dat",ios::out);
for( i=0;i<10;i++){
if(!fileList[i].strFileName.IsEmpty()){
outfile<<fileList[i].strMenu<<"*-*-*-*";
outfile<<fileList[i].strFileName<<endl;
}
}
outfile.close();
if(nIndex==nCurrentList){
m_strPlayListArray.RemoveAll();
m_playlist.ResetContent();
nCurrentList=-1;
}
return TRUE;
}
BOOL CPlayListDlg::IsFileExist(CString strFileName)
{
HANDLE hFind;
WIN32_FIND_DATA wfd;
hFind=FindFirstFile(strFileName,&wfd);
if(hFind==INVALID_HANDLE_VALUE)
return FALSE;
FindClose(hFind);
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -