📄 cd playerdlg.cpp
字号:
case 'L':
OnMenuLast();
return 0;
break;
case 'e':
case 'E':
OnMenuEject();
return 0;
break;
case 't':
case 'T':
OnMenuTopmost();
return 0;
break;
default:
break;
}
}
return CDialog::PreTranslateMessage(pMsg); // CG: This was added by the ToolTips component.
}
void CCDPlayerDlg::OnAboutbox()
{
// TODO: Add your command handler code here
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
void CCDPlayerDlg::OnButtonClose()
{
// TODO: Add your control notification handler code here
OnCancel() ;
}
void CCDPlayerDlg::OnButtonInfo()
{
// TODO: Add your control notification handler code here
CPoint point;
GetCursorPos(&point);
CMenu menu;
VERIFY(menu.LoadMenu(CG_IDR_POPUP_CDPLAYER_DLG));
CMenu* pPopup = menu.GetSubMenu(1);
ASSERT(pPopup != NULL);
// Check our 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);
CWnd* pWndPopupOwner = this;
while (pWndPopupOwner->GetStyle() & WS_CHILD)
pWndPopupOwner = pWndPopupOwner->GetParent();
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,
pWndPopupOwner);
}
void CCDPlayerDlg::OnButtonPlay()
{
// TODO: Add your control notification handler code here
m_CDAudio.Play();
m_bUserStoped=false;
}
void CCDPlayerDlg::OnButtonStop()
{
// TODO: Add your control notification handler code here
m_CDAudio.Stop ();
m_bUserStoped=true;
}
void CCDPlayerDlg::OnCancel()
{
// TODO: Add extra cleanup here
if(MessageBox("You really want to exit?",
NULL,MB_YESNO | MB_ICONQUESTION)==IDYES)
{
KillTimer(1);
CDialog::OnCancel();
}
}
void CCDPlayerDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
BOOL bPaused;
BOOL bPlaying;
if(m_CDAudio.IsDriveReady() && CanPlay())
{
// Reset our var.
if(!m_bCDReady)
{
m_nTotalTracks=m_CDAudio.GetTotalTracks();
m_bCDReady=true;
}
m_nCurrentTrack=m_CDAudio.GetCurrentTrack();
m_CDAudio.GetTotalLength(&m_nTotalMinutes,&m_nTotalSeconds);
m_CDAudio.GetTrackLength(m_nCurrentTrack,
&m_nCurrentTrackMinutes,
&m_nCurrentTrackSeconds);
m_nCurrentMinute=m_CDAudio.GetMinutes();
m_nCurrentSecond=m_CDAudio.GetSeconds();
bPlaying=m_CDAudio.IsPlaying(&bPaused);
if(!bPlaying && !m_bUserStoped)
{
// Play the CD.
m_CDAudio.Play ();
}
else if(m_bUserStoped)
{
m_stUpText.SetText("Stopped...");
}
else if(bPaused)
{
m_stUpText.SetText("Paused...");
}
else
{
// Playing.
// We'll judge if we have reach the end of the CD.
if(m_nCurrentMinute==m_nCurrentTrackMinutes &&
m_nCurrentSecond==m_nCurrentTrackSeconds)
{
m_stUpText.SetText(" Finished");
if(m_bPlayCircle)
{
m_CDAudio.SeekTo(1,0,0,0);
}
else
{
m_CDAudio.Close();
}
}
else
m_stUpText.SetText("Playing...");
}
CString tempstr;
tempstr.Format(" [%02d] %02d:%02d",m_nCurrentTrack,
m_nCurrentMinute,m_nCurrentSecond);
if(tempstr!=m_sCurTrack)
{
m_sCurTrack=tempstr;
m_stDownText.SetText(m_sCurTrack);
}
}
else
{
// Reset our vars.
m_bCDReady=false;
m_nTotalSeconds=0;
m_nTotalMinutes=0;
m_nCurrentTrackSeconds=0;
m_nCurrentTrackMinutes=0;
m_nCurrentTrack=0;
m_nTotalTracks=0;
m_stUpText.SetText(" Not Ready...");
m_stDownText.SetText(" CD Player");
}
// Reset the buttons.
m_btnPlay.EnableWindow((m_bUserStoped && m_bCDReady)?TRUE:FALSE);
m_btnStop.EnableWindow((bPlaying && m_bCDReady)?TRUE:FALSE);
m_btnPause.EnableWindow((m_bCDReady && !m_bUserStoped)?TRUE:FALSE);
m_btnFFword.EnableWindow((bPlaying && m_bCDReady)?TRUE:FALSE);
m_btnFBword.EnableWindow((bPlaying && m_bCDReady)?TRUE:FALSE);
m_btnEnd.EnableWindow((bPlaying && m_bCDReady)?TRUE:FALSE);
m_btnStart.EnableWindow((bPlaying && m_bCDReady)?TRUE:FALSE);
CDialog::OnTimer(nIDEvent);
}
BOOL CCDPlayerDlg::OnCommand(WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
// Get the selected track.
int index=LOWORD(wParam)-ID_TRACK01+1;
// Make sure it is what we need.
if(index<=m_nTotalTracks && index>=1)
{
m_CDAudio.SeekTo (index,0,0,0);
m_CDAudio.Play ();
m_nCurrentTrack=index;
}
return CDialog::OnCommand(wParam, lParam);
}
void CCDPlayerDlg::OnMenuNexttrack()
{
// TODO: Add your command handler code here
if(m_nCurrentTrack==m_nTotalTracks)
{
// now it's the end,let's back.
m_nCurrentTrack=1;
m_CDAudio.SeekTo(1,0,0,0);
}
else
{
m_nCurrentTrack++;
m_CDAudio.SeekTo (m_nCurrentTrack,0,0,0);
}
m_CDAudio.Play ();
}
void CCDPlayerDlg::OnMenuLast()
{
// TODO: Add your command handler code here
if(m_nCurrentTrack==1)
{
// now it's the begining.
m_nCurrentTrack=m_nTotalTracks;
m_CDAudio.SeekTo(m_nCurrentTrack,0,0,0);
}
else
{
m_nCurrentTrack--;
m_CDAudio.SeekTo (m_nCurrentTrack,0,0,0);
}
m_CDAudio.Play ();
}
void CCDPlayerDlg::OnButtonPause()
{
// TODO: Add your control notification handler code here
BOOL bPaused;
m_CDAudio.IsPlaying(&bPaused);
if(!bPaused)
{
m_CDAudio.Pause ();
}
else
{
m_CDAudio.Play ();
}
}
void CCDPlayerDlg::OnButtonFfword()
{
// TODO: Add your control notification handler code here
int nSkipTime; // Skip time
int nTotalTime; // The track's total time.
int nCurrentTime; // The playing time.
nTotalTime=m_nCurrentTrackMinutes * 60 +m_nCurrentTrackSeconds;
nCurrentTime=m_nCurrentMinute * 60 +m_nCurrentSecond;
nSkipTime=nTotalTime / m_nTurnTimes;
if(nCurrentTime+nSkipTime>=nTotalTime)
{
// Move to next track.
OnMenuNexttrack();
}
else
{
nCurrentTime+=nSkipTime;
m_nCurrentMinute=nCurrentTime / 60;
m_nCurrentSecond=nCurrentTime % 60;
m_CDAudio.SeekTo(m_nCurrentTrack,
m_nCurrentMinute,
m_nCurrentSecond,
0);
}
m_CDAudio.Play();
}
void CCDPlayerDlg::OnButtonFbword()
{
// TODO: Add your control notification handler code here
int nSkipTime; // Skip time
int nTotalTime; // The track's total time.
int nCurrentTime; // The playing time.
nTotalTime=m_nCurrentTrackMinutes * 60 +m_nCurrentTrackSeconds;
nCurrentTime=m_nCurrentMinute * 60 +m_nCurrentSecond;
nSkipTime=nTotalTime / m_nTurnTimes;
if(nCurrentTime-nSkipTime<=0)
{
// Move to start.
OnButtonStart();
}
else
{
nCurrentTime-=nSkipTime;
m_nCurrentMinute=nCurrentTime / 60;
m_nCurrentSecond=nCurrentTime % 60;
m_CDAudio.SeekTo(m_nCurrentTrack,
m_nCurrentMinute,
m_nCurrentSecond,
0);
}
m_CDAudio.Play();
}
bool CCDPlayerDlg::CanPlay()
{
for(int i=1;i<=m_CDAudio.GetTotalTracks();i++)
{
if(m_CDAudio.IsAudioTrack(i))
return true;
}
return false;
}
void CCDPlayerDlg::OnButtonEnd()
{
// TODO: Add your control notification handler code here
OnMenuNexttrack();
}
void CCDPlayerDlg::OnButtonStart()
{
// TODO: Add your control notification handler code here
m_CDAudio.SeekTo (m_nCurrentTrack,0,0,0);
m_CDAudio.Play();
}
void CCDPlayerDlg::OnMenuEject()
{
// TODO: Add your command handler code here
if(!m_CDAudio.IsDriveReady())
{
m_CDAudio.CloseDrive();
}
else
{
m_CDAudio.OpenDrive();
}
}
void CCDPlayerDlg::OnMenuChageshape()
{
// TODO: Add your command handler code here
CRect rect;
GetWindowRect(&rect);
if(!m_bIsSmall)
{
// Move it to small.
MoveWindow(rect.left,rect.top,
BACKWIDTH,9);
m_bIsSmall=true;
}
else
{
// Move it to small.
MoveWindow(rect.left,rect.top,
BACKWIDTH,BACKHEIGHT);
m_bIsSmall=false;
}
}
void CCDPlayerDlg::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_rStrUp.PtInRect(point) || m_rStrDown.PtInRect(point) )
OnMenuShowmsg();
else
OnMenuChageshape();
CDialog::OnLButtonDblClk(nFlags, point);
}
void CCDPlayerDlg::OnMenuTopmost()
{
// TODO: Add your command handler code here
if(m_bIsTopmost)
{
::SetWindowPos(this->GetSafeHwnd(),HWND_NOTOPMOST,
0,0,10,10,SWP_NOSIZE | SWP_NOMOVE);
m_bIsTopmost=false;
}
else
{
::SetWindowPos(this->GetSafeHwnd(),HWND_TOPMOST,
0,0,10,10,SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
m_bIsTopmost=true;
}
}
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_mailLink.SetURL(_T("mailto:andygood@263.net"));
m_btnExit.SetIcon(IDI_ICON_EXIT);
m_btnExit.SetFlat(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
BOOL CCDPlayerDlg::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
// We'll draw our background picture here.
CDC memDC;
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BITMAP_MAINBACK);
memDC.CreateCompatibleDC (pDC);
CBitmap *oldBitmap=memDC.SelectObject(&bitmap);
pDC->BitBlt (0,0,BACKWIDTH,BACKHEIGHT,&memDC,0,0,SRCCOPY);
memDC.SelectObject(oldBitmap);
return TRUE;
}
HBRUSH CCDPlayerDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
// TODO: Return a different brush if the default is not desired
CBrush brush(m_clBkColor);
HBRUSH hBrush=HBRUSH(brush);
return hBrush;
}
void CCDPlayerDlg::OnMenuShowmsg()
{
// TODO: Add your command handler code here
if(m_bShowMsg)
{
m_stUpText.ShowWindow(SW_HIDE);
m_stDownText.ShowWindow(SW_HIDE);
m_bShowMsg=false;
}
else
{
m_stUpText.ShowWindow(SW_SHOWNORMAL);
m_stDownText.ShowWindow(SW_SHOWNORMAL);
m_bShowMsg=true;
}
}
///////////////////////////////////////////////////////////
void CCDPlayerDlg::AdjustButtons()
{
int space = (int)((BACKWIDTH - 2*AMPLIFIERWIDTH - 7*BTNWIDTH)/8);
int start = AMPLIFIERWIDTH + space;
// CString str;
// str.Format("%d",space);
// MessageBox(str);
m_btnPlay.MoveWindow(CRect(start,BTNYPOS,start+BTNWIDTH,BTNYPOS+BTNWIDTH));
start += BTNWIDTH + space;
m_btnStop.MoveWindow(CRect(start,BTNYPOS,start+BTNWIDTH,BTNYPOS+BTNWIDTH));
start += BTNWIDTH + space;
m_btnPause.MoveWindow(CRect(start,BTNYPOS,start+BTNWIDTH,BTNYPOS+BTNWIDTH));
start += BTNWIDTH + space;
m_btnFFword.MoveWindow(CRect(start,BTNYPOS,start+BTNWIDTH,BTNYPOS+BTNWIDTH));
start += BTNWIDTH + space;
m_btnFBword.MoveWindow(CRect(start,BTNYPOS,start+BTNWIDTH,BTNYPOS+BTNWIDTH));
start += BTNWIDTH + space;
m_btnEnd.MoveWindow(CRect(start,BTNYPOS,start+BTNWIDTH,BTNYPOS+BTNWIDTH));
start += BTNWIDTH + space;
m_btnStart.MoveWindow(CRect(start,BTNYPOS,start+BTNWIDTH,BTNYPOS+BTNWIDTH));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -