📄 simplemp3dlg.cpp
字号:
/*
* Copyright (c) 2002, Bcdliang
* All rights reserved.
*
* 文件名称:SimpleMP3Dlg.cpp
* 摘 要:类CSimpleMP3Dlg的实现
*
* 当前版本:1.01
* 作 者:LIANG Zheng
* 完成日期:2002年8月11日
*/
#include "stdafx.h"
#include "SimpleMP3.h"
#include "SimpleMP3.h"
//#include <direct.h>
#include "ID3TAGDlg.h"
#include "AboutSplashDlg.h"
#include "DynamicTitle.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// Control colors
const COLORREF DIALOG_BKCOLOR = RGB(234, 234, 234);
const COLORREF CONTROL_BKCOLOR = RGB(0, 0, 0);
const COLORREF CONTROL_TEXTCOLOR = RGB(0, 255, 0);
/////////////////////////////////////////////////////////////////////////////
// CSimpleMP3Dlg dialog
CSimpleMP3Dlg::CSimpleMP3Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CSimpleMP3Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSimpleMP3Dlg)
m_iOpenedID = -1;
m_bElapse = true;
m_bIconized = false;
//}}AFX_DATA_INIT
//取得当前目录,作为默认目录
GetCurrentDirectory(255, m_strDefaultDir.GetBuffer(255));
// _getcwd(m_strDefaultDir.GetBuffer(255), 255);
m_strDefaultDir.ReleaseBuffer();
m_strM3UPath = m_strDefaultDir+_T("\\Default");
// 初始化背景刷
this->m_bkBrush.CreateSolidBrush(DIALOG_BKCOLOR);
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
CSimpleMP3Dlg::~CSimpleMP3Dlg()
{
}
void CSimpleMP3Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSimpleMP3Dlg)
DDX_Control(pDX, IDC_LIST, m_List);
DDX_Control(pDX, IDC_M3U, m_M3u);
DDX_Control(pDX, IDC_TITLE, m_Title);
DDX_Control(pDX, IDC_TIME, m_Time);
DDX_Control(pDX, IDC_STOP, m_Stop);
DDX_Control(pDX, IDC_STEP, m_Step);
DDX_Control(pDX, IDC_SLIDER, m_Slider);
DDX_Control(pDX, IDC_PREV, m_Prev);
DDX_Control(pDX, IDC_PLAY, m_Play);
DDX_Control(pDX, IDC_PAUSE, m_Pause);
DDX_Control(pDX, IDC_NEXT, m_Next);
DDX_Control(pDX, IDC_BACK, m_Back);
DDX_Control(pDX, IDC_REPEAT, m_Repeat);
DDX_Control(pDX, IDC_RANDOM, m_Random);
DDX_Control(pDX, IDC_LOOP, m_Loop);
DDX_Control(pDX, IDC_MUTE, m_Mute);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSimpleMP3Dlg, CDialog)
ON_WM_CONTEXTMENU()
//{{AFX_MSG_MAP(CSimpleMP3Dlg)
ON_WM_SYSCOMMAND()
ON_WM_DESTROY()
ON_WM_HSCROLL()
ON_BN_CLICKED(IDC_MUTE, OnMute)
ON_BN_CLICKED(IDC_PAUSE, OnPause)
ON_BN_CLICKED(IDC_PLAY, OnPlay)
ON_BN_CLICKED(IDC_STOP, OnStop)
ON_BN_CLICKED(IDC_PREV, OnPrev)
ON_BN_CLICKED(IDC_BACK, OnBack)
ON_BN_CLICKED(IDC_STEP, OnStep)
ON_BN_CLICKED(IDC_NEXT, OnNext)
ON_WM_TIMER()
ON_WM_SIZE()
ON_MESSAGE(MYWM_TRAYICON, OnMyTrayIcon)
ON_BN_CLICKED(IDC_TIME, OnTime)
ON_BN_CLICKED(IDC_M3U, OnM3u)
ON_BN_CLICKED(IDC_TITLE, OnTitle)
ON_WM_CTLCOLOR_REFLECT()
ON_WM_NCHITTEST()
ON_MESSAGE(MYWM_LISTITEMPLAY, OnListItemPlay)
ON_MESSAGE(MYWM_LISTITEMDELETE, OnListItemDelete)
ON_MESSAGE(MYWM_LISTITEMINFO, OnListItemInfo)
ON_MESSAGE(MYWM_LISTOPENEDITEMMOVE, OnListOpenedItemMove)
ON_WM_GETMINMAXINFO()
ON_WM_LBUTTONDOWN()
ON_COMMAND(IDM_ABOUTBOX, OnDialogPopup)
ON_COMMAND(IDM_ADDDIR, OnM3uPopup)
ON_WM_QUERYDRAGICON()
ON_COMMAND(IDA_NEXT, OnNext)
ON_COMMAND(IDA_PAUSE, OnPause)
ON_COMMAND(IDA_PLAY, OnPlay)
ON_COMMAND(IDA_PREV, OnPrev)
ON_COMMAND(IDA_STOP, OnStop)
ON_COMMAND(IDM_DYNAMICTITLE, OnDialogPopup)
ON_COMMAND(IDM_ICON, OnDialogPopup)
ON_COMMAND(IDM_LOOP, OnDialogPopup)
ON_COMMAND(IDM_MUTE, OnDialogPopup)
ON_COMMAND(IDM_RANDOM, OnDialogPopup)
ON_COMMAND(IDM_REPEAT, OnDialogPopup)
ON_COMMAND(ID_EXIT, OnDialogPopup)
ON_COMMAND(IDM_SAVE, OnM3uPopup)
ON_COMMAND(IDM_SAVEAS, OnM3uPopup)
ON_COMMAND(IDM_OPEN, OnM3uPopup)
ON_COMMAND(IDM_NEW, OnM3uPopup)
ON_COMMAND(IDM_CLOSE, OnM3uPopup)
ON_COMMAND(IDM_ADDFILE, OnM3uPopup)
ON_COMMAND(IDM_PLAY, OnPlay)
ON_COMMAND(IDM_PREV, OnPrev)
ON_COMMAND(IDM_PAUSE, OnPause)
ON_COMMAND(IDM_NEXT, OnNext)
ON_COMMAND(IDM_STOP, OnStop)
ON_COMMAND(IDM_STEP, OnStep)
ON_COMMAND(IDM_BACK, OnBack)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSimpleMP3Dlg message handlers
void CSimpleMP3Dlg::OnBack()
{
// TODO: Add your control notification handler code here
DWORD dwPos;
BOOL bPlaying=m_mcimp3.MCIIsPlaying();
m_mcimp3.MCIGetPos(&dwPos);
dwPos-=5;
if (dwPos<0 || dwPos>m_mcimp3.m_dwLength)
dwPos=0;
m_mcimp3.MCISeekTo(dwPos);
SetTime(m_bElapse ? dwPos : m_mcimp3.m_dwLength-dwPos);
m_Slider.SetPos(dwPos);
if (bPlaying)
Play();
}
void CSimpleMP3Dlg::OnContextMenu(CWnd*, CPoint point)
{
// CG: This block was added by the Pop-up Menu component
{
if (point.x == -1 && point.y == -1){
//keystroke invocation
CRect rect;
GetClientRect(rect);
ClientToScreen(rect);
point = rect.TopLeft();
point.Offset(5, 5);
}
CMenu menu;
VERIFY(menu.LoadMenu(CG_IDR_POPUP_SIMPLE_MP3DLG));
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);
//设置MARK********
if (m_Repeat.GetCheck())
menu.CheckMenuItem(IDM_REPEAT, MF_CHECKED);
else
menu.CheckMenuItem(IDM_REPEAT, MF_UNCHECKED);
if (m_Loop.GetCheck())
menu.CheckMenuItem(IDM_LOOP, MF_CHECKED);
else
menu.CheckMenuItem(IDM_LOOP, MF_UNCHECKED);
if (m_Random.GetCheck())
menu.CheckMenuItem(IDM_RANDOM, MF_CHECKED);
else
menu.CheckMenuItem(IDM_RANDOM, MF_UNCHECKED);
if (m_Mute.GetCheck())
menu.CheckMenuItem(IDM_MUTE, MF_CHECKED);
else
menu.CheckMenuItem(IDM_MUTE, MF_UNCHECKED);
//*****************
//CBitmap bm1;
//bm1.Attach((HBITMAP)::LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_PLAY),IMAGE_BITMAP,0,0,0));
//bm2.Attach((HBITMAP)m_Play.GetBitmap());
//bm1.Attach(LoadBitmap(AfxGetResourceHandle(), MAKEINTRESOURCE(IDB_PLAY)));
//bm2.Attach(LoadBitmap(AfxGetResourceHandle(), MAKEINTRESOURCE(IDB_PLAY)));
//pPopup->ModifyMenu(0, MF_BYPOSITION, MF_OWNERDRAW, &bm1);
//pPopup->SetMenuItemBitmaps(0, MF_BYPOSITION, &bm1 , NULL);
CWnd* pWndPopupOwner = this;
while (pWndPopupOwner->GetStyle() & WS_CHILD)
pWndPopupOwner = pWndPopupOwner->GetParent();
// this->SetForegroundWindow();
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,
pWndPopupOwner);
// this->PostMessage(WM_NULL, 0, 0);
//bm1.Detach();
}
}
void CSimpleMP3Dlg::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
if (m_strM3UPath == m_strDefaultDir+_T("\\Default"))
{
m_List.SaveM3U(m_strM3UPath);
}
WriteProfile();
m_mcimp3.MCIClose();
m_bkBrush.DeleteObject();
delete m_pTrayIcon;
//卸去资源DLL
// if (m_hDLL)
// FreeLibrary(m_hDLL);
}
////////////////////////////////////////////////////////////////////////
/*
* 函数名称:OnCancel
* 函数介绍:重写父类成员OnCancel, 防止按Esc键退出
* 输入参数:无
* 输出参数:无
* 返回值 :无
*/
void CSimpleMP3Dlg::OnCancel()
{
// TODO: Add your command handler code here
// 什么也不做:避免按ESC键退出程序
}
void CSimpleMP3Dlg::OnOK()
{
// TODO: Add your command handler code here
/* if (this->GetFocus()==&m_List && m_List.GetSelCount())
{
m_List.SendMessage(WM_COMMAND, ID_LISTMENU_PLAY);
}
*/}
void CSimpleMP3Dlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{ //必须保证只有一个Slider控件
if (pScrollBar->GetDlgCtrlID()==IDC_SLIDER)
if (m_mcimp3.MCIIsOpened())
{ DWORD dwPos=(DWORD)((CSliderCtrl *)pScrollBar)->GetPos();
BOOL bPlaying=m_mcimp3.MCIIsPlaying();
// SetTime(dwPos);
SetTime(m_bElapse ? dwPos : m_mcimp3.m_dwLength-dwPos);
UpdateData(false);
if (nSBCode!=SB_ENDSCROLL)
{ KillTimer(TIMER1);
}else
{ m_mcimp3.MCISeekTo(dwPos);
if (bPlaying)
{ m_mcimp3.MCIPlay();
SetTimer(TIMER1, 1000, NULL);
}
}
}
// TODO: Add your message handler code here and/or call default
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}
BOOL CSimpleMP3Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
//为快捷键而设置
m_hAccTable = ::LoadAccelerators(AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDR_DIALOGACCELERATOR));
// 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
/*
// 修改系统菜单
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
UINT u=0, uItemCount = pSysMenu->GetMenuItemCount();
while (u < uItemCount-1)
{
pSysMenu->DeleteMenu(0, MF_BYPOSITION);
u++;
}
}
*/
//产生随机数种子
srand( (unsigned)time( NULL ) );
//初始化界面
InitInterface();
//读入上次的设置
ReadProfile();
return TRUE; // return TRUE unless you set the focus to a control
}
void CSimpleMP3Dlg::OnM3u()
{
// TODO: Add your control notification handler code here
// CG: This block was added by the Pop-up Menu component
{
//让快捷菜单在按扭左下角弹出
CRect rect;
m_M3u.GetWindowRect(rect);
CPoint point(rect.left, rect.bottom);
CMenu menu;
VERIFY(menu.LoadMenu(CG_IDR_POPUP_MENU_BUTTON));
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);
CWnd* pWndPopupOwner = &m_M3u;
while (pWndPopupOwner->GetStyle() & WS_CHILD)
pWndPopupOwner = pWndPopupOwner->GetParent();
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,
pWndPopupOwner);
}
}
void CSimpleMP3Dlg::OnMute()
{
// TODO: Add your control notification handler code here
BOOL bIsMute=m_Mute.GetCheck();
if (bIsMute)
{
m_Mute.SetPic(IDB_BACKGROUND, IDB_MUTE);
}
else
{
m_Mute.SetPic(IDB_BACKGROUND, IDB_VOLUME);
}
m_mcimp3.MCISetMute(bIsMute);
}
void CSimpleMP3Dlg::OnMyTrayIcon(WPARAM wParam, LPARAM lParam)
{
switch (lParam)
{
case WM_LBUTTONDOWN:
SendMessage(WM_SYSCOMMAND, SC_RESTORE);
break;
case WM_RBUTTONDOWN:
CPoint pnt(0, 0);
GetCursorPos(&pnt);
/*
******************SYMPTOMS******************
When you display a context menu for a Notify Icon (see Shell_NotifyIcon), clicking anywhere besides the menu or the window that created the menu (if it is visible) doesn't cause the menu to disappear. When this behavior is corrected, the second time this menu is displayed, it displays and then immediately disappears.
******************RESOLUTION******************
To correct the first behavior, you need to make the current window the foreground window before calling TrackPopupMenu or TrackPopupMenuEx.
The second problem is caused by a problem with TrackPopupMenu. It is necessary to force a task switch to the application that called TrackPopupMenu at some time in the near future. This can be accomplished by posting a benign message to the window or thread.
The following code will take care of all of this:
SetForegroundWindow(hDlg);
// Display the menu
TrackPopupMenu( hSubMenu,
TPM_RIGHTBUTTON,
pt.x,
pt.y,
0,
hDlg,
NULL);
PostMessage(hDlg, WM_NULL, 0, 0);
*/
this->SetForegroundWindow();
this->OnContextMenu(this, pnt);
this->PostMessage(WM_NULL, 0, 0);
break;
}
}
void CSimpleMP3Dlg::OnNext()
{
// TODO: Add your control notification handler code here
if (!Open(GetNext()))
return;
Play();
}
void CSimpleMP3Dlg::OnPause()
{
// TODO: Add your control notification handler code here
if (!m_mcimp3.MCIIsOpened())
{ m_Pause.SetCheck(false);
return;
}
if (m_mcimp3.MCIIsPlaying())
Pause();
else
Resume();
}
void CSimpleMP3Dlg::OnPlay()
{
// TODO: Add your control notification handler code here
// int iSelItemID;
if (!m_mcimp3.MCIIsOpened())
{ m_Play.SetCheck(false);
return;
}
if (!m_mcimp3.MCIIsPlaying())
if (m_mcimp3.MCIIsOpened())
Play();
else
if (m_List.GetCount()>0)
if (m_List.GetSelCount())
{ int iSelItem;
m_List.GetSelItems(1, &iSelItem);
ASSERT(iSelItem > -1);
if (!Open(iSelItem))
return;
Play();
}else
{ if (!Open(0))
return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -