⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pcrecorddlg.cpp

📁 PC录音机 可以实行简单的录音 但是不能录入扬声器的声音 录的应该是内存中的
💻 CPP
字号:
// PCRecordDlg.cpp : implementation file
//

#include "stdafx.h"
#include "PCRecord.h"
#include "PCRecordDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
#include  "HyperLink.h"

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	CHyperLink	m_hwEmail;
	CHyperLink	m_hyWeb;
	//}}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)
	virtual BOOL OnInitDialog();
	//}}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)
	DDX_Control(pDX, IDC_EMAIL, m_hwEmail);
	DDX_Control(pDX, IDC_WEB, m_hyWeb);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BOOL CAboutDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	m_hyWeb.SetURL(_T("http://www.24bc.com/NewPoint.htm"));
	m_hwEmail.SetURL(_T("mailto:youzhongxie@126.com"));
		
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

/////////////////////////////////////////////////////////////////////////////
// CPCRecordDlg dialog

CPCRecordDlg::CPCRecordDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CPCRecordDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPCRecordDlg)
	m_strFile = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CPCRecordDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPCRecordDlg)
	DDX_Control(pDX, IDC_INPUT_STATUS, m_InStatus);
	DDX_Text(pDX, IDC_SAVE_FILE, m_strFile);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CPCRecordDlg, CDialog)
	//{{AFX_MSG_MAP(CPCRecordDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_START, OnStart)
	ON_BN_CLICKED(IDC_PAUSE, OnPause)
	ON_BN_CLICKED(IDC_STOP, OnStop)
	ON_BN_CLICKED(IDC_SET_INFO, OnSetInfo)
	ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPCRecordDlg message handlers

BOOL CPCRecordDlg::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	
	m_InStatus.SetRange(0, 32767);
	m_InStatus.SetPos(0);
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CPCRecordDlg::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 CPCRecordDlg::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 CPCRecordDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CPCRecordDlg::OnOK() 
{

}

void CPCRecordDlg::OnCancel() 
{		
	CDialog::OnCancel();
}

// Handler Start button click message
void CPCRecordDlg::OnStart() 
{
	UpdateData(true);
	if (m_strFile.IsEmpty())
		{
		AfxMessageBox(_T("请先输入要保存的文件名"));
		return;	
		}
	m_Recorder.SetFileName(m_strFile.GetBuffer(m_strFile.GetLength()));
	m_strFile.ReleaseBuffer();
	m_Recorder.StartRec();
	SetTimer(0, 10, NULL);
	GetDlgItem(IDC_SET_INFO)->EnableWindow(false);
	GetDlgItem(IDC_BROWSE)->EnableWindow(false);
}

// Handler Pause button click message
void CPCRecordDlg::OnPause() 
{	
	m_Recorder.PauseRec();
}

// Handler Stop button click message
void CPCRecordDlg::OnStop() 
{	
	m_Recorder.StopRec();
	GetDlgItem(IDC_SET_INFO)->EnableWindow(true);
	GetDlgItem(IDC_BROWSE)->EnableWindow(true);
}


// Handler set information button click message
void CPCRecordDlg::OnSetInfo() 
{	
	CSetting  Dlg;
	ID3_INF   inf;

	ZeroMemory(&inf, sizeof(inf));
	if (Dlg.DoModal() == IDCANCEL)
		return;
	Dlg.GetID3(&inf);
	m_Recorder.SetArtist(inf.chArtist);
	m_Recorder.SetAlbum(inf.chAlbum);
	m_Recorder.SetTitle(inf.chTitle);
	m_Recorder.SetTrack(inf.chTrack);
	m_Recorder.SetYear(inf.chYear);
	m_Recorder.SetComment(inf.chComment);
	m_Recorder.SetGenre(inf.chGenre);	
}


// Handler Browse button click message
void CPCRecordDlg::OnBrowse() 
{
	CFileDialog    Dlg(false);

	if (Dlg.DoModal() == IDCANCEL)
		return;
	m_strFile = Dlg.GetPathName();
	m_strFile+= ".mp3";
	UpdateData(false);
}

void CPCRecordDlg::OnTimer(UINT nIDEvent) 
{	
	m_InStatus.SetPos(m_Recorder.GetLev());

	CString  str, strWnd;

	// Show file size
	Int2MB(m_Recorder.GetFileSize(), str);	
	GetDlgItem(IDC_FILE_SIZE)->SetWindowText(str);

	// Show record time
	Int2Time(m_Recorder.GetRSec(), str);	
	GetDlgItem(IDC_SECOND)->SetWindowText(str);

	CDialog::OnTimer(nIDEvent);
}

BOOL CPCRecordDlg::DestroyWindow() 
{
	KillTimer(0);
	
	return CDialog::DestroyWindow();
}


////////////////////////////////////////////////////////////////////
// Name        : Int2Time
// Description : Change integer into time string
// Parameter   : None
// Return      : None
// Remark      : None
////////////////////////////////////////////////////////////////////
void CPCRecordDlg::Int2Time(int  delta, CString &strRet)
{
	CString str;

	strRet = "";
	// weeks
	if (delta >= 604800)
		{
		str.Format("%d周", delta/604800);		
		strRet += str;
		delta = delta % 604800;
		}

	// days
	if (delta >= 86400)
	{
		str.Format("%d天", delta/86400);
		strRet += str;
		delta = delta % 86400;
	}

	// hours
	if (delta >= 3600)
	{
		str.Format("%d时", delta/3600);
		strRet += str;
		delta = delta % 3600;
	}

	// minutes
	if (delta >= 60)
	{
		str.Format("%d分", delta/60);
		strRet += str;
		delta = delta % 60;
	}

	// seconds
	str.Format("%d秒",delta);
	strRet += str;	

	return;
}




////////////////////////////////////////////////////////////////////
// Name        : Int2MB
// Description : Translate integer value into Size string
// Parameter   : None
// Return      : None
// Remark      : None
////////////////////////////////////////////////////////////////////
void CPCRecordDlg::Int2MB(int fsize, CString &strRet)
{	
	CString  str;

	strRet  = "";
	if (fsize >= 1048576)	
		{
		str.Format("%d", fsize / 1048576);
		strRet = str;
		}
	else if (fsize >= 1024)	
		{
		str.Format("%d KB", fsize / 1024);		
		strRet += str;
		}
	else
		{
		str.Format("%d Byte", fsize);
		strRet += str;
		}

	return;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -