📄 mp3playerdlg.cpp
字号:
// CMP3PlayerDlg.cpp: implementation of the CMP3PlayerDlg class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "MP3PlayerDlg.h"
#include "commctrl.h"
#include "UICommon.h"
BEGIN_MESSAGE_MAP(CMP3PlayerDlg, CMediaPlayer)
ON_BN_CLICKED(IDC_PREVIOUS,OnPrevious)
ON_BN_CLICKED(IDC_NEXT,OnNext)
END_MESSAGE_MAP()
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMP3PlayerDlg::CMP3PlayerDlg(CNWnd* pParent, UINT uID)
:CMediaPlayer(pParent, uID)
{
}
CMP3PlayerDlg::~CMP3PlayerDlg()
{
}
BOOL CMP3PlayerDlg::OnInitDialog()
{
CMediaPlayer::OnInitDialog();
// subclassing dialog item
m_lbFileList.SubclassDlgItem(IDC_FILE_LIST, this);
m_lbFileList.SetWindowPos(NULL, 1,1,
SCREEN_WIDTH-2, SCREEN_HEIGHT - MP_BAR_HEIGHT-14, 0);
// searching files and add to list box.
FILE_NAME *pFileName = GetFileList(NGetCurrentDir(),//(_T("D:\\Documents and Settings\\morson\\"),
_T("*.mp3 | *.wma | *.ram | *.rm "));
if(pFileName)
{
TCHAR szFileFullName[MAX_PATH +1];
for(int i=0; i<GetCount(); i++)
{
_tcscpy(szFileFullName, pFileName[i].FilePath);
_tcscat(szFileFullName, pFileName[i].FileName);
m_lbFileList.AddItem(szFileFullName, LISTBOX_ITEM_NOT_PLAYING);
}
// select the first one in listbox in default and play it.
m_lbFileList.SetCurSel(0);
PlayItem(0);
}
ReleaseFileList();
return TRUE;
}
BOOL CMP3PlayerDlg::OnEraseBkgnd(HDC hdc)
{
RECT rc;
SetRect(&rc, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
FillSolidRect(hdc, &rc, MP_BAR_COLOR);
return TRUE;
}
void CMP3PlayerDlg::OnIdle()
{
// do't call base class OnIdle(), it does something special for it.
CNDialog::OnIdle();
}
LRESULT CMP3PlayerDlg::WndProc(HWND hWnd,
UINT uMsg, WPARAM wParam, LPARAM lParam)
{
// handle List box's notify message.
if( uMsg == WM_COMMAND && LOWORD(wParam)== IDC_FILE_LIST)
{
// double click one item.
if( HIWORD(wParam) == LBN_DBLCLK )
{
// play the selected item.
PlayItem( m_lbFileList.GetCurSel() );
}
}
// handle dshow's notification message.
if( uMsg == WM_MULTIMEDIA_NOTIFY )
{
ASSERT( m_pMultimedia != NULL);
int eventCode;
m_pMultimedia->HandleEvent((WPARAM)&eventCode, 0);
if(eventCode == EC_COMPLETE) // play next one.
{
int nItem = GetPlayingItem();
// if it's not the last one, then play the next item.
if( nItem < m_lbFileList.GetCount() - 1 )
{
PlayItem(nItem+1);
}
}
}
return CMediaPlayer::WndProc(hWnd, uMsg, wParam, lParam);
}
// playback the item in the list box indexed by nIndex.
void CMP3PlayerDlg::PlayItem(int nIndex)
{
for (int i=0; i<m_lbFileList.GetCount(); i++)
{
if(i == nIndex)
m_lbFileList.SetItemData(i, LISTBOX_ITEM_IS_PLAYING);
else
m_lbFileList.SetItemData(i, LISTBOX_ITEM_NOT_PLAYING);
}
m_lbFileList.InvalidateRect(NULL);
// Get the file name and play it.
TCHAR szFileFullName[MAX_PATH+1];
m_lbFileList.GetItemText(nIndex, szFileFullName, MAX_PATH);
m_strFileName = szFileFullName;
CreateMultimedia();
}
// if found, return the index of the item.
// in not found, return -1.
int CMP3PlayerDlg::GetPlayingItem()
{
BOOL bFound = FALSE;
for (int i=0; i<m_lbFileList.GetCount(); i++)
{
if(m_lbFileList.GetItemData(i) == LISTBOX_ITEM_IS_PLAYING)
{
bFound = TRUE;
break;
}
}
if( bFound )
return i;
else
return -1;
}
void CMP3PlayerDlg::OnPrevious()
{
}
// forward
void CMP3PlayerDlg::OnNext()
{
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -