【VC开源代码栏目提醒】:网学会员--在 VC开源代码编辑为广大网友搜集整理了:Playsong.cpp绩等信息,祝愿广大网友取得需要的信息,参考学习。
// Playsong.cpp : implementation file
//
#include "stdafx.h"
#include "songclient.h"
#include "Playsong.h"
#include "ClientWnd.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPlaysong dialog
CPlaysong::CPlaysong(CWnd* pParent /*=NULL*/)
: CDialog(CPlaysong::IDD, pParent)
{
//{{AFX_DATA_INIT(CPlaysong)
//}}AFX_DATA_INIT
m_nTotalNum = 0;
m_nCurrentIndex = -1;
m_pstrFilePath = NULL;
}
void CPlaysong::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPlaysong)
DDX_Control(pDX, IDC_Mediaplay, m_mediaplay);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPlaysong, CDialog)
//{{AFX_MSG_MAP(CPlaysong)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPlaysong message handlers
BOOL CPlaysong::OnInitDialog()
{
CDialog::OnInitDialog();
m_mediaplay.SetShowControls(false);
m_mediaplay.SetShowDisplay(false);
m_mediaplay.SetAutoStart(true);//自动播放
m_mediaplay.SetFullScreenMode(true);//全屏播放
m_mediaplay.SetVolume(0);//声音最大
m_mediaplay.SetBalance(0);//设置平衡
//
注册系统热键
RegisterHotKey(m_hWnd, 50000, 0, 'A');//音量增
RegisterHotKey(m_hWnd, 50001, 0, 'B');//音量减
RegisterHotKey(m_hWnd, 50002, 0, 'D');//停唱
RegisterHotKey(m_hWnd, 50003, 0, VK_F2);//伴唱,换声道
// RegisterHotKey(m_hWnd, 50004, 0, VK_RETURN);//回车键,暂停或继续播放
SetTimer(1, 100, NULL);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
BOOL CPlaysong::PreTranslateMessage(MSG* pMsg)
{
if( pMsg->message == WM_HOTKEY)
{
switch( (int)pMsg->wParam )
{
case 50000://按下了a
SetVolume();
break;
case 50001://按下了b
SetVolume(false);
break;
case 50002://按下了d
//找到全屏播放窗口,发WM_CLOSE给它,让其退出全屏
CWnd* pWnd;
pWnd = FindWindow("VideoRenderer", "ActiveMovie Window");
if( pWnd != NULL)
::SendMessage(pWnd->m_hWnd, WM_CLOSE, 0, 0);
//找到全屏播放窗口,发WM_CLOSE给它,让其退出全屏 end
m_mediaplay.SetFullScreenMode(false);
m_mediaplay.Stop();
ShowWindow(SW_HIDE);
break;
case 50003://按下了F2
SetBalance();
break;
/* case 50004://按下了回车键
// CWnd* pWnd;
pWnd = FindWindow("VideoRenderer", "ActiveMovie Window");
if( pWnd != NULL)
{
static BOOL bplay = false;
bplay = !bplay;
if(bplay)
m_mediaplay.Run();
else
m_mediaplay.Pause();
break;
}
::SendMessage(GetParent()->m_hWnd, WM_KEYDOWN, VK_RETURN, 0);
break;*/
}
}
return CDialog::PreTranslateMessage(pMsg);
}
/////////////////////////////////////////////////////////////
/*函数功能: 设置播放
列表 //参数说明: lpszFilePath: 文件路径
bFst: 是否为第一次调用该函数,是则将m_pstrFilePath数组清空,
以后调用则把歌曲加到m_pstrFilePath数组中 */
void CPlaysong::SetFilePath(LPCTSTR lpszFilePath, BOOL bFst)
{
if(!strcmp(lpszFilePath, ""))
return;
if( bFst )
{
delete[] m_pstrFilePath;
m_nTotalNum = 0;
m_nCurrentIndex = -1;
m_pstrFilePath = NULL;
}
CString *strtmp;
if(m_pstrFilePath != NULL)
{
strtmp = new CString[m_nTotalNum];
for(int i = 0; i < m_nTotalNum; i++)
strtmp[i] = m_pstrFilePath[i];
delete[] m_pstrFilePath;
m_pstrFilePath = NULL;
}
m_pstrFilePath = new CString[++m_nTotalNum];
for(int i = 0; i < m_nTotalNum - 1; i++)
m_pstrFilePath[i] = strtmp[i];
m_pstrFilePath[i] = lpszFilePath;
}
void CPlaysong::Play(int nIndex)
{
if( nIndex >= m_nTotalNum || m_pstrFilePath == NULL )
return;
m_nCurrentIndex = nIndex;
m_mediaplay.SetFileName(m_pstrFilePath[m_nCurrentIndex]);
m_mediaplay.SetFullScreenMode(false);
m_mediaplay.SetFullScreenMode(true);
}
/////////////////////////////////////////////////////////////
/*函数功能: 改变声音大小
//参数说明: bTurnup: 是否为增大 */
void CPlaysong::SetVolume(BOOL bTurnup)
{
long lVolume = bTurnup ? m_mediaplay.GetVolume()+200 : m_mediaplay.GetVolume()-200;
if(lVolume > 0)
lVolume = 0;
else if(lVolume < -4000)
lVolume = -4000;
m_mediaplay.SetVolume(lVolume);
}
/////////////////////////////////////////////////