home *** CD-ROM | disk | FTP | other *** search
- // PlayListDlg.cpp : implementation file
- //
-
- #include "stdafx.h"
- #include "SCPlayer.h"
- #include "PlayListDlg.h"
- #include "PlayerControlDlg.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- //////////////////////////////////////////////////////////////////////////
- LRESULT CPlayListBox::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
- {
- switch(message)
- {
- case WM_LBUTTONDBLCLK:
- ((CPlayListDlg*)GetParent())->SetCurFileID(GetCurSel());
- ((CPlayerControlDlg*)AfxGetMainWnd())->PlayNew();
- break;
- }
- return CListBox::WindowProc(message, wParam, lParam);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CPlayListDlg dialog
-
-
- CPlayListDlg::CPlayListDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CPlayListDlg::IDD, pParent),m_CurFileID(-1)
- {
- //{{AFX_DATA_INIT(CPlayListDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- }
-
-
- void CPlayListDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CPlayListDlg)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
-
-
- BEGIN_MESSAGE_MAP(CPlayListDlg, CDialog)
- //{{AFX_MSG_MAP(CPlayListDlg)
- ON_BN_CLICKED(IDC_ADDTOPLAYLIST, OnAddFiles)
- ON_BN_CLICKED(IDC_DELFORMPLAYLIST, OnDeleteFiles)
- ON_WM_SIZE()
- ON_WM_CLOSE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CPlayListDlg message handlers
-
- void CPlayListDlg::OnAddFiles()
- {
- CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT);
- if(dlg.DoModal()==IDOK)
- {
- POSITION pos = dlg.GetStartPosition();
- while (pos)
- {
- CString path = dlg.GetNextPathName(pos);
- AddFile(path);
- }
- FillPlayList();
- if(m_CurFileID<0)
- {
- SetCurFileID(0);
- }
- }
- }
-
- void CPlayListDlg::OnDeleteFiles()
- {
- CListBox* pList = ((CListBox*)GetDlgItem(IDC_THELIST));
- CString key;
-
- int i = pList->GetCurSel();
- if(i>LB_ERR)
- {
- pList->GetText(i,key);
- m_PlayListMap.RemoveKey(key);
- }
-
- FillPlayList();
- }
- void CPlayListDlg::OnSize(UINT nType, int cx, int cy)
- {
- CDialog::OnSize(nType, cx, cy);
-
- CWnd* pWnd = GetDlgItem(IDC_THELIST);
- if (pWnd)
- pWnd->MoveWindow(0,0,cx,cy-12);
- pWnd = GetDlgItem(IDC_ADDTOPLAYLIST);
- if (pWnd)
- pWnd->MoveWindow(0,cy-11,32,10);
- pWnd = GetDlgItem(IDC_DELFORMPLAYLIST);
- if (pWnd)
- pWnd->MoveWindow(33,cy-11,32,10);
- }
-
- BOOL CPlayListDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- theApp.m_pSkin->IncludeWnd((long)m_hWnd,TRUE);
- theApp.m_pSkin->SetCustomSkinWnd((long)m_hWnd,"PlayerFrame",TRUE);
- theApp.m_pSkin->SetCustomSkinWnd((long)m_hWnd,"PlayListDialog",FALSE);
-
- //Do it only to have a button name in dialog editor
- GetDlgItem(IDC_ADDTOPLAYLIST)->SetWindowText("");
- theApp.m_pSkin->SetCustomSkinWnd((long)GetDlgItem(IDC_ADDTOPLAYLIST)->m_hWnd,"AddButton",FALSE);
-
- //Do it only to have a button name in dialog editor
- GetDlgItem(IDC_DELFORMPLAYLIST)->SetWindowText("");
- theApp.m_pSkin->SetCustomSkinWnd((long)GetDlgItem(IDC_DELFORMPLAYLIST)->m_hWnd,"DelButton",FALSE);
-
- CRect r;
- GetWindowRect(&r);
-
- r.left+=1;
- MoveWindow(r);
-
- CListBox* pList = ((CListBox*)GetDlgItem(IDC_THELIST));
-
- m_myLb.SubclassDlgItem(IDC_THELIST,this);
-
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
-
- void CPlayListDlg::OnClose()
- {
- ShowWindow(SW_HIDE) ;
- //CDialog::OnClose();
- }
-
- CString CPlayListDlg::GetCurMediaPath()
- {
- if(m_CurFileID<0)
- return "";
- CListBox* pList = ((CListBox*)GetDlgItem(IDC_THELIST));
- CString str;
- pList->GetText(m_CurFileID,str);
- CString thepath;
- if(!m_PlayListMap.Lookup(str, thepath))
- return "";
- else
- return thepath;
- }
-
- CString CPlayListDlg::GetNextMediaPath()
- {
- if(m_CurFileID<0)
- return "";
- if(m_CurFileID<m_PlayListMap.GetCount()-1)
- m_CurFileID++;
-
- CListBox* pList = ((CListBox*)GetDlgItem(IDC_THELIST));
- CString str;
- pList->GetText(m_CurFileID,str);
- CString thepath;
- if(!m_PlayListMap.Lookup(str, thepath))
- return "";
- else
- return thepath;
- }
- CString CPlayListDlg::GetPrevMediaPath()
- {
- if(m_CurFileID<0)
- return "";
- if (m_CurFileID>0)
- m_CurFileID--;
-
- CListBox* pList = ((CListBox*)GetDlgItem(IDC_THELIST));
- CString str;
- pList->GetText(m_CurFileID,str);
- CString thepath;
- if(!m_PlayListMap.Lookup(str, thepath))
- return "";
- else
- return thepath;
- }
-
- void CPlayListDlg::FillPlayList()
- {
- CListBox* pList = ((CListBox*)GetDlgItem(IDC_THELIST));
- pList->ResetContent();
- POSITION pos = m_PlayListMap.GetStartPosition();
- CString fname, path;
- int i=0;
- while (pos)
- {
- m_PlayListMap.GetNextAssoc(pos,fname,path);
- pList->InsertString(i++,fname);
- }
-
- if(m_PlayListMap.GetCount() == 0)
- SetCurFileID(-1);
- }
-
- void CPlayListDlg::SetCurFileID(int curId)
- {
- m_CurFileID = curId;
- CListBox* pList = ((CListBox*)GetDlgItem(IDC_THELIST));
- CString str;
- pList->GetText(m_CurFileID,str);
- pList->SelectString(m_CurFileID,str);
- }
-
- void CPlayListDlg::AddFile(CString fullpath)
- {
- char drive[_MAX_DRIVE]="";
- char dir[_MAX_DIR]="";
- char fname[_MAX_FNAME]="";
- char ext[_MAX_EXT]="";
-
- CString fkeyname;
- _splitpath(fullpath,drive,dir,fname,ext);
- fkeyname.Format("%s%s",fname,ext);
- m_PlayListMap.SetAt(fkeyname,fullpath);
- }