-
December 12th, 2009, 07:26 AM
#1
Edit Program to run several files at once.
Does anyone know how to edit this code so that it runs several files at once rathar than just one at a time.
mp3info.h
Code:
#if !defined(AFX_MP3INFO_H__0937E432_CE1E_4978_8ED3_FC79FD9AA7AE__INCLUDED_)
#define AFX_MP3INFO_H__0937E432_CE1E_4978_8ED3_FC79FD9AA7AE__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif
#include "resource.h"
class MP3InfoApplication : public CWinApp
{
public:
MP3InfoApplication();
public:
virtual BOOL InitInstance();
DECLARE_MESSAGE_MAP()
};
#endif
mp3info.cpp
Code:
#include "stdafx.h"
#include "mp3info.h"
#include "mp3infoProcess.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
BEGIN_MESSAGE_MAP(MP3InfoApplication, CWinApp)
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
MP3InfoApplication::MP3InfoApplication()
{
}
MP3InfoApplication theApp;
BOOL MP3InfoApplication::InitInstance()
{
AfxEnableControlContainer();
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
MP3InfoProcess Pro;
m_pMainWnd = &Pro;
int nResponse = Pro.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
mp3InfoProcess.h
Code:
//
#if !defined(AFX_MP3INFODLG_H__5CF00C98_D882_472E_AB1C_B9873E8E6983__INCLUDED_)
#define AFX_MP3INFODLG_H__5CF00C98_D882_472E_AB1C_B9873E8E6983__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
/////////////////////////////////////////////////////////////////////////////
class MP3InfoProcess : public CDialog
{
// Construction
public:
MP3InfoProcess(CWnd* pParent = NULL); // standard constructor
// Dialog Data
enum { IDD = IDD_MP3INFO_DIALOG };
CListBox m_ctlinfo;
CButton m_ctlselectfile;
CButton m_ctlreadinfo;
CString m_strfilename;
CString m_strinfo;
//}}AFX_DATA
// ClassWizard generated virtual function overrides
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
HICON m_hIcon;
// Generated message map functions
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnBreadinfo();
afx_msg void OnBselectfile();
afx_msg int readinfo();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnBnClickedBreadinfo();
afx_msg void OnLbnSelchangeLinfo();
afx_msg void OnBnClickedBselectfile();
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_MP3INFODLG_H__5CF00C98_D882_472E_AB1C_B9873E8E6983__INCLUDED_)
mp3InfoProcess.cpp
Code:
#include "stdafx.h"
#include "mp3info.h"
#include "mp3infoProcess.h"
#include "fcntl.h"
#include "io.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CString m_strfile;
CString m_strinfo;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
MP3InfoProcess::MP3InfoProcess(CWnd* pParent /*=NULL*/)
: CDialog(MP3InfoProcess::IDD, pParent)
{
m_strfilename = _T("");
m_strinfo = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void MP3InfoProcess::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LINFO, m_ctlinfo);
DDX_Control(pDX, IDC_BSELECTFILE, m_ctlselectfile);
DDX_Control(pDX, IDC_BREADINFO, m_ctlreadinfo);
DDX_Text(pDX, IDC_EFILENAME, m_strfilename);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(MP3InfoProcess, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BREADINFO, OnBreadinfo)
ON_BN_CLICKED(IDC_BSELECTFILE, OnBselectfile)
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BREADINFO, &MP3InfoProcess::OnBnClickedBreadinfo)
ON_LBN_SELCHANGE(IDC_LINFO, &MP3InfoProcess::OnLbnSelchangeLinfo)
ON_BN_CLICKED(IDC_BSELECTFILE, &MP3InfoProcess::OnBnClickedBselectfile)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
BOOL MP3InfoProcess::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_strfilename="Select file";
GetDlgItem(IDC_BREADINFO)->EnableWindow(FALSE);
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void MP3InfoProcess::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 MP3InfoProcess::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 MP3InfoProcess::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void MP3InfoProcess::OnBreadinfo()
{
// TODO: Add your control notification handler code here
MP3InfoProcess::readinfo();
}
void MP3InfoProcess::OnBselectfile()
{
// TODO: Add your control notification handler code here
static char szFilter[] = "MP3 Files (*.mp3)|*.mp3|All Files (*.*)|*.*||";
CFileDialog m_openfile(TRUE,NULL,NULL,OFN_HIDEREADONLY,szFilter,NULL);
if(m_openfile.DoModal()==IDOK)
{
m_strfilename=m_openfile.GetFileName();
m_strfile=m_openfile.GetPathName();
UpdateData(FALSE);
GetDlgItem(IDC_BREADINFO)->EnableWindow(TRUE);
}
}
int MP3InfoProcess::readinfo()
{
m_ctlinfo.ResetContent();
FILE *fp;
int curch;
int flag1=0;
fp=fopen(m_strfile,"rb");
m_strinfo="Filename : "+m_strfilename;
m_ctlinfo.AddString(m_strinfo);
// filesize.....
int handle=open(m_strfile,O_BINARY);
int filesize=filelength(handle);
char size[20];
_itoa(filesize,size,10);
m_strinfo="Size (in bytes) : ";
m_strinfo+=size;
m_ctlinfo.AddString(m_strinfo);
// finding first frame for MPEG 1 LAYER III
do
{
curch=fgetc(fp);
if(curch==255)
{
curch=fgetc(fp);
if(tolower(curch/16)==15) flag1=1;
}
}while(flag1==0);
// position of first frame header......
fpos_t filepos;
char firstframeposition[10];
fgetpos(fp,&filepos);
filepos-=2;
int firstheaderpos=filepos;
_ltoa(firstheaderpos,firstframeposition,10);
m_strinfo="First frame found at byte :";
m_strinfo+=firstframeposition;
m_ctlinfo.AddString(m_strinfo);
// version check MPEG 1/2...
int impegversion=tolower(((curch%16)/4)/2);
if(impegversion==1) m_strinfo="MPEG 1 ";
if(impegversion==0) m_strinfo="MPEG 2 ";
// layer check....
int layer=tolower((((curch%16)/4)%2)*2+(((curch%16)%4)/2));
CString mpeglayer[4]={"Reserved","Layer III","Layer II","Layer I"};
m_strinfo+=mpeglayer[layer];
m_ctlinfo.AddString(m_strinfo);
if(layer!=1) return 1;
// CRC check.......
int protectbit=tolower(((curch%16)%4)%2);
if(protectbit==1) m_strinfo="CRCs : No";
else m_strinfo="CRCs : Yes";
m_ctlinfo.AddString(m_strinfo);
//get next byte to read 3rd byte of header.
curch=fgetc(fp);
// bitrate info
int bitratetable[2][16]={0,8,16,24,32,64,80,56,64,128,160,112,128,256,320,0,0,32,40,48,56,64,80,96,112,128,160,192,224,256,320,0};
int mp3bitrate=bitratetable[impegversion][tolower(curch/16)];
char mp3bps[2];
_itoa(mp3bitrate,mp3bps,10);
m_strinfo="Bitrate (kbps) : ";
m_strinfo+=mp3bps;
m_ctlinfo.AddString(m_strinfo);
// frequency info
long int frequencytable[2][4]={22050,24000,16000,0,44100,48000,32000,0};
int mp3frequency=frequencytable[impegversion][tolower((curch%16)/4)];
char mp3fs[10];
_itoa(mp3frequency,mp3fs,10);
m_strinfo="Frequency (Hz) : ";
m_strinfo+=mp3fs;
m_ctlinfo.AddString(m_strinfo);
// padding bit
int paddingbit=tolower(((curch%16)%4)/2);
if(paddingbit==0) m_strinfo="Padding : No";
else m_strinfo="Padding : Yes";
m_ctlinfo.AddString(m_strinfo);
// private bit
int privatebit=tolower(((curch%16)%4)%2);
if(privatebit==0) m_strinfo="Private : No";
else m_strinfo="Private : Yes";
m_ctlinfo.AddString(m_strinfo);
// get next char to read 4th byte of header.
curch=fgetc(fp);
//channel mode
CString channelmode[4]={"Stereo","Joint Stereo","Dual Channel","Single Channel"};
int ichannelmode=tolower((curch/16)/4);
m_ctlinfo.AddString(channelmode[ichannelmode]);
// mode extension ignored.
// copyright bit
int copyrightbit=tolower(((curch%16)/4)/2);
if(copyrightbit==1) m_strinfo="Copyrighted : Yes";
else m_strinfo="Copyrighted : No";
m_ctlinfo.AddString(m_strinfo);
//original bit
int originalbit=tolower(((curch%16)/4)%2);
if(originalbit==1) m_strinfo="Original : Yes";
else m_strinfo="Original : No";
m_ctlinfo.AddString(m_strinfo);
//emphasis
int emphasis=tolower((curch%16)%4);
if(emphasis==0) m_strinfo="Emphasis : None";
if(emphasis==1) m_strinfo="Emphasis : 50/15 ms";
if(emphasis==3) m_strinfo="Emphasis : CCITT J.17";
m_ctlinfo.AddString(m_strinfo);
// all header info over..... calculating frame size.
int iframesize=(144000*mp3bitrate/mp3frequency)+paddingbit;
char framesize[5];
_itoa(iframesize,framesize,10);
m_strinfo="Framesize : ";
m_strinfo+=framesize;
m_ctlinfo.AddString(m_strinfo);
//no. of frames...
int iframes=(filesize-firstheaderpos)/iframesize;
char frames[10];
_itoa(iframes,frames,10);
m_strinfo="Frames : ";
m_strinfo+=frames;
m_ctlinfo.AddString(m_strinfo);
//song length...
int iplaytime=toupper(iframes*26/1000);
char playtime[5];
_itoa(iplaytime,playtime,10);
m_strinfo="Length (in sec) : ";
m_strinfo+=playtime;
m_ctlinfo.AddString(m_strinfo);
fclose(fp);
return 0;
}
void MP3InfoProcess::OnBnClickedBreadinfo()
{
// TODO: Add your control notification handler code here
}
void MP3InfoProcess::OnLbnSelchangeLinfo()
{
// TODO: Add your control notification handler code here
}
void MP3InfoProcess::OnBnClickedBselectfile()
{
// TODO: Add your control notification handler code here
}
resource.h
Code:
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by mp3info.rc
//
#define IDM_ABOUTBOX 0x0010
#define IDD_ABOUTBOX 100
#define IDS_ABOUTBOX 101
#define IDD_MP3INFO_DIALOG 102
#define IDR_MAINFRAME 128
#define IDC_BSELECTFILE 1000
#define IDC_EFILENAME 1002
#define IDC_BREADINFO 1003
#define IDC_LINFO 1004
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 129
#define _APS_NEXT_COMMAND_VALUE 32771
#define _APS_NEXT_CONTROL_VALUE 1005
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
-
December 12th, 2009, 09:54 AM
#2
Re: Edit Program to run several files at once.
mp3infoprocess:
looking at this:
Code:
void MP3InfoProcess::OnBselectfile()
{
// TODO: Add your control notification handler code here
static char szFilter[] = "MP3 Files (*.mp3)|*.mp3|All Files (*.*)|*.*||";
CFileDialog m_openfile(TRUE,NULL,NULL,OFN_HIDEREADONLY,szFilter,NULL);
if(m_openfile.DoModal()==IDOK)
{
m_strfilename=m_openfile.GetFileName();
m_strfile=m_openfile.GetPathName();
UpdateData(FALSE);
GetDlgItem(IDC_BREADINFO)->EnableWindow(TRUE);
}
}
It gets one filename. I imagine that this needs to be modified to receive a list of filenames, and to modify code later to loop over all the files.
-
December 12th, 2009, 11:03 AM
#3
Re: Edit Program to run several files at once.
I imagine that this needs to be modified to receive a list of filenames, and to modify code later to loop over all the files.
You imagined right... but ... why do you imagine ? Instead of simply looking up the helpfiles and change your code accordingly ?
The constructor of CFileDialog contains a remark and a example on how to query multiple files.
-
December 12th, 2009, 11:40 AM
#4
Re: Edit Program to run several files at once.
Originally Posted by Skizmo
You imagined right... but ... why do you imagine ? Instead of simply looking up the helpfiles and change your code accordingly ?
The constructor of CFileDialog contains a remark and a example on how to query multiple files.
'my' code?
-
December 12th, 2009, 11:56 AM
#5
Re: Edit Program to run several files at once.
Originally Posted by Amleto
'my' code?
You posted it
-
December 12th, 2009, 11:57 AM
#6
Re: Edit Program to run several files at once.
no, I copied the relevant bit from the OP, so he could see which bit I was talking about when mentioning filenames.
-
December 12th, 2009, 12:03 PM
#7
Re: Edit Program to run several files at once.
Originally Posted by Amleto
no, I copied the relevant bit from the OP, so he could see which bit I was talking about when mentioning filenames.
O sh!t.. I didn't look at your name.. confused you with the OP my bad.
-
December 12th, 2009, 12:34 PM
#8
Re: Edit Program to run several files at once.
no probs
-
December 12th, 2009, 02:48 PM
#9
Re: Edit Program to run several files at once.
Originally Posted by Amleto
mp3infoprocess:
looking at this:
Code:
void MP3InfoProcess::OnBselectfile()
{
// TODO: Add your control notification handler code here
static char szFilter[] = "MP3 Files (*.mp3)|*.mp3|All Files (*.*)|*.*||";
CFileDialog m_openfile(TRUE,NULL,NULL,OFN_HIDEREADONLY,szFilter,NULL);
if(m_openfile.DoModal()==IDOK)
{
m_strfilename=m_openfile.GetFileName();
m_strfile=m_openfile.GetPathName();
UpdateData(FALSE);
GetDlgItem(IDC_BREADINFO)->EnableWindow(TRUE);
}
}
It gets one filename. I imagine that this needs to be modified to receive a list of filenames, and to modify code later to loop over all the files.
Should I modifyit to use an 'array' of files? So something like CFileDialog m_openfile(array of four or five files)?
Something along those lines?
-
December 13th, 2009, 07:33 AM
#10
Re: Edit Program to run several files at once.
yes, using a list or a vector will probably be neater and easier to manage than a raw array.
-
December 13th, 2009, 11:08 AM
#11
Re: Edit Program to run several files at once.
What if I altered the code
Code:
void MP3InfoProcess::OnBreadinfo()
{
// TODO: Add your control notification handler code here
MP3InfoProcess::readinfo();
}
So that it reads readinfo(array of attributes)? So it calls a method which read the mp3 info for different files selected by the user.
-
December 13th, 2009, 11:42 AM
#12
Re: Edit Program to run several files at once.
Is there any way I can edit it to read a folder of files at once rather than just one single file?
-
December 13th, 2009, 11:54 AM
#13
Re: Edit Program to run several files at once.
yeah, or you could just make all of readinfo into a loop:
here is assuming lists of filenames and lists of filepaths are perfectly synchronised which is quite lazy.
Code:
int readinfo()
{
list<CString>::iterator filenameIter = m_filenames.begin();
list<CString>::iterator endIter = m_filenames.end();
list<CString>::iterator filepathIter = m_filepaths.begin();
for(; filenameIter != endIter; ++filenameIter, ++filepathIter)
{
// change all references of m_strfilename to *filenameIter
// change all references of m_strfile to *filepathIter
m_ctlinfo.ResetContent();
FILE *fp;
int curch;
int flag1=0;
fp=fopen(m_strfile,"rb");
m_strinfo="Filename : "+m_strfilename;
m_ctlinfo.AddString(m_strinfo);
// etc ...
}
}
Last edited by Amleto; December 13th, 2009 at 11:56 AM.
-
December 13th, 2009, 12:54 PM
#14
Re: Edit Program to run several files at once.
I tried editing it the way you suggested but it's causing some errors.
Here's the whole file.
Code:
#include "stdafx.h"
#include "mp3info.h"
#include "mp3infoProcess.h"
#include "fcntl.h"
#include "io.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CString filepathIter;
CString m_stringinfo;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
MP3InfoProcess::MP3InfoProcess(CWnd* pParent /*=NULL*/)
: CDialog(MP3InfoProcess::IDD, pParent)
{
filenameIter = _T("");
m_stringinfo = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void MP3InfoProcess::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LINFO, m_ctlinfo);
DDX_Control(pDX, IDC_BSELECTFILE, m_ctlselectfile);
DDX_Control(pDX, IDC_BREADINFO, m_ctlreadinfo);
DDX_Text(pDX, IDC_EFILENAME, filenameIter);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(MP3InfoProcess, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BREADINFO, OnBreadinfo)
ON_BN_CLICKED(IDC_BSELECTFILE, OnBselectfile)
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BREADINFO, &MP3InfoProcess::OnBnClickedBreadinfo)
ON_LBN_SELCHANGE(IDC_LINFO, &MP3InfoProcess::OnLbnSelchangeLinfo)
ON_BN_CLICKED(IDC_BSELECTFILE, &MP3InfoProcess::OnBnClickedBselectfile)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
BOOL MP3InfoProcess::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
filenameIter="Select file";
GetDlgItem(IDC_BREADINFO)->EnableWindow(FALSE);
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void MP3InfoProcess::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 MP3InfoProcess::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 MP3InfoProcess::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void MP3InfoProcess::OnBreadinfo()
{
// TODO: Add your control notification handler code here
MP3InfoProcess::readinfo();
}
void MP3InfoProcess::OnBselectfile()
{
for (int i=0;i<=3;i++)
{
// TODO: Add your control notification handler code here
static char szFilter[] = "MP3 Files (*.mp3)|*.mp3|All Files (*.*)|*.*||";
CFileDialog m_openfile(TRUE,NULL,NULL,OFN_HIDEREADONLY,szFilter,NULL);
if(m_openfile.DoModal()==IDOK)
{
filenameIter=m_openfile.GetFileName();
filepathIter=m_openfile.GetPathName();
UpdateData(FALSE);
GetDlgItem(IDC_BREADINFO)->EnableWindow(TRUE);
//MP3InfoProcess::readinfo();
}
}
}
int MP3InfoProcess::readinfo()
{
int readinfo()
{
list<CString>::iterator filenameIter = m_filenames.begin();
list<CString>::iterator endIter = m_filenames.end();
list<CString>::iterator filepathIter = m_filepaths.begin();
for(; filenameIter != endIter; ++filenameIter, ++filepathIter)
{
m_ctlinfo.ResetContent();
FILE *fileMp3;
int curch;
int flag1=0;
fileMp3=fopen(filepathIter,"rb");
m_stringinfo="Filename : "+filenameIter;
m_ctlinfo.AddString(m_stringinfo);
// filesize.....
int handle=open(filepathIter,O_BINARY);
int filesize=filelength(handle);
char size[20];
_itoa(filesize,size,10);
m_stringinfo="Size (in bytes) : ";
m_stringinfo+=size;
m_ctlinfo.AddString(m_stringinfo);
// finding first frame for MPEG 1 LAYER III
do
{
curch=fgetc(fileMp3);
if(curch==255)
{
curch=fgetc(fileMp3);
if(tolower(curch/16)==15) flag1=1;
}
}while(flag1==0);
// position of first frame header......
fpos_t filepos;
char firstframeposition[10];
fgetpos(fileMp3,&filepos);
filepos-=2;
int firstheaderpos=filepos;
_ltoa(firstheaderpos,firstframeposition,10);
m_stringinfo="First frame found at byte :";
m_stringinfo+=firstframeposition;
m_ctlinfo.AddString(m_stringinfo);
// version check MPEG 1/2...
int impegversion=tolower(((curch%16)/4)/2);
if(impegversion==1) m_stringinfo="MPEG 1 ";
if(impegversion==0) m_stringinfo="MPEG 2 ";
// layer check....
int layer=tolower((((curch%16)/4)%2)*2+(((curch%16)%4)/2));
CString mpeglayer[4]={"Reserved","Layer III","Layer II","Layer I"};
m_stringinfo+=mpeglayer[layer];
m_ctlinfo.AddString(m_stringinfo);
if(layer!=1) return 1;
// CRC check.......
int protectbit=tolower(((curch%16)%4)%2);
if(protectbit==1) m_stringinfo="CRCs : No";
else m_stringinfo="CRCs : Yes";
m_ctlinfo.AddString(m_stringinfo);
//get next byte to read 3rd byte of header.
curch=fgetc(fileMp3);
// bitrate info
int bitratetable[2][16]={0,8,16,24,32,64,80,56,64,128,160,112,128,256,320,0,0,32,40,48,56,64,80,96,112,128,160,192,224,256,320,0};
int mp3bitrate=bitratetable[impegversion][tolower(curch/16)];
char mp3bps[2];
_itoa(mp3bitrate,mp3bps,10);
m_stringinfo="Bitrate (kbps) : ";
m_stringinfo+=mp3bps;
m_ctlinfo.AddString(m_stringinfo);
// frequency info
long int frequencytable[2][4]={22050,24000,16000,0,44100,48000,32000,0};
int mp3frequency=frequencytable[impegversion][tolower((curch%16)/4)];
char mp3fs[10];
_itoa(mp3frequency,mp3fs,10);
m_stringinfo="Frequency (Hz) : ";
m_stringinfo+=mp3fs;
m_ctlinfo.AddString(m_stringinfo);
// padding bit
int paddingbit=tolower(((curch%16)%4)/2);
if(paddingbit==0) m_stringinfo="Padding : No";
else m_stringinfo="Padding : Yes";
m_ctlinfo.AddString(m_stringinfo);
// private bit
int privatebit=tolower(((curch%16)%4)%2);
if(privatebit==0) m_stringinfo="Private : No";
else m_stringinfo="Private : Yes";
m_ctlinfo.AddString(m_stringinfo);
// get next char to read 4th byte of header.
curch=fgetc(fileMp3);
//channel mode
CString channelmode[4]={"Stereo","Joint Stereo","Dual Channel","Single Channel"};
int ichannelmode=tolower((curch/16)/4);
m_ctlinfo.AddString(channelmode[ichannelmode]);
// mode extension ignored.
// copyright bit
int copyrightbit=tolower(((curch%16)/4)/2);
if(copyrightbit==1) m_stringinfo="Copyrighted : Yes";
else m_stringinfo="Copyrighted : No";
m_ctlinfo.AddString(m_stringinfo);
//original bit
int originalbit=tolower(((curch%16)/4)%2);
if(originalbit==1) m_stringinfo="Original : Yes";
else m_stringinfo="Original : No";
m_ctlinfo.AddString(m_stringinfo);
//emphasis
int emphasis=tolower((curch%16)%4);
if(emphasis==0) m_stringinfo="Emphasis : None";
if(emphasis==1) m_stringinfo="Emphasis : 50/15 ms";
if(emphasis==3) m_stringinfo="Emphasis : CCITT J.17";
m_ctlinfo.AddString(m_stringinfo);
// all header info over..... calculating frame size.
int iframesize=(144000*mp3bitrate/mp3frequency)+paddingbit;
char framesize[5];
_itoa(iframesize,framesize,10);
m_stringinfo="Framesize : ";
m_stringinfo+=framesize;
m_ctlinfo.AddString(m_stringinfo);
//no. of frames...
int iframes=(filesize-firstheaderpos)/iframesize;
char frames[10];
_itoa(iframes,frames,10);
m_stringinfo="Frames : ";
m_stringinfo+=frames;
m_ctlinfo.AddString(m_stringinfo);
//song length...
int iplaytime=toupper(iframes*26/1000);
char playtime[5];
_itoa(iplaytime,playtime,10);
m_stringinfo="Length of song (in secs) : ";
m_stringinfo+=playtime;
m_ctlinfo.AddString(m_stringinfo);
fclose(fileMp3);
return 0;
}
}
}
void MP3InfoProcess::OnBnClickedBreadinfo()
{
// TODO: Add your control notification handler code here
}
void MP3InfoProcess::OnLbnSelchangeLinfo()
{
// TODO: Add your control notification handler code here
}
void MP3InfoProcess::OnBnClickedBselectfile()
{
// TODO: Add your control notification handler code here
}
-
December 13th, 2009, 04:23 PM
#15
Re: Edit Program to run several files at once.
You haven't edited it the way I suggested though!
this is what you have:
Code:
void MP3InfoProcess::OnBselectfile()
{
for (int i=0;i<=3;i++)
{
// TODO: Add your control notification handler code here
static char szFilter[] = "MP3 Files (*.mp3)|*.mp3|All Files (*.*)|*.*||";
CFileDialog m_openfile(TRUE,NULL,NULL,OFN_HIDEREADONLY,szFilter,NULL);
if(m_openfile.DoModal()==IDOK)
{
filenameIter=m_openfile.GetFileName();
filepathIter=m_openfile.GetPathName();
UpdateData(FALSE);
GetDlgItem(IDC_BREADINFO)->EnableWindow(TRUE);
//MP3InfoProcess::readinfo();
}
}
}
You're using filenameIter in a different function to what I showed above, and it's not even declared anywhere in the function you put it in - of course you get errors!!
In future, you really need to highlight where errors are coming from, or provide a compilable example, because that is too much code to conveniently look over just by eye.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|