home *** CD-ROM | disk | FTP | other *** search
- // CPlayerControlDlg.cpp : implementation file
- //
-
- #include "stdafx.h"
- #include "SCPlayer.h"
- #include "PlayerControlDlg.h"
- #include "PlayListDlg.h"
- #include "math.h"
- #include "wmpsettings.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CPlayerControlDlg dialog
-
-
- CPlayerControlDlg::CPlayerControlDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CPlayerControlDlg::IDD, pParent),m_bIsMoved(FALSE)
- {
- //{{AFX_DATA_INIT(CPlayerControlDlg)
- //}}AFX_DATA_INIT
- }
-
-
- void CPlayerControlDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CPlayerControlDlg)
- //DDX_Text(pDX, IDC_CURFILE, m_strCurFile);
- DDX_Text(pDX, IDC_CURTIME, m_strCurTime);
- //}}AFX_DATA_MAP
- }
-
-
- BEGIN_MESSAGE_MAP(CPlayerControlDlg, CDialog)
- //{{AFX_MSG_MAP(CPlayerControlDlg)
- ON_BN_CLICKED(IDC_PLAYBUT, OnPlaybut)
- ON_BN_CLICKED(IDC_PLAYLIST, OnPlaylist)
- ON_BN_CLICKED(IDC_OPENFILE, OnOpenfile)
- ON_BN_CLICKED(IDC_STOPBUT, OnStopbut)
- ON_BN_CLICKED(IDC_PAUSEBUT, OnPausebut)
- ON_BN_CLICKED(IDC_NEXTBUT, OnNextbut)
- ON_BN_CLICKED(IDC_PREVBUT, OnPrevbut)
- ON_WM_CLOSE()
- ON_WM_LBUTTONDOWN()
- ON_WM_LBUTTONUP()
- ON_WM_MOUSEMOVE()
- ON_WM_HSCROLL()
- ON_BN_CLICKED(IDC_AMEGA_BUTTON, OnAmegaButton)
- ON_WM_TIMER()
- ON_WM_RBUTTONDOWN()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CPlayerControlDlg message handlers
-
- void CPlayerControlDlg::OnPlaylist()
- {
- if (!theApp.m_pPlayListDlg)
- {
- theApp.m_pPlayListDlg = new CPlayListDlg;
- theApp.m_pPlayListDlg->Create(IDD_PLAYLIST,this);
- theApp.m_pPlayListDlg->ShowWindow(SW_SHOW);
- }
- else
- {
- if (theApp.m_pPlayListDlg->IsWindowVisible())
- {
- theApp.m_pPlayListDlg->ShowWindow(SW_HIDE);
- }
- else
- theApp.m_pPlayListDlg->ShowWindow(SW_SHOW);
- }
- }
-
- void CPlayerControlDlg::OnPlaybut()
- {
- SetTimer(111,10,0);
- EnsurePlayerIsReady();
- theApp.m_mWMPlayer.SetRedraw(FALSE);
- theApp.m_mWMPlayer.GetControls().play();
- theApp.m_mWMPlayer.SetRedraw(TRUE);
-
- }
-
- void CPlayerControlDlg::OnOpenfile()
- {
- CFileDialog dlg(TRUE);
-
- if(dlg.DoModal() == IDOK)
- {
- EnsurePlayerIsReady();
- SetTimer(111,10,0);
- CString path = dlg.GetPathName();
- PlayNew(path);
- m_strCurMediaName = theApp.m_mWMPlayer.GetCurrentMedia().GetName();
- theApp.m_pPlayListDlg->AddFile(path);
- theApp.m_pPlayListDlg->FillPlayList();
- }
-
- }
-
- void CPlayerControlDlg::OnStopbut()
- {
- KillTimer(111);
- EnsurePlayerIsReady();
- theApp.m_mWMPlayer.SetRedraw(FALSE);
- theApp.m_mWMPlayer.GetControls().stop();
- theApp.m_mWMPlayer.SetRedraw(TRUE);
- m_strCurMediaName = "";
- }
-
- void CPlayerControlDlg::OnPausebut()
- {
- EnsurePlayerIsReady();
- theApp.m_mWMPlayer.SetRedraw(FALSE);
- theApp.m_mWMPlayer.GetControls().pause();
- theApp.m_mWMPlayer.SetRedraw(TRUE);
- }
-
- void CPlayerControlDlg::OnNextbut()
- {
- CString str = theApp.m_pPlayListDlg->GetNextMediaPath();
- CWMPMedia me = theApp.m_mWMPlayer.newMedia(str);
- theApp.m_pSCPlayerDlg->SetFocus();
- theApp.m_mWMPlayer.SetCurrentMedia(me.operator LPDISPATCH());
- SetFocus();
- }
-
- void CPlayerControlDlg::OnPrevbut()
- {
- OnStopbut();
- CString str = theApp.m_pPlayListDlg->GetPrevMediaPath();
- CWMPMedia me = theApp.m_mWMPlayer.newMedia(str);
- theApp.m_pSCPlayerDlg->SetFocus();
- theApp.m_mWMPlayer.SetCurrentMedia(me.operator LPDISPATCH());
- SetFocus();
- }
- void CPlayerControlDlg::OnTimer(UINT nIDEvent)
- {
- switch(nIDEvent) {
- case 111://Timer for displaying the current position
- {
- if(!theApp.m_mWMPlayer.m_hWnd)
- {
- KillTimer(111);
- break;
- }
- double pos = theApp.m_mWMPlayer.GetControls().GetCurrentPosition();
- double dur = theApp.m_mWMPlayer.GetCurrentMedia().GetDuration();
- if(theApp.m_pSCPlayerDlg->m_flagMoveSlider)
- {
- ((CSliderCtrl*)theApp.m_pSCPlayerDlg->GetDlgItem(IDC_SLIDER))->SetPos(pos/(dur)*100);
- if(floor(pos*100) == floor(dur*100) && dur)
- KillTimer(111);
- }
- CString strTime;
- strTime.Format("Current / Total time: %s --- %s",theApp.m_mWMPlayer.GetControls().GetCurrentPositionString(),theApp.m_mWMPlayer.GetCurrentMedia().GetDurationString());
- m_strCurTime=strTime;
- UpdateData(FALSE);
- }
- break;
- }
-
- CDialog::OnTimer(nIDEvent);
- }
-
-
- void CPlayerControlDlg::EnsurePlayerIsReady()
- {
- if (!theApp.m_pSCPlayerDlg)
- {
- theApp.m_pSCPlayerDlg = new CSCPlayerDlg;
- theApp.m_pSCPlayerDlg->Create(IDD_SCPLAYER_DIALOG,this);
- theApp.m_pSCPlayerDlg->ShowWindow(SW_SHOW);
- theApp.m_pthePlayList = new CWMPPlaylist;
- }
- else if(!theApp.m_pSCPlayerDlg->IsWindowVisible())
- {
- theApp.m_pSCPlayerDlg->ShowWindow(SW_SHOW);
- }
- }
-
- void CPlayerControlDlg::OnClose()
- {
- KillTimer(111);
- CDialog::OnClose();
- }
-
- BOOL CPlayerControlDlg::OnInitDialog()
- {
- m_ToolTip.Create(this);
- m_ToolTip.SetDelayTime(0);
- m_ToolTip.SetMaxTipWidth(300);
-
- CRect r;
- GetDlgItem(IDC_AMEGA_BUTTON)->GetWindowRect(&r);
- m_ToolTip.AddTool(GetDlgItem(IDC_AMEGA_BUTTON),IDS_TOOLTIP);
- theApp.m_pSkin->IncludeWnd((long)m_hWnd,TRUE);
-
- //Do it only to have a button name in dialog editor
- GetDlgItem(IDC_PLAYBUT)->SetWindowText("");
- theApp.m_pSkin->SetCustomSkinWnd((long)GetDlgItem(IDC_PLAYBUT)->m_hWnd,"PlayButton",FALSE);
-
- //Do it only to have a button name in dialog editor
- GetDlgItem(IDC_STOPBUT)->SetWindowText("");
- theApp.m_pSkin->SetCustomSkinWnd((long)GetDlgItem(IDC_STOPBUT)->m_hWnd,"StopButton",FALSE);
-
- //Do it only to have a button name in dialog editor
- GetDlgItem(IDC_PAUSEBUT)->SetWindowText("");
- theApp.m_pSkin->SetCustomSkinWnd((long)GetDlgItem(IDC_PAUSEBUT)->m_hWnd,"PauseButton",FALSE);
-
- //Do it only to have a button name in dialog editor
- GetDlgItem(IDC_PREVBUT)->SetWindowText("");
- theApp.m_pSkin->SetCustomSkinWnd((long)GetDlgItem(IDC_PREVBUT)->m_hWnd,"PrevButton",FALSE);
-
- //Do it only to have a button name in dialog editor
- GetDlgItem(IDC_NEXTBUT)->SetWindowText("");
- theApp.m_pSkin->SetCustomSkinWnd((long)GetDlgItem(IDC_NEXTBUT)->m_hWnd,"NextButton",FALSE);
-
- GetDlgItem(IDC_OPENFILE)->SetWindowText("");
- theApp.m_pSkin->SetCustomSkinWnd((long)GetDlgItem(IDC_OPENFILE)->m_hWnd,"OpenButton",FALSE);
-
- GetDlgItem(IDC_PLAYLIST)->SetWindowText("");
- theApp.m_pSkin->SetCustomSkinWnd((long)GetDlgItem(IDC_PLAYLIST)->m_hWnd,"PlayListButton",FALSE);
-
- theApp.m_pSkin->SetCustomSkinWnd((long)GetDlgItem(IDC_VOLUME)->m_hWnd,"CustomSliders",FALSE);
-
- theApp.m_pSkin->SetCustomSkinWnd((long)m_hWnd,"ControlsFrame",TRUE);
- theApp.m_pSkin->SetCustomSkinWnd((long)m_hWnd,"ControlsDialog",FALSE);
-
- GetDlgItem(IDC_AMEGA_BUTTON)->SetWindowText("");
- theApp.m_pSkin->SetCustomSkinWnd((long)GetDlgItem(IDC_AMEGA_BUTTON)->m_hWnd,"AmegaButton",FALSE);
-
- OnPlaylist();
- CDialog::OnInitDialog();
-
- GetDlgItem(IDC_CURFILE)->SetWindowText("");
- GetDlgItem(IDC_CURTIME)->SetWindowText("");
-
- GetWindowRect(&r);
-
- SetWindowPos(NULL,100,100,r.Width(),r.Height(),SWP_NOSIZE|SWP_SHOWWINDOW);
- int width = r.Height()+100;
- theApp.m_pPlayListDlg->GetWindowRect(&r);
- theApp.m_pPlayListDlg->SetWindowPos(NULL,100,width,r.Width(),r.Height(),SWP_NOSIZE|SWP_SHOWWINDOW);
-
- CSliderCtrl* pVolume = (CSliderCtrl*)GetDlgItem(IDC_VOLUME);
- pVolume->SetRange(0,100);
- pVolume->SetPos(50);
-
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
-
-
- void CPlayerControlDlg::PlayNew(CString path)
- {
- if(path.IsEmpty())
- {
- path = theApp.m_pPlayListDlg->GetCurMediaPath();
- }
- EnsurePlayerIsReady();
- KillTimer(111);
- SetTimer(111,10,0);
- CWMPMedia me = theApp.m_mWMPlayer.newMedia(path);
- theApp.m_mWMPlayer.SetCurrentMedia(me.operator LPDISPATCH());
- GetDlgItem(IDC_CURFILE)->SetWindowText(me.GetName());
- }
-
-
- void CPlayerControlDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- int minpos;
- int maxpos;
- CSliderCtrl* pSlider = ((CSliderCtrl*)GetDlgItem(IDC_VOLUME));
- pSlider->GetRange(minpos, maxpos);
- int curpos = pSlider->GetPos();
-
- if(!theApp.m_pSCPlayerDlg)
- return;
-
- switch(nSBCode)
- {
- case SB_THUMBPOSITION:
- case SB_THUMBTRACK:
- {
- //m_flagMoveSlider=FALSE;
- if(theApp.m_mWMPlayer.GetCurrentMedia())
- {
- curpos=nPos;
- }
- }
- break;
- case SB_LEFT: // Scroll to far left.
- curpos = minpos;
- break;
-
- case SB_RIGHT: // Scroll to far right.
- curpos = maxpos;
- break;
-
- case SB_ENDSCROLL: // End scroll.
- break;
-
- case SB_LINELEFT: // Scroll left.
- if (curpos > minpos)
- curpos--;
- break;
-
- case SB_LINERIGHT: // Scroll right.
- if (curpos < maxpos)
- curpos++;
- break;
-
- case SB_PAGELEFT: // Scroll one page left.
- {
- if (curpos > minpos)
- curpos = max(minpos, curpos - (int)pSlider->GetPageSize());
- }
- break;
-
- case SB_PAGERIGHT: // Scroll one page right.
- {
- if (curpos < maxpos)
- curpos = min(maxpos, curpos + (int) pSlider->GetPageSize());
- }
- break;
- default:
- return;
- }
- pSlider->SetPos(curpos);
-
-
- theApp.m_mWMPlayer.GetSettings().SetVolume(curpos);
-
- CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
- }
-
- void CPlayerControlDlg::OnLButtonDown(UINT nFlags, CPoint point)
- {
- m_ptMouse = point;
- SetCapture();
- m_bIsMoved = TRUE;
-
- CDialog::OnLButtonDown(nFlags, point);
- }
- void CPlayerControlDlg::OnMouseMove(UINT nFlags, CPoint point)
- {
- if(nFlags&MK_LBUTTON && GetCapture()==this && m_bIsMoved)
- {
- CRect r;
- GetWindowRect(&r);
- r.OffsetRect(point - m_ptMouse);
- MoveWindow(&r);
- }
-
- CDialog::OnMouseMove(nFlags, point);
- }
-
- void CPlayerControlDlg::OnLButtonUp(UINT nFlags, CPoint point)
- {
-
- ReleaseCapture();
- m_bIsMoved = FALSE;
- CDialog::OnLButtonUp(nFlags, point);
- }
-
- void CPlayerControlDlg::OnAmegaButton()
- {
- //LoadSkin();
- static int index = 0;
- static CString arr[] = {"PlayerSkin-BoomBox.skf", "PlayerSkin.skf"};
-
- FILE* f= fopen(arr[index] ,"r");
- if(f)
- {
- fclose(f);
- theApp.m_pSkin->LoadSkinFromFile(arr[index]);
- theApp.m_pSkin->ApplySkin();
- }
- index = !index;
- // ::ShellExecute(0,"open","http://a-megastudio.com",0,0,0);
- }
-
- void CPlayerControlDlg::OnRButtonDown(UINT nFlags, CPoint point)
- {
- CPoint pt(GetMessagePos());
- CMenu popMenu;
-
- if ( !popMenu.LoadMenu(IDR_POPUP_MENU) )
- AfxMessageBox("Cannot create menu");
-
- CMenu *pMenu = popMenu.GetSubMenu(0);
-
- UINT mID = pMenu->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON | TPM_RETURNCMD,pt.x,pt.y,this);
- pMenu->DestroyMenu();
-
- switch(mID)
- {
- case ID_MENU_CHOOSESKIN:
- {
- LoadSkin();
- break;
- }
- case ID_MENU_ABOUT:
- {
- CAboutDlg dlg;
- dlg.DoModal();
- }
- }
- CDialog::OnRButtonDown(nFlags, point);
- }
-
- void CPlayerControlDlg::LoadSkin()
- {
- CString Filter("SkinCrafter files (*.skf)|*.skf||");
-
- CFileDialog dlg(TRUE, "skf", NULL, NULL, Filter);
-
- dlg.m_ofn.lpstrTitle = "Select file";
-
- if(dlg.DoModal()==IDOK)
- {
- CString path = dlg.GetPathName();
- theApp.m_pSkin->LoadSkinFromFile(path);
- theApp.m_pSkin->ApplySkin();
- }
- }
-
- BOOL CPlayerControlDlg::PreTranslateMessage(MSG* pMsg)
- {
- // TODO: Add your specialized code here and/or call the base class
-
- m_ToolTip.RelayEvent(pMsg);
-
- return CDialog::PreTranslateMessage(pMsg);
- }
-