📄 cd playerdlg.cpp
字号:
// CD PlayerDlg.cpp : implementation file
//
#include "stdafx.h"
#include "CD Player.h"
#include "CD PlayerDlg.h"
#include "resource.h"
#include "HyperLink.h"
#include "BtnST.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
CButtonST m_btnExit;
CHyperLink m_mailLink;
//}}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, IDOK, m_btnExit);
DDX_Control(pDX, IDC_STATIC_MAIL, m_mailLink);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
DynaCDMenu CCDPlayerDlg::m_DynaCDMenu[20]=
{
{ ID_TRACK01 , "TRACK01" },
{ ID_TRACK02 , "TRACK02" },
{ ID_TRACK03 , "TRACK03" },
{ ID_TRACK04 , "TRACK04" },
{ ID_TRACK05 , "TRACK05" },
{ ID_TRACK06 , "TRACK06" },
{ ID_TRACK07 , "TRACK07" },
{ ID_TRACK08 , "TRACK08" },
{ ID_TRACK09 , "TRACK09" },
{ ID_TRACK10 , "TRACK10" },
{ ID_TRACK11 , "TRACK11" },
{ ID_TRACK12 , "TRACK12" },
{ ID_TRACK13 , "TRACK13" },
{ ID_TRACK14 , "TRACK14" },
{ ID_TRACK15 , "TRACK15" },
{ ID_TRACK16 , "TRACK16" },
{ ID_TRACK17 , "TRACK17" },
{ ID_TRACK18 , "TRACK18" },
{ ID_TRACK19 , "TRACK19" },
{ ID_TRACK20 , "TRACK20" },
};
/////////////////////////////////////////////////////////////////////////////
// CCDPlayerDlg dialog
CCDPlayerDlg::CCDPlayerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCDPlayerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCDPlayerDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
// init the var.
m_nTotalSeconds=0;
m_nTotalMinutes=0;
m_nCurrentTrackSeconds=0;
m_nCurrentTrackMinutes=0;
m_nCurrentTrack=0;
m_nTotalTracks=0;
m_nCurrentSecond=0;
m_nCurrentMinute=0;
m_nTurnTimes=6;
m_bUserStoped=false;
// Our window's pos and size.
m_bIsSmall=false;
m_bIsTopmost=false;
m_bShowMsg=true;
m_bCDReady=false;
m_bPlayCircle=true;
m_clBkColor=RGB(236,213,157);
}
void CCDPlayerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCDPlayerDlg)
DDX_Control(pDX, IDC_STATIC_STRDOWN, m_stDownText);
DDX_Control(pDX, IDC_STATIC_STRUP, m_stUpText);
DDX_Control(pDX, IDC_BUTTON_CLOSE, m_btnClose);
DDX_Control(pDX, IDC_BUTTON_INFO, m_btnInfo);
DDX_Control(pDX, IDC_BUTTON_END, m_btnEnd);
DDX_Control(pDX, IDC_BUTTON_FBWORD, m_btnFBword);
DDX_Control(pDX, IDC_BUTTON_FFWORD, m_btnFFword);
DDX_Control(pDX, IDC_BUTTON_PAUSE, m_btnPause);
DDX_Control(pDX, IDC_BUTTON_START, m_btnStart);
DDX_Control(pDX, IDC_BUTTON_STOP, m_btnStop);
DDX_Control(pDX, IDC_BUTTON_PLAY, m_btnPlay);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCDPlayerDlg, CDialog)
ON_WM_CONTEXTMENU()
//{{AFX_MSG_MAP(CCDPlayerDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_LBUTTONDOWN()
ON_COMMAND(ID_MENU_EXIT, OnMenuExit)
ON_COMMAND(IDM_ABOUTBOX, OnAboutbox)
ON_BN_CLICKED(IDC_BUTTON_CLOSE, OnButtonClose)
ON_BN_CLICKED(IDC_BUTTON_INFO, OnButtonInfo)
ON_BN_CLICKED(IDC_BUTTON_PLAY, OnButtonPlay)
ON_BN_CLICKED(IDC_BUTTON_STOP, OnButtonStop)
ON_WM_TIMER()
ON_COMMAND(ID_MENU_NEXTTRACK, OnMenuNexttrack)
ON_COMMAND(ID_MENU_LAST, OnMenuLast)
ON_BN_CLICKED(IDC_BUTTON_PAUSE, OnButtonPause)
ON_BN_CLICKED(IDC_BUTTON_FFWORD, OnButtonFfword)
ON_BN_CLICKED(IDC_BUTTON_FBWORD, OnButtonFbword)
ON_BN_CLICKED(IDC_BUTTON_END, OnButtonEnd)
ON_BN_CLICKED(IDC_BUTTON_START, OnButtonStart)
ON_COMMAND(ID_MENU_EJECT, OnMenuEject)
ON_COMMAND(ID_MENU_CHAGESHAPE, OnMenuChageshape)
ON_WM_LBUTTONDBLCLK()
ON_COMMAND(ID_MENU_TOPMOST, OnMenuTopmost)
ON_WM_ERASEBKGND()
ON_WM_CTLCOLOR()
ON_COMMAND(ID_MENU_SHOWMSG, OnMenuShowmsg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCDPlayerDlg message handlers
BOOL CCDPlayerDlg::OnInitDialog()
{
CDialog::OnInitDialog();
AdjustButtons();
// 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
// Set the window's text.
SetWindowText("CD Player");
// Set the window's rect.
CRect windowRect;
windowRect.SetRect(0,
0,
BACKWIDTH ,
BACKHEIGHT );
// Set the Info rect.
rectInfo.SetRect(AMPLIFIERWIDTH ,0,AMPLIFIERWIDTH+10,10);
m_btnInfo.MoveWindow (&rectInfo,FALSE);
m_btnInfo.SetActiveBgColor(m_clBkColor,TRUE);
m_btnInfo.SetInactiveBgColor(m_clBkColor,TRUE);
m_btnInfo.SetIcon(IDI_ICON_INFO);
// Set the Close rect.
rectClose.SetRect(BACKWIDTH-AMPLIFIERWIDTH-10,0,BACKWIDTH-AMPLIFIERWIDTH,10);
m_btnClose.SetActiveBgColor(m_clBkColor,TRUE);
m_btnClose.SetInactiveBgColor(m_clBkColor,TRUE);
m_btnClose.MoveWindow(&rectClose,FALSE);
m_btnClose.SetIcon(IDI_ICON_CLOSE);
// Resize our Window.
this->MoveWindow(&windowRect,FALSE);
m_rShowState.SetRect(AMPLIFIERWIDTH+9,10,AMPLIFIERWIDTH+93,48);
// Set the up state static.
m_rStrUp.SetRect(m_rShowState.left,m_rShowState.top,m_rShowState.right,m_rShowState.top+m_rShowState.Height()/2);
m_stUpText.MoveWindow(&m_rStrUp);
m_stUpText.SetBkColor(RGB(0,0,0));
m_stUpText.SetTextColor(RGB(0,255,0));
m_stUpText.SetTextHeight(12);
m_stUpText.VCenterText();
m_stUpText.BeginRoll(3,100);
if(!m_bShowMsg)
m_stUpText.ShowWindow(SW_HIDE);
// Set the down state static.
m_rStrDown.SetRect(m_rShowState.left,m_rShowState.top+m_rShowState.Height()/2,m_rShowState.right,m_rShowState.bottom);
if(!m_bShowMsg)
m_stDownText.ShowWindow(SW_HIDE);
m_stDownText.MoveWindow(&m_rStrDown);
m_stDownText.SetBkColor(RGB(0,0,0));
m_stDownText.SetTextColor(RGB(0,255,0));
m_stDownText.SetTextHeight(12);
m_stDownText.VCenterText();
if(!m_bShowMsg)
m_stUpText.ShowWindow(SW_HIDE);
// CG: The following block was added by the ToolTips component. { // Create the ToolTip control. m_tooltip.Create(this); m_tooltip.Activate(TRUE); // TODO: Use one of the following forms to add controls: m_tooltip.AddTool(GetDlgItem(IDC_BUTTON_PLAY),"Play");
m_tooltip.AddTool(GetDlgItem(IDC_BUTTON_STOP),"Stop");
m_tooltip.AddTool(GetDlgItem(IDC_BUTTON_PAUSE),"Pause");
m_tooltip.AddTool(GetDlgItem(IDC_BUTTON_START),"To Start");
m_tooltip.AddTool(GetDlgItem(IDC_BUTTON_END),"To End");
m_tooltip.AddTool(GetDlgItem(IDC_BUTTON_FFWORD),"Fast Foward");
m_tooltip.AddTool(GetDlgItem(IDC_BUTTON_FBWORD),"Fast Backword");
m_tooltip.AddTool(GetDlgItem(IDC_BUTTON_CLOSE),"Close");
m_tooltip.AddTool(GetDlgItem(IDC_BUTTON_INFO),"Option");
}
// m_btnPlay.SubclassDlgItem(IDC_BUTTON_PLAY,this);
// Set the play button
m_btnPlay.SetActiveBgColor(m_clBkColor,TRUE);
m_btnPlay.SetInactiveBgColor(m_clBkColor,TRUE);
m_btnPlay.SetIcon(IDI_ICON_PLAYENABLE,
IDI_ICON_PLAYDISABLED);
// Set the stop button
m_btnStop.SetActiveBgColor(m_clBkColor,TRUE);
m_btnStop.SetInactiveBgColor(m_clBkColor,TRUE);
m_btnStop.SetIcon(IDI_ICON_STOPENABLED,
IDI_ICON_STOPDISABLED);
// Set the pause button
m_btnPause.SetActiveBgColor(m_clBkColor,TRUE);
m_btnPause.SetInactiveBgColor(m_clBkColor,TRUE);
m_btnPause.SetIcon(IDI_ICON_PAUSEENABLED,
IDI_ICON_PAUSEDISABLED);
// Set the fast-forward button
m_btnFFword.SetActiveBgColor(m_clBkColor,TRUE);
m_btnFFword.SetInactiveBgColor(m_clBkColor,TRUE);
m_btnFFword.SetIcon(IDI_ICON_FFWORDENABLED,
IDI_ICON_FFWORDDISABLED);
// Set the fast-backward button
m_btnFBword.SetActiveBgColor(m_clBkColor,TRUE);
m_btnFBword.SetInactiveBgColor(m_clBkColor,TRUE);
m_btnFBword.SetIcon(IDI_ICON_FBWORDENABLED,
IDI_ICON_FBWORDDISABLED);
// Set the move-to-end button
m_btnEnd.SetActiveBgColor(m_clBkColor,TRUE);
m_btnEnd.SetInactiveBgColor(m_clBkColor,TRUE);
m_btnEnd.SetIcon(IDI_ICON_TOENDENABLED,
IDI_ICON_TOENDDISABLED);
// Set the move-to-start button
m_btnStart.SetActiveBgColor(m_clBkColor,TRUE);
m_btnStart.SetInactiveBgColor(m_clBkColor,TRUE);
m_btnStart.SetIcon(IDI_ICON_TOSTARTENABLED,
IDI_ICON_TOSTARTDISABLED);
// Set the auto-detect timer.
SetTimer(1,200,NULL);
// Open the CD device.
m_CDAudio.Open ();
return TRUE; // return TRUE unless you set the focus to a control
}
void CCDPlayerDlg::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 CCDPlayerDlg::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 CCDPlayerDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CCDPlayerDlg::OnOK()
{
// TODO: Add extra validation here
}
void CCDPlayerDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnLButtonDown(nFlags, point);
PostMessage(WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM (point.x, point.y));
}
void CCDPlayerDlg::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_CDPLAYER_DLG)); CMenu* pPopup = menu.GetSubMenu(0); ASSERT(pPopup != NULL);
// We'll add tracks to our menu.
// Define the time of one track.
int nMinutes,nSeconds;
CString sTrackInfo;
if(m_bCDReady)
{
pPopup->AppendMenu (MF_STRING,ID_MENU_TOPMOST,"Always on &Top T");
pPopup->AppendMenu (MF_STRING,ID_MENU_SHOWMSG,"Show State &Window");
pPopup->AppendMenu (MF_STRING,ID_MENU_EJECT,"E&ject/Close E");
// Check the menu items.
UINT nMenuState=m_bIsTopmost ? MF_CHECKED | MF_BYCOMMAND : MF_UNCHECKED | MF_BYCOMMAND;
pPopup->CheckMenuItem(ID_MENU_TOPMOST,nMenuState);
nMenuState=m_bShowMsg ? MF_CHECKED | MF_BYCOMMAND : MF_UNCHECKED | MF_BYCOMMAND;
pPopup->CheckMenuItem(ID_MENU_SHOWMSG,nMenuState);
pPopup->AppendMenu (MF_SEPARATOR);
// Add the track info.
for(int i=0;i<m_nTotalTracks;i++)
{
m_CDAudio.GetTrackLength (i+1,&nMinutes,&nSeconds);
sTrackInfo.Format("%s %02d:%02d",m_DynaCDMenu[i].m_nString,nMinutes,nSeconds);
pPopup->AppendMenu (MF_STRING,m_DynaCDMenu[i].m_nID,sTrackInfo);
}
// Check our menu item.
pPopup->CheckMenuItem( m_DynaCDMenu[m_nCurrentTrack-1].m_nID ,MF_CHECKED );
}
else
{
pPopup->DeleteMenu(ID_MENU_LAST,MF_BYCOMMAND);
pPopup->DeleteMenu(ID_MENU_NEXTTRACK,MF_BYCOMMAND);
// Show the state.
pPopup->AppendMenu (MF_STRING,ID_MENU_STATE,"Your CD is not ready.");
pPopup->AppendMenu (MF_SEPARATOR);
pPopup->AppendMenu (MF_STRING,ID_MENU_TOPMOST,"Always on &Top T");
pPopup->AppendMenu (MF_STRING,ID_MENU_SHOWMSG,"Show State &Window");
pPopup->AppendMenu (MF_STRING,ID_MENU_EJECT,"E&ject/Close E");
// Check the menu items.
UINT nMenuState=m_bIsTopmost ? MF_CHECKED | MF_BYCOMMAND : MF_UNCHECKED | MF_BYCOMMAND;
pPopup->CheckMenuItem(ID_MENU_TOPMOST,nMenuState);
nMenuState=m_bShowMsg ? MF_CHECKED | MF_BYCOMMAND : MF_UNCHECKED | MF_BYCOMMAND;
pPopup->CheckMenuItem(ID_MENU_SHOWMSG,nMenuState);
}
// Add exit to the end.
pPopup->AppendMenu (MF_SEPARATOR);
pPopup->AppendMenu (MF_STRING,ID_MENU_EXIT,"E&xit X");
CWnd* pWndPopupOwner = this; while (pWndPopupOwner->GetStyle() & WS_CHILD) pWndPopupOwner = pWndPopupOwner->GetParent(); pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, pWndPopupOwner); }
}
void CCDPlayerDlg::OnMenuExit()
{
// TODO: Add your command handler code here
OnCancel();
}
BOOL CCDPlayerDlg::PreTranslateMessage(MSG* pMsg)
{
// CG: The following block was added by the ToolTips component. { // Let the ToolTip process this message. m_tooltip.RelayEvent(pMsg); } if(pMsg->message==WM_KEYDOWN && (int)pMsg->wParam==VK_RETURN )
{
OnButtonPlay();
return 0;
}
if(pMsg->message==WM_CHAR)
{
switch((TCHAR)pMsg->wParam)
{
case 'p':
case 'P':
OnButtonPause();
return 0;
break;
case 'n':
case 'N':
OnMenuNexttrack();
return 0;
break;
case 'x':
case 'X':
OnMenuExit();
return 0;
break;
case 'l':
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -