📄 options.cpp
字号:
// Options.cpp : implementation file
//
#include "stdafx.h"
#include "MusicRip.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
extern WAVEHDR wavehdr;
extern char MusicDir[MAX_PATH];
extern int TempMem;
extern HANDLE hFileCF, hFileCFM;
extern DWORD lFileSize;
extern WAVEFORMATEX wfx;
extern BOOL ShellGetPath(HANDLE hDlg, char lpszPath[]);
int MemoryMethod=-1, TempMinSec;
#define ONE_BLOCK 1024*1024
/////////////////////////////////////////////////////////////////////////////
// COptions dialog
COptions::COptions(CWnd* pParent /*=NULL*/)
: CDialog(COptions::IDD, pParent)
{
//{{AFX_DATA_INIT(COptions)
m_Bits = -1;
m_One = -1;
m_ChOne = -1;
m_MinSec = -1;
//}}AFX_DATA_INIT
}
void COptions::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(COptions)
DDX_Control(pDX, IDC_BROWSE, m_Browse);
DDX_Control(pDX, IDC_SEC, m_Sec);
DDX_Control(pDX, IDC_MIN, m_Min);
DDX_Control(pDX, IDC_DIR, m_Dir);
DDX_Control(pDX, IDC_TEMP, m_TempMem);
DDX_Radio(pDX, IDC_BITS8, m_Bits);
DDX_Radio(pDX, IDC_ONE, m_One);
DDX_Radio(pDX, IDC_CHANNELONE, m_ChOne);
DDX_Radio(pDX, IDC_TEMPRAD, m_MinSec);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(COptions, CDialog)
//{{AFX_MSG_MAP(COptions)
ON_BN_CLICKED(IDC_MINSEC, OnMinsec)
ON_BN_CLICKED(IDC_TEMPRAD, OnTemprad)
ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// COptions message handlers
void COptions::OnOK()
{
// TODO: Add extra validation here
UpdateData(TRUE);
m_Dir.GetWindowText(MusicDir, MAX_PATH);
if(!strlen(MusicDir)){
AfxMessageBox("Music files folder must be specified!");
return;
}
char TmpStr[15];
m_TempMem.GetWindowText(TmpStr, 10);
TempMem = atoi(TmpStr);
if(_chdir(MusicDir)){
AfxMessageBox("Music files folder error!");
return;
}
/* hFileCF=CreateFile("TEMP.TMP", GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL);
HANDLE hMem = LocalAlloc(LMEM_MOVEABLE|LMEM_ZEROINIT, ONE_BLOCK);
LPBYTE pMem = (LPBYTE) LocalLock(hMem);
for(int i=0; i<TempMem; i++){
DWORD Tmp;
WriteFile(hFileCF, pMem, ONE_BLOCK, &Tmp, NULL);
if(Tmp != ONE_BLOCK){
AfxMessageBox("Memory insufficient for temporary file!");
LocalUnlock(hMem);
LocalFree(hMem);
return;
}
}
LocalUnlock(hMem);
LocalFree(hMem);
lFileSize = GetFileSize(hFileCF, NULL);
hFileCFM=CreateFileMapping(hFileCF, NULL, PAGE_READWRITE, 0, lFileSize, NULL);
wavehdr.lpData=(LPSTR)MapViewOfFile(hFileCFM, FILE_MAP_WRITE, 0, 0, 0);*/
wfx.nSamplesPerSec = 11025 * (m_One == 0 ? 1:(m_One<<1)); // 11.025 kHz (11.025 * 1000)
wfx.nChannels = m_ChOne + 1;
wfx.wBitsPerSample = (m_Bits + 1) * 8;
if(m_MinSec){
m_Min.GetWindowText(TmpStr, 10);
TempMem = atoi(TmpStr)*60;
m_Sec.GetWindowText(TmpStr, 10);
TempMem += atoi(TmpStr);
TempMinSec = TempMem;
TempMem = (TempMem * wfx.nSamplesPerSec * wfx.nChannels * (wfx.wBitsPerSample/8)) / (1024*1024) + 1;
}
LPSTR TmpVal;
if(wavehdr.lpData)
VirtualFree(wavehdr.lpData, 0, MEM_RELEASE);
if((TmpVal = (LPSTR) VirtualAlloc(NULL, TempMem*1024*1024, MEM_COMMIT, PAGE_READWRITE))==NULL){
AfxMessageBox("Unable to create memory!");
return;
}
wavehdr.lpData = TmpVal;
// LPSTR pTmp = wavehdr.lpData;
wavehdr.dwBufferLength = TempMem*1024*1024;
MemoryMethod = m_MinSec;
CDialog::OnOK();
}
BOOL COptions::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
UpdateData(TRUE);
m_Dir.SetWindowText(MusicDir);
char TmpStr[50];
itoa(TempMem, TmpStr, 10);
m_One = (wfx.nSamplesPerSec/11025) >> 1;
m_ChOne = wfx.nChannels ? wfx.nChannels-1 : 1;
m_Bits = wfx.wBitsPerSample >> 4;
m_MinSec = MemoryMethod < 0 ? 1:MemoryMethod;
MemoryMethod = m_MinSec;
if(!MemoryMethod)
OnTemprad();
else
OnMinsec();
m_TempMem.SetWindowText(TmpStr);
itoa(TempMinSec/60, TmpStr, 10);
m_Min.SetWindowText(TmpStr);
itoa(TempMinSec%60, TmpStr, 10);
m_Sec.SetWindowText(TmpStr);
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void COptions::OnMinsec()
{
// TODO: Add your control notification handler code here
m_Min.EnableWindow(TRUE);
m_Sec.EnableWindow(TRUE);
m_TempMem.EnableWindow(FALSE);
}
void COptions::OnTemprad()
{
// TODO: Add your control notification handler code here
m_Min.EnableWindow(FALSE);
m_Sec.EnableWindow(FALSE);
m_TempMem.EnableWindow(TRUE);
}
void COptions::OnBrowse()
{
// TODO: Add your control notification handler code here
if(ShellGetPath(this->m_hWnd, MusicDir))
m_Dir.SetWindowText(MusicDir);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -