Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
Mp3ManagerDlg.cpp
Package: Mp3Manager.zip [view]
Upload User: gkimayay
Upload Date: 2013-04-13
Package Size: 23k
Code Size: 8k
Category:
mpeg mp3
Development Platform:
Visual C++
- // Mp3ManagerDlg.cpp : implementation file
- //
- #include "my.h"
- #include "stdafx.h"
- #include "Mp3Manager.h"
- #include "Mp3ManagerDlg.h"
- #include "DirDialog.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CAboutDlg dialog used for App About
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
- // Dialog Data
- //{{AFX_DATA(CAboutDlg)
- enum { IDD = IDD_ABOUTBOX };
- //}}AFX_DATA
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CAboutDlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
- // Implementation
- protected:
- //{{AFX_MSG(CAboutDlg)
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- //{{AFX_DATA_INIT(CAboutDlg)
- //}}AFX_DATA_INIT
- }
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAboutDlg)
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- //{{AFX_MSG_MAP(CAboutDlg)
- // No message handlers
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMp3ManagerDlg dialog
- CMp3ManagerDlg::CMp3ManagerDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CMp3ManagerDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CMp3ManagerDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CMp3ManagerDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CMp3ManagerDlg)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CMp3ManagerDlg, CDialog)
- //{{AFX_MSG_MAP(CMp3ManagerDlg)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDC_BUTTON1, OnSelectSourceDir)
- ON_BN_CLICKED(IDC_BUTTON2, OnSelectDestinatDir)
- ON_BN_CLICKED(IDC_BUTTON3, OnManage)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMp3ManagerDlg message handlers
- BOOL CMp3ManagerDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // Add "About..." menu item to system menu.
- // IDM_ABOUTBOX must be in the system command range.
- ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
- ASSERT(IDM_ABOUTBOX < 0xF000);
- CMenu* pSysMenu = GetSystemMenu(FALSE);
- if (pSysMenu != NULL)
- {
- CString strAboutMenu;
- strAboutMenu.LoadString(IDS_ABOUTBOX);
- if (!strAboutMenu.IsEmpty())
- {
- pSysMenu->AppendMenu(MF_SEPARATOR);
- pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
- }
- }
- // Set the icon for this dialog. The framework does this automatically
- // when the application's main window is not a dialog
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
- // TODO: Add extra initialization here
- return TRUE; // return TRUE unless you set the focus to a control
- }
- void CMp3ManagerDlg::OnSysCommand(UINT nID, LPARAM lParam)
- {
- if ((nID & 0xFFF0) == IDM_ABOUTBOX)
- {
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
- else
- {
- CDialog::OnSysCommand(nID, lParam);
- }
- }
- // If you add a minimize button to your dialog, you will need the code below
- // to draw the icon. For MFC applications using the document/view model,
- // this is automatically done for you by the framework.
- void CMp3ManagerDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // device context for painting
- SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
- // Center icon in client rectangle
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
- // Draw the icon
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
- // The system calls this to obtain the cursor to display while the user drags
- // the minimized window.
- HCURSOR CMp3ManagerDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- void CMp3ManagerDlg::OnSelectSourceDir()
- {
- CDirDialog dlg;
- if(dlg.DoBrowse(this)==IDOK)
- m_sourceDir=dlg.m_strPath;
- SetDlgItemText(IDC_STATIC1,m_sourceDir);
- }
- void CMp3ManagerDlg::OnSelectDestinatDir()
- {
- CDirDialog dlg;
- if(dlg.DoBrowse(this)==IDOK)
- m_destinatDir=dlg.m_strPath;
- SetDlgItemText(IDC_STATIC2,m_destinatDir);
- }
- void CMp3ManagerDlg::GetCompnent(char buffer[128],MP3_INFO *p_tag)
- {
- int i,j;
- for(i=3,j=0;i<=32;i++,j++)
- p_tag->title[j]=buffer[i];
- p_tag->title[j]='';
- for(int k=2;k<31;k++)
- if(p_tag->title[k]==' '&&p_tag->title[k-1]==' '&&p_tag->title[k-2]==' ')
- p_tag->title[k-2]='';
- for(i=33,j=0;i<=62;i++)
- p_tag->artist[j++]=buffer[i];
- p_tag->artist[j]='';
- for( k=2;k<31;k++)
- if(p_tag->artist[k]==' '&&p_tag->artist[k-1]==' '&&p_tag->artist[k-2]==' ')
- p_tag->artist[k-2]='';
- for(i=63,j=0;i<=92;i++)
- p_tag->album[j++]=buffer[i];
- p_tag->album[j]='';
- for( k=2;k<31;k++)
- if(p_tag->album[k]==' '&&p_tag->album[k-1]==' '&&p_tag->album[k-2]==' ')
- p_tag->album[k-2]='';
- for(i=93,j=0;i<=96;i++)
- p_tag->year[j++]=buffer[i];
- p_tag->year[j]='';
- for(i=97,j=0;i<=126;i++)
- p_tag->comment[j++]=buffer[i];
- p_tag->comment[j]='';
- for( k=2;k<31;k++)
- if(p_tag->comment[k]==' '&&p_tag->comment[k-1]==' '&&p_tag->comment[k-2]==' ')
- p_tag->comment[k-2]='';
- for(i=127,j=0;i<=127;i++)
- p_tag->genre[j++]=buffer[i];
- p_tag->genre[j]='';
- }
- BOOL CMp3ManagerDlg::Remp3name(LPCTSTR filename)
- {
- CFile file;
- if(!file.Open(filename,CFile::modeRead))
- {
- MessageBox("在改名字的时候无法读取mp3文件");
- return FALSE;
- }
- file.SeekToEnd();
- file.Seek(-128,CFile::end);
- char buffer[128];
- file.Read(buffer,128);
- MP3_INFO mp3_info;
- GetCompnent(buffer,&mp3_info);
- CString newname;
- CString path;
- int a=file.GetFilePath().GetLength();
- int b=file.GetFileName().GetLength();
- int c=a-b;
- path=file.GetFilePath().Left(c);
- newname.Format("%s%s-[%s]%s.mp3", path, mp3_info.artist, mp3_info.album, mp3_info.title);
- file.Close();
- CFile::Rename(filename,newname);
- return TRUE;
- }
- CString CMp3ManagerDlg::Movemp3(LPCTSTR filename,LPCTSTR destinatDir)
- {
- char buffer[128];
- MP3_INFO mp3_info;
- CFile file;
- if(!file.Open(filename,CFile::modeRead))
- {
- CString a;
- a.Format("在移动文件%s时发生错误,无法读取文件",filename);
- MessageBox(a);
- }
- file.SeekToEnd();
- file.Seek(-128,CFile::end);
- file.Read(buffer,128);
- GetCompnent(buffer,&mp3_info);
- if(mp3_info.artist=="")
- {
- CString nonamedir;
- nonamedir.Format("%s\佚名",destinatDir);
- CreateDirectory(nonamedir,NULL);
- CString newnonamefile;
- newnonamefile.Format("%s\%s",nonamedir,file.GetFileName());
- file.Close();
- MoveFile(filename,newnonamefile);
- return filename;
- }
- CString newdir;
- newdir.Format("%s\%s",destinatDir,mp3_info.artist);
- CreateDirectory(newdir,NULL);
- CString newfile;
- newfile.Format("%s\%s",newdir,file.GetFileName());
- file.Close();
- MoveFile(filename,newfile);
- return newfile;
- }
- BOOL CMp3ManagerDlg::Operate(LPCTSTR sDir,LPCTSTR dDir)
- {
- CString Movedfile;
- CFileFind find;
- CString tempfind;
- tempfind.Format("%s\*.*",sDir);
- BOOL Isfinded=find.FindFile(tempfind);
- while(Isfinded)
- {
- Isfinded=find.FindNextFile();
- if(!find.IsDots())
- {
- CString findfile;
- findfile.Format("%s",find.GetFilePath());
- if(find.IsDirectory())
- {
- Operate(findfile,dDir);
- }
- if(findfile.Right(4)==".mp3"||findfile.Right(4)==".MP3")
- {
- Movedfile=Movemp3(findfile,dDir);
- Remp3name(Movedfile);
- }
- }
- }
- find.Close();
- RemoveDirectory(sDir);
- return TRUE;
- }
- void CMp3ManagerDlg::OnManage()
- {
- if(m_sourceDir==""||m_destinatDir=="")
- {
- MessageBox("请先选择目录");
- return ;
- }
- if(!Operate(m_sourceDir,m_destinatDir))
- MessageBox("Fail");
- }