📄 mp3infotestdlg.cpp
字号:
// MP3InfoTestDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MP3InfoTest.h"
#include "MP3InfoTestDlg.h"
#include <strstrea.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()
/////////////////////////////////////////////////////////////////////////////
// CMP3InfoTestDlg dialog
CMP3InfoTestDlg::CMP3InfoTestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMP3InfoTestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMP3InfoTestDlg)
m_strFile = _T("");
m_strInfo = _T("");
m_strTitle = _T("");
m_nTrack = 0;
m_strArtist = _T("");
m_strAlbum = _T("");
m_strComment = _T("");
m_strYear = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMP3InfoTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMP3InfoTestDlg)
DDX_Control(pDX, IDC_GENRE, m_wndGenre);
DDX_Text(pDX, IDC_FILE, m_strFile);
DDX_Text(pDX, IDC_INFO, m_strInfo);
DDX_Text(pDX, IDC_TITLE, m_strTitle);
DDX_Text(pDX, IDC_TRACK, m_nTrack);
DDX_Text(pDX, IDC_ARTIST, m_strArtist);
DDX_Text(pDX, IDC_ALBUM, m_strAlbum);
DDX_Text(pDX, IDC_COMMENT, m_strComment);
DDX_Text(pDX, IDC_YEAR, m_strYear);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMP3InfoTestDlg, CDialog)
//{{AFX_MSG_MAP(CMP3InfoTestDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
ON_EN_CHANGE(IDC_FILE, OnChangeFile)
ON_BN_CLICKED(IDC_SAVE, OnSave)
ON_BN_CLICKED(IDC_CLEAR, OnClear)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMP3InfoTestDlg message handlers
BOOL CMP3InfoTestDlg::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
m_strInfo = "Open an MP3 file to see its information.";
UpdateData(FALSE);
m_wndGenre.AddString("");
for (int i = 0; i < g_nMP3GenreCount; i++)
m_wndGenre.AddString(g_arrMP3Genre[i]);
return TRUE; // return TRUE unless you set the focus to a control
}
void CMP3InfoTestDlg::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 CMP3InfoTestDlg::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 CMP3InfoTestDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMP3InfoTestDlg::OnBrowse()
{
CFileDialog fd(TRUE,"mp3",NULL,OFN_HIDEREADONLY,
"MP3's (*.mp3)|*.mp3|All Files (*.*)|*.*||",this);
if (fd.DoModal() == IDOK)
{
m_strFile = fd.GetPathName();
UpdateData(FALSE);
OnChangeFile();
}
}
ostream& operator<<(ostream& stream, const ENMPEGVER& n)
{
switch (n)
{
case MPEGVER_NA: stream << "N/A"; break;
case MPEGVER_25: stream << "MPEG 2.5"; break;
case MPEGVER_2: stream << "MPEG 2"; break;
case MPEGVER_1: stream << "MPEG 1"; break;
}
return stream;
}
ostream& operator<<(ostream& stream, const ENCHANNELMODE& n)
{
switch (n)
{
case MP3CM_STEREO: stream << "Stereo"; break;
case MP3CM_JOINT_STEREO: stream << "Joint Stereo"; break;
case MP3CM_DUAL_CHANNEL: stream << "Dual Channel"; break;
case MP3CM_SINGLE_CHANNEL: stream << "Single Channel"; break;
}
return stream;
}
ostream& operator<<(ostream& stream, const ENEMPHASIS& n)
{
switch (n)
{
case MP3EM_NONE: stream << "N/A"; break;
case MP3EM_50_15_MS: stream << "50/15 ms"; break;
case MP3EM_RESERVED: stream << "N/A"; break;
case MP3EM_CCIT_J17: stream << "CCIT J.17"; break;
}
return stream;
}
void CMP3InfoTestDlg::OnChangeFile()
{
if (!UpdateData())
return;
ostrstream s;
char* endofline = "\r\n";
CMP3Info mp3;
if (mp3.Open(m_strFile))
{
s << "File: " + mp3.GetFileName() << endofline;
s << "Validity: ";
if (mp3.GetValidity() & MP3VLD_DATA_VALID)s << "Data is okay. ";
if (mp3.GetValidity() & MP3VLD_ID3V1_VALID)s << "ID3v1 tag is okay. ";
s << endofline << endofline;
m_strTitle = mp3.GetTitle();
m_strArtist = mp3.GetArtist();
m_strAlbum = mp3.GetAlbum();
m_strComment = mp3.GetComment();
m_strYear = mp3.GetYear();
m_nTrack = mp3.GetTrack();
if (mp3.GetGenreIndex() >= g_nMP3GenreCount)
m_wndGenre.SetCurSel(0);
else
m_wndGenre.SetCurSel(mp3.GetGenreIndex() + 1);
s << "--- MP3 Frame information ---" << endofline;
s << "# of frames: " << mp3.GetNumFrames() << endofline;
s << "Length: " << CMP3Info::GetLengthString(mp3.GetLength()) << " seconds" << endofline;
s << "MPEG Type: " << mp3.GetMPEGVersion() << " Layer " << mp3.GetMPEGLayer() << endofline;
s << "CRC: " << (mp3.HasCRC() ? "Yes" : "No") << endofline;
s << "Bitrate: " << mp3.GetBitRate() << " kbps" << endofline;
s << "Sample Rate: " << mp3.GetSampleRate() << endofline;
s << "Channel Mode: " << mp3.GetChannelMode() << endofline;
s << "Emphasis: " << mp3.GetEmphasis() << endofline;
s << "Copyrighted: " << (mp3.IsCopyrighted() ? "Yes" : "No") << endofline;
s << "Original: " << (mp3.IsOriginal() ? "Yes" : "No") << endofline;
}
else
{
m_strTitle = "";
m_strArtist = "";
m_strAlbum = "";
m_strComment = "";
m_strYear = "";
m_nTrack = 0;
m_wndGenre.SetCurSel(-1);
s << "Error reading MP3 information from file '" << m_strFile << "'." << endofline;
}
s << (char)0;
m_strInfo = s.str();
UpdateData(FALSE);
}
void CMP3InfoTestDlg::OnSave()
{
if (!UpdateData())
return;
CMP3Info mp3;
mp3.SetTitle(m_strTitle);
mp3.SetArtist(m_strArtist);
mp3.SetAlbum(m_strAlbum);
mp3.SetComment(m_strComment);
mp3.SetTrack(m_nTrack);
mp3.SetYear(m_strYear);
if (m_wndGenre.GetCurSel() > 0)
mp3.SetGenreIndex(m_wndGenre.GetCurSel() - 1);
else
mp3.SetGenreIndex(255);
if (!mp3.WriteID3V1(m_strFile))
AfxMessageBox("*Error* while writing the ID3... oops :(",MB_ICONEXCLAMATION);
OnChangeFile();
}
void CMP3InfoTestDlg::OnClear()
{
CMP3Info mp3;
if (AfxMessageBox("Are you sure you want to permanently delete the ID3v1??",
MB_OKCANCEL | MB_ICONEXCLAMATION) == IDOK)
{
mp3.WriteID3V1(m_strFile,TRUE);
OnChangeFile();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -