📄 musicripdlg.cpp
字号:
// MusicRipDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MusicRip.h"
#include "MusicRipDlg.h"
#include "General.h"
#include "Options.h"
#include <mmsystem.h>
#include <direct.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
char RetStr[200];
char CmdStr[200], TitleStr[150];
HANDLE hFileCF, hFileCFM;
char msg[MSG_LEN+1];
HWAVEIN hwi;
WAVEHDR wavehdr;
WAVEFORMATEX wfx;
MMRESULT rc;
DWORD lFileSize;
LPMMIOPROC pIOProc = NULL;
char MusicDir[MAX_PATH];
int TempMem = 75;
extern VOID RecordWave(HWND hWnd);
extern VOID CreateRiff(LPSTR);
extern LONG CALLBACK WaveIOProc(LPMMIOINFO lpmmioInfo, UINT uMsg,
LPARAM lParam1, LPARAM lParam2);
extern VOID CALLBACK waveInProc( HWAVEIN hwi, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2 );
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CMusicRipDlg dialog
CMusicRipDlg::CMusicRipDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMusicRipDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMusicRipDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMusicRipDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMusicRipDlg)
DDX_Control(pDX, ID_OPTIONS, m_Options);
DDX_Control(pDX, IDC_STATUS, m_Status);
DDX_Control(pDX, IDC_REFRESH, m_Refresh);
DDX_Control(pDX, ID_RIPCD, m_RipCd);
DDX_Control(pDX, ID_STOP, m_Stop);
DDX_Control(pDX, ID_RIPOTHER, m_RipOther);
DDX_Control(pDX, IDC_CD, m_Cd);
DDX_Control(pDX, IDC_TRACKS, m_ListCtrl);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMusicRipDlg, CDialog)
//{{AFX_MSG_MAP(CMusicRipDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_CBN_SELCHANGE(IDC_CD, OnSelchangeCd)
ON_BN_CLICKED(ID_RIPCD, OnRipcd)
ON_BN_CLICKED(ID_OPTIONS, OnOptions)
ON_BN_CLICKED(ID_STOP, OnStop)
ON_BN_CLICKED(IDC_REFRESH, OnRefresh)
ON_WM_CLOSE()
ON_BN_CLICKED(ID_RIPOTHER, OnRipother)
ON_BN_CLICKED(IDB_HELP, OnHelp)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMusicRipDlg message handlers
BOOL CMusicRipDlg::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
for(int i=0; i<26; i++){
char DrvStr[]="A:\\";
DrvStr[0] = i + 'A';
if(GetDriveType(DrvStr) == DRIVE_CDROM)
m_Cd.AddString(DrvStr);
}
m_Cd.SetCurSel(0);
m_ListCtrl.InsertColumn(0, "AudioCD Tracks", LVCFMT_LEFT, 120, 0);
OnSelchangeCd();
pIOProc = mmioInstallIOProc( (FOURCC)mmioStringToFOURCC("WAV", 0),
(LPMMIOPROC)WaveIOProc, MMIO_INSTALLPROC);
if (!pIOProc)
AfxMessageBox("Install I/O proc failure.", NULL, MB_OK);
// allocate data block
// using only one data block in order to
// keep this example simple
//......................................
wavehdr.lpData = NULL;
return TRUE; // return TRUE unless you set the focus to a control
}
void CMusicRipDlg::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 CMusicRipDlg::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 CMusicRipDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
/*void CMusicRipDlg::OnOK()
{
// TODO: Add extra validation here
mciSendString("open cdaudio", RetStr, 100, NULL);
mciSendString("set cdaudio time format tmsf", RetStr, 100, NULL);
mciSendString("play cdaudio from 1 to 2", RetStr, 100, NULL);
mciSendString("close cdaudio", RetStr, 100, NULL);
} */
/*void CMusicRipDlg::OnCancel()
{
// TODO: Add extra cleanup here
// mciSendString("stop cdaudio", RetStr, 100, NULL);
// UnmapViewOfFile(wavehdr.lpData);
// CloseHandle(hFileCF);
// CloseHandle(hFileCFM);
// DeleteFile("TEMP.TMP");
// VirtualFree(wavehdr.lpData, 0, MEM_RELEASE);
// CDialog::OnCancel();
}*/
void CMusicRipDlg::OnSelchangeCd()
{
// TODO: Add your control notification handler code here
WIN32_FIND_DATA ff;
char CurDrv[10];
UpdateData(TRUE);
::GetWindowText(m_Cd.m_hWnd, CurDrv, 10);
_chdir(CurDrv);
HANDLE hFf;
int i=0;
m_ListCtrl.DeleteAllItems();
if((hFf = FindFirstFile("*.cda", &ff)) == INVALID_HANDLE_VALUE)
return;
do{
m_ListCtrl.InsertItem(i++, ff.cFileName, NULL);
}while(FindNextFile(hFf, &ff));
CloseHandle(hFf);
}
void CMusicRipDlg::OnRipcd()
{
// TODO: Add your control notification handler code here
if(!strlen(MusicDir)){
AfxMessageBox("First enter some destination directory through Options!");
return;
}
if(!m_ListCtrl.GetSelectedCount()){
AfxMessageBox("Select atleast one item to extract");
return;
}
int Tmp = m_ListCtrl.GetItemCount();
for(int i=0; i<Tmp; i++){
if(m_ListCtrl.GetItemState(i, LVIS_SELECTED)==LVIS_SELECTED){
if((i+1) != Tmp)
wsprintf(CmdStr, "play cdaudio from %u to %u", i+1, i+2);
else
wsprintf(CmdStr, "play cdaudio from %u", i+1);
m_ListCtrl.GetItemText(i, 0, TitleStr, 100);
strcat(TitleStr, ".Wav");
}
else
continue;
char TmpStr[MAX_PATH];
strcpy(TmpStr, MusicDir);
if(TmpStr[3] != 0)
strcat(TmpStr, "\\");
strcat(TmpStr, TitleStr);
strcpy(TitleStr, TmpStr);
_lclose(_lcreat(TitleStr, 0));
mciSendString("open cdaudio", RetStr, 100, NULL);
mciSendString("set cdaudio time format tmsf", RetStr, 100, NULL);
RecordWave(this->m_hWnd);
mciSendString(CmdStr, RetStr, 100, NULL);
mciSendString("close cdaudio", RetStr, 100, NULL);
break;
}
m_Status.SetWindowText("Recording ....");
DisableButtons();
}
void CMusicRipDlg::OnOptions()
{
// TODO: Add your control notification handler code here
COptions Cp;
Cp.DoModal();
}
LRESULT CMusicRipDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
if(message == USR_INBLOCK){
// stop recording
//...............
mciSendString("stop cdaudio", RetStr, 100, NULL);
waveInStop(hwi);
waveInReset(hwi);
// Unprepare header
//.................
waveInUnprepareHeader(hwi, &wavehdr, sizeof(WAVEHDR));
waveInClose(hwi);
hwi = NULL;
// create the RIFF file new.wav
//.............................
m_Status.SetWindowText("Writing File ....");
CreateRiff(TitleStr);
m_Status.SetWindowText("");
EnableButtons();
// VirtualFree(wavehdr.lpData, 0, MEM_RELEASE);
}
return CDialog::WindowProc(message, wParam, lParam);
}
void CMusicRipDlg::OnStop()
{
// TODO: Add your control notification handler code here
mciSendString("stop cdaudio", RetStr, 100, NULL);
waveInStop(hwi);
waveInReset(hwi);
// Unprepare header
//.................
waveInUnprepareHeader(hwi, &wavehdr, sizeof(WAVEHDR));
waveInClose(hwi);
hwi = NULL;
m_Status.SetWindowText("");
EnableButtons();
// create the RIFF file new.wav
//.............................
// CreateRiff(TitleStr);
// VirtualFree(wavehdr.lpData, 0, MEM_RELEASE);
}
void CMusicRipDlg::OnRefresh()
{
// TODO: Add your control notification handler code here
OnSelchangeCd();
}
void CMusicRipDlg::OnRipother()
{
// TODO: Add your control notification handler code here
WIN32_FIND_DATA Ff;
if(!strlen(MusicDir)){
AfxMessageBox("First enter some destination directory through Options!");
return;
}
strcpy(TitleStr, "Sound.Wav");
if(FindFirstFile(TitleStr, &Ff) != INVALID_HANDLE_VALUE){
if(AfxMessageBox("Overwrite existing sound?", MB_YESNO|MB_ICONQUESTION)==IDNO)
return;
}
char TmpStr[MAX_PATH];
strcpy(TmpStr, MusicDir);
if(TmpStr[3] != 0)
strcat(TmpStr, "\\");
strcat(TmpStr, TitleStr);
strcpy(TitleStr, TmpStr);
_lclose(_lcreat(TitleStr, 0));
RecordWave(this->m_hWnd);
AfxMessageBox("Switch on the recording source and press OK....");
m_Status.SetWindowText("Recording ....");
DisableButtons();
}
void CMusicRipDlg::OnClose()
{
// TODO: Add your message handler code here and/or call default
mciSendString("stop cdaudio", RetStr, 100, NULL);
VirtualFree(wavehdr.lpData, 0, MEM_RELEASE);
CDialog::OnClose();
}
void CMusicRipDlg::DisableButtons(void)
{
m_RipCd.EnableWindow(FALSE);
m_RipOther.EnableWindow(FALSE);
m_Options.EnableWindow(FALSE);
m_Cd.EnableWindow(FALSE);
m_Refresh.EnableWindow(FALSE);
m_ListCtrl.EnableWindow(FALSE);
m_Stop.EnableWindow(TRUE);
}
void CMusicRipDlg::EnableButtons(void)
{
m_RipCd.EnableWindow(TRUE);
m_RipOther.EnableWindow(TRUE);
m_Options.EnableWindow(TRUE);
m_Cd.EnableWindow(TRUE);
m_Refresh.EnableWindow(TRUE);
m_ListCtrl.EnableWindow(TRUE);
m_Stop.EnableWindow(FALSE);
}
void CMusicRipDlg::OnHelp()
{
// TODO: Add your control notification handler code here
char cPath[MAX_PATH], *cPathTmp;
strcpy(cPath, GetCommandLine());
cPathTmp = cPath;
cPathTmp++;
for(int i=strlen(cPathTmp); cPathTmp[i] != '\\'; i--)
;
cPathTmp[++i]=0;
strcat(cPathTmp, "MusicRip.HLP");
::WinHelp(this->m_hWnd, cPathTmp, HELP_CONTENTS, 0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -