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

📄 simplemp3dlg.cpp

📁 一些关于C++开发的多媒体制作书籍的源代码
💻 CPP
📖 第 1 页 / 共 4 页
字号:

////////////////////////////////////////////////////////////////////////
/*
* 函数名称:NewM3U
* 函数介绍:完成新建M3U文件功能
* 输入参数:无
* 输出参数:无
* 返回值  :BOOL, true=success, false=failure
*/
void CSimpleMP3Dlg::NewM3U()
{
	CFileDialog FileDlg(
		false,			//"新建"窗口
		"M3U",			//默认扩展名
		"Untitled",		//默认文件名
		OFN_OVERWRITEPROMPT,	//窗口风格
		"M3U列表文件(*.m3u)|*.m3u||",		//文件类型和扩展名
		this);			//父窗口
	FileDlg.m_ofn.lpstrTitle="新建";
	if (FileDlg.DoModal()==IDCANCEL)
		return;

	m_mcimp3.MCIClose();
	m_Play.SetCheck(FALSE);
	m_Pause.SetCheck(FALSE);
	m_Stop.SetCheck(FALSE);
	m_iOpenedID=-1;
	m_Slider.SetPos(0);
	this->SetTime(0);
	m_Title.SetWindowText("无");

	CString strTitle=_T(""), strFileName=_T(""), strWinTitle;
	strTitle.LoadString(IDS_TITLE);
	GetFileTitle((LPCTSTR)m_strM3UPath, strFileName.GetBuffer(255), 255);
	strFileName.ReleaseBuffer();		// Nesissary!!
	if (strFileName!="Default")
		this->SetWindowText(strTitle + " - " + strFileName);

	strWinTitle.LoadString(IDS_TITLE);
	m_pTrayIcon->ModifyTip(strWinTitle);

	//SaveM3UProc(m_strM3UPath);
	m_List.DeleteAllFiles();
	m_strM3UPath=FileDlg.GetPathName();
	
	this->AddDir();
}

////////////////////////////////////////////////////////////////////////
/*
* 函数名称:Open
* 函数介绍:打开uItemID所示的MP3文件
* 输入参数:UINT uItemID, 要打开的项的ID号
* 输出参数:无
* 返回值  :BOOL, true=success, false=failure
*/
BOOL CSimpleMP3Dlg::Open(UINT uItemID)
{
	CString strPath;

	m_mcimp3.MCIClose();
	m_iOpenedID=0;

	strPath=m_List.GetPath(uItemID);
	if (m_mcimp3.MCIOpen(strPath)==0)		//成功打开
	{	m_iOpenedID=uItemID;

		//读取已打开的MP3文件的信息,更新列表
		m_List.UpdateSongInfo(m_iOpenedID);

		//更改将播放项在列表中的长度
		CString strLength;
		strLength.Format("%d:%02d", m_mcimp3.m_dwLength/60, m_mcimp3.m_dwLength%60);
		m_List.SetLength(m_iOpenedID, strLength);
		
		//设置Slider的范围
		m_Slider.SetRange(0, m_mcimp3.m_dwLength, true);

		SetTime(m_bElapse ? 0 : m_mcimp3.m_dwLength);
		m_List.SetHotItem(uItemID);
		
		//设置按扭状态
		if (m_Mute.GetCheck())
			m_mcimp3.MCISetMute(true);
		m_Play.SetCheck(false);
		m_Pause.SetCheck(false);
		m_Stop.SetCheck(false);

		//设置Title标签、工具栏提示
		CString strWinTitle, strTitle;
		strWinTitle.LoadString(IDS_TITLE);
		strTitle=m_List.GetTitle(uItemID) + "(" + m_List.GetLength(uItemID) + ")";
		strWinTitle = strTitle + " - " + strWinTitle;
		m_Title.SetWindowText(strTitle);
		m_pTrayIcon->ModifyTip(strWinTitle);

		return true;
	}
	
	m_iOpenedID=-1;
	m_Play.SetCheck(false);
	m_Pause.SetCheck(false);
	m_Stop.SetCheck(false);
	return false;	
}

////////////////////////////////////////////////////////////////////////
/*
* 函数名称:OpenM3U
* 函数介绍:完成打开M3U列表功能
* 输入参数:无
* 输出参数:无
* 返回值  :无
*/
void CSimpleMP3Dlg::OpenM3U() 
{
	// TODO: Add your command handler code here
	CString strPath;
	CFileDialog FileDlg(
		true,			//“打开”窗口
		"M3U",			//默认扩展名
		NULL,			//默认文件名
		OFN_FILEMUSTEXIST,	//窗口风格
		"M3U列表文件(*.m3u)|*.m3u||",		//文件类型和扩展名
		this);			//父窗口

	if (FileDlg.DoModal()==IDCANCEL)
		return;

	strPath=FileDlg.GetPathName();
	if (m_List.OpenM3U(strPath) <= 0)			//打开出错或文件空
	{	AfxMessageBox("文件格式错误或文件空!\n");
		return;
	}
	m_strM3UPath=strPath;

	// 更改标题
	CString strTitle=_T(""), strFileName=_T("");
	strTitle.LoadString(IDS_TITLE);
	GetFileTitle((LPCTSTR)strPath, strFileName.GetBuffer(255), 255);
	strFileName.ReleaseBuffer();		// Nesissary!!
	if (strFileName!="Default")
		this->SetWindowText(strTitle + " - " + strFileName);

	// 打开并播放第一首
	if (!Open(0))
		return;
	Play();
}

////////////////////////////////////////////////////////////////////////
/*
* 函数名称:Pause
* 函数介绍:完成暂停播放功能
* 输入参数:无
* 输出参数:无
* 返回值  :BOOL, true=success, false=failure
*/
BOOL CSimpleMP3Dlg::Pause()
{
	if (m_mcimp3.MCIPause()==0)	//成功暂停
	{	KillTimer(TIMER1);
		m_Play.SetCheck(false);
		m_Pause.SetCheck(true);
		m_Stop.SetCheck(false);
		return true;
	}
	return false;
}

////////////////////////////////////////////////////////////////////////
/*
* 函数名称:Play
* 函数介绍:完成播放功能
* 输入参数:无
* 输出参数:无
* 返回值  :BOOL, true=success, false=failure
*/
BOOL CSimpleMP3Dlg::Play()
{
	if (m_mcimp3.MCIPlay()==0)	//成功播放
	{	SetTimer(TIMER1, 1000, NULL);
		m_Play.SetCheck(true);
		m_Pause.SetCheck(false);
		m_Stop.SetCheck(false);
		return true;
	}
	m_Play.SetCheck(true);
	m_Pause.SetCheck(false);
	m_Stop.SetCheck(false);
	return false;
}

////////////////////////////////////////////////////////////////////////
/*
* 函数名称:Resume
* 函数介绍:完成恢复播放功能
* 输入参数:无
* 输出参数:无
* 返回值  :BOOL, true=success, false=failure
*/
BOOL CSimpleMP3Dlg::Resume()
{
	if (m_mcimp3.MCIResume()==0)	//成功恢复
	{	SetTimer(TIMER1, 1000, NULL);
		m_Play.SetCheck(true);
		m_Pause.SetCheck(false);
		m_Stop.SetCheck(false);
		return true;
	}
	return false;
}

////////////////////////////////////////////////////////////////////////
/*
* 函数名称:SaveM3U
* 函数介绍:完成保存文件功能
* 输入参数:无
* 输出参数:无
* 返回值  :无
*/
void CSimpleMP3Dlg::SaveM3U()
{
	if (m_strM3UPath==m_strDefaultDir+_T("\\Default"))
	{	CFileDialog FileDlg(
			false,			//"新建"窗口
			"M3U",			//默认扩展名
			"Untitled",		//默认文件名
			OFN_OVERWRITEPROMPT,	//窗口风格
			"M3U列表文件(*.m3u)|*.m3u||",		//文件类型和扩展名
			this);			//父窗口
	//	FileDlg.m_ofn.lpstrTitle="保存";
		if (FileDlg.DoModal()==IDCANCEL)
			return;

		m_strM3UPath=FileDlg.GetPathName();
	}
	if (m_List.SaveM3U(m_strM3UPath) == -1)
	{
		return;
	}

	// 更改标题
	CString strTitle=_T(""), strFileName=_T("");
	strTitle.LoadString(IDS_TITLE);
	GetFileTitle((LPCTSTR)m_strM3UPath, strFileName.GetBuffer(255), 255);
	strFileName.ReleaseBuffer();		// Nesissary!!
	if (strFileName!="Default")
		this->SetWindowText(strTitle + " - " + strFileName);
	return;
}

////////////////////////////////////////////////////////////////////////
/*
* 函数名称:SaveM3UAs
* 函数介绍:完成另存为功能
* 输入参数:无
* 输出参数:无
* 返回值  :无
*/
void CSimpleMP3Dlg::SaveM3UAs()
{
	CFileDialog FileDlg(
		false,			//"新建"窗口
		"M3U",			//默认扩展名
		"Untitled",		//默认文件名
		OFN_OVERWRITEPROMPT,	//窗口风格
		"M3U列表文件(*.m3u)|*.m3u||",		//文件类型和扩展名
		this);			//父窗口
	FileDlg.m_ofn.lpstrTitle="另存为";
	if (FileDlg.DoModal()==IDCANCEL)
		return;

	m_strM3UPath=FileDlg.GetPathName();
	if (m_List.SaveM3U(m_strM3UPath) == -1)
	{
		return;
	}

	// 更改标题
	CString strTitle=_T(""), strFileName=_T("");
	strTitle.LoadString(IDS_TITLE);
	GetFileTitle((LPCTSTR)m_strM3UPath, strFileName.GetBuffer(255), 255);
	strFileName.ReleaseBuffer();		// Nesissary!!
	if (strFileName!="Default")
		this->SetWindowText(strTitle + " - " + strFileName);
	return;
}

////////////////////////////////////////////////////////////////////////
/*
* 函数名称:SetTime
* 函数介绍:设置时间标签
* 输入参数:DWORD dwTime, 单位为秒的时间
* 输出参数:无
* 返回值  :无
*/
void CSimpleMP3Dlg::SetTime(DWORD dwTime)
{
	CString strTime;

	ASSERT(dwTime >= 0);
	{	strTime.Format("%02d:%02d", dwTime/60, dwTime%60);
		m_Time.SetWindowText(strTime);
	}
}

////////////////////////////////////////////////////////////////////////
/*
* 函数名称:Stop
* 函数介绍:停止播放
* 输入参数:无
* 输出参数:无
* 返回值  :BOOL, true=success, false=failure
*/
BOOL CSimpleMP3Dlg::Stop()
{
	if (m_mcimp3.MCIPause()==0)	//成功停止
	{	KillTimer(TIMER1);
		m_Play.SetCheck(false);
		m_Pause.SetCheck(false);
		m_Stop.SetCheck(true);
		return true;
	}
	return false;
}

////////////////////////////////////////////////////////////////////////
/*
* 函数名称:WriteProfile
* 函数介绍:将当前设置写到注册表
      项目:
      ********************************************
      [Control Status]
      Repeat = 0
      Loop = 1
      Random = 1
      Mute = 0
      
      [File Last Open]
      PathName=m_strDefaultDir+_T("\\Default")
            
      [Position] 
      (窗口是否为图标化(在系统栏中),及左上角位置坐标、高)
      Iconized = 0
      x =20
      y = 20
      cy = 368(与最小[m_iMinHeight]的不同)
      
      [Options]
      Elapse = 1
      
      [Title]
      (标题的Style, Step, Tick)
      Style = CScrollLabel::SL_HSCROLLBOTH
      Step = 4
      Tick = 200
      ********************************************
* 输入参数:无
* 输出参数:无
* 返回值  :无
*/
void CSimpleMP3Dlg::WriteProfile()
{
	CWinApp *pApp=AfxGetApp();

	//[Control Status]
	pApp->WriteProfileInt("Control Status", "Repeat", m_Repeat.GetCheck());
	pApp->WriteProfileInt("Control Status", "Loop", m_Loop.GetCheck());
	pApp->WriteProfileInt("Control Status", "Random", m_Random.GetCheck());
	pApp->WriteProfileInt("Control Status", "Mute", m_Mute.GetCheck());

	//[File Last Open]
	pApp->WriteProfileString("File Last Open", "PathName", m_strM3UPath);

	//[Position]
	//(窗口是否为图标化(在系统栏中),及左上角位置坐标、高)
	pApp->WriteProfileInt("Position", "Iconized", this->m_bIconized);
	CRect WinRect;
	this->GetWindowRect(&WinRect);
	pApp->WriteProfileInt("Position", "x", WinRect.TopLeft().x);
	pApp->WriteProfileInt("Position", "y", WinRect.TopLeft().y);
	pApp->WriteProfileInt("Position", "cy", WinRect.Height());

	//[Options]
	pApp->WriteProfileInt("Options", "Elapse", m_bElapse);

	//[Title]
	pApp->WriteProfileInt("Title", "Style", m_Title.GetScrollStyle());
	pApp->WriteProfileInt("Title", "Step", m_Title.GetStep());
	pApp->WriteProfileInt("Title", "Tick", m_Title.GetTick());

}

////////////////////////////////////////////////////////////////////////
/*
* 函数名称:ReadProfile
* 函数介绍:从注册表读入上次的设置
      项目:
      ********************************************
      [Control Status]
      Repeat = 0
      Loop = 1
      Random = 1
      Mute = 0
      
      [File Last Open]
      PathName=m_strDefaultDir+_T("\\Default")
            
      [Position] 
      (窗口是否为图标化(在系统栏中),及左上角位置坐标、高)
      Iconized = 0
      x =20
      y = 20
      cy = 368(与最小[m_iMinHeight]的不同)
      
      [Options]
      Elapse = 1
      
      [Title]
      (标题的Style, Step, Tick)
      Style = CScrollLabel::SL_HSCROLLBOTH
      Step = 4
      Tick = 200
      ********************************************
* 输入参数:无
* 输出参数:无
* 返回值  :无
*/
void CSimpleMP3Dlg::ReadProfile()
{
	CWinApp *pApp=AfxGetApp();

	//[Control Status]
	m_Repeat.SetCheck(pApp->GetProfileInt("Control Status", "Repeat", 0));
	m_Loop.SetCheck(pApp->GetProfileInt("Control Status", "Loop", 1));
	m_Random.SetCheck(pApp->GetProfileInt("Control Status", "Random", 1));
	m_Mute.SetCheck(pApp->GetProfileInt("Control Status", "Mute", 0));
	OnMute();

	//[File Last Open]
	m_strM3UPath=pApp->GetProfileString("File Last Open", "PathName", m_strDefaultDir+_T("\\Default"));
	if (m_strM3UPath.IsEmpty())
		m_strM3UPath=m_strDefaultDir+_T("\\Default");

	if (m_List.OpenM3U(m_strM3UPath) > 0)
	{
		// 更改标题
		CString strTitle=_T(""), strFileName=_T("");
		strTitle.LoadString(IDS_TITLE);

⌨️ 快捷键说明

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