home *** CD-ROM | disk | FTP | other *** search
- // SCPlayerDlg.cpp : implementation file
- //
-
-
- #include "stdafx.h"
- #include "SCPlayer.h"
- #include "SCPlayerDlg.h"
- #include "math.h"
- #include "wmpplaylist.h"
- #include "wmpmedia.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- LPWSTR ProduceWFromA( UINT uiCodePage, LPCSTR psz )
- {
- LPWSTR pszW;
- int cch;
-
- if (psz == NULL || psz == LPSTR_TEXTCALLBACKA)
- return (LPWSTR)psz;
-
- // The old code would call lstrlen and lstrcpy which would fault internal to the
- // api, this should do about the same...
- if (IsBadReadPtr(psz,1))
- return NULL; // For now lets try not setting a string...
-
- cch = MultiByteToWideChar(uiCodePage, 0, psz, -1, NULL, 0);
-
- if (cch == 0)
- cch = 1;
-
- pszW = (LPWSTR)LocalAlloc( LMEM_FIXED, cch * sizeof(WCHAR) );
-
- if (pszW != NULL ) {
- if (MultiByteToWideChar( uiCodePage, MB_PRECOMPOSED, psz, -1, pszW,
- cch ) == FALSE) {
- LocalFree(pszW);
- pszW = NULL;
- }
- }
-
- return pszW;
-
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CAboutDlg dialog used for App About
-
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- //{{AFX_DATA_INIT(CAboutDlg)
- //}}AFX_DATA_INIT
- }
-
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAboutDlg)
- //}}AFX_DATA_MAP
- }
-
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- //{{AFX_MSG_MAP(CAboutDlg)
- // No message handlers
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CSCPlayerDlg dialog
-
- CSCPlayerDlg::CSCPlayerDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CSCPlayerDlg::IDD, pParent),m_flagMoveSlider(TRUE),m_fStep(1)
- {
- //{{AFX_DATA_INIT(CSCPlayerDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
-
- void CSCPlayerDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CSCPlayerDlg)
- DDX_Control(pDX, IDC_WMPLAYER, theApp.m_mWMPlayer);
- //}}AFX_DATA_MAP
- }
-
- BEGIN_MESSAGE_MAP(CSCPlayerDlg, CDialog)
- //{{AFX_MSG_MAP(CSCPlayerDlg)
- ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER, OnReleasedcaptureSlider)
- ON_WM_TIMER()
- ON_WM_SIZE()
- ON_WM_LBUTTONDOWN()
- ON_WM_LBUTTONUP()
- ON_WM_MOUSEMOVE()
- ON_WM_HSCROLL()
- ON_WM_CLOSE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CSCPlayerDlg message handlers
-
- BOOL CSCPlayerDlg::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);
- theApp.m_pSkin->SetCustomSkinWnd((long)GetDlgItem(IDC_SLIDER)->m_hWnd,"PlayerSlider",FALSE);
-
- CDialog::OnInitDialog();
-
- SetWindowText("");
-
- CRect r;
- GetWindowRect(&r);
- r.bottom+=1;
- MoveWindow(&r);
-
- r.bottom-=40;
- GetClientRect(&r);
-
- ((CSliderCtrl*)GetDlgItem(IDC_SLIDER))->SetPageSize(5);
-
- return TRUE; // return TRUE unless you set the focus to a control
- }
-
- // 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 CSCPlayerDlg::OnPaint()
- {
-
- }
-
- // The system calls this to obtain the cursor to display while the user drags
- // the minimized window.
- HCURSOR CSCPlayerDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
-
- void CSCPlayerDlg::OnPlay()
- {
- // pPl->PlayFile();
- static BOOL flag = TRUE;
- if(flag)
- {
- SetTimer(111,10,0);
- flag=FALSE;
- }
-
- theApp.m_mWMPlayer.SetRedraw(FALSE);
- theApp.m_mWMPlayer.GetControls().play();
- theApp.m_mWMPlayer.SetRedraw(TRUE);
- }
-
- void CSCPlayerDlg::OnPause()
- {
- theApp.m_mWMPlayer.SetRedraw(FALSE);
- theApp.m_mWMPlayer.GetControls().pause();
- theApp.m_mWMPlayer.SetRedraw(TRUE);
- }
-
- void CSCPlayerDlg::OnStop()
- {
- KillTimer(111);
- theApp.m_mWMPlayer.SetRedraw(FALSE);
- theApp.m_mWMPlayer.GetControls().stop();
- theApp.m_mWMPlayer.SetRedraw(TRUE);
- }
-
- BEGIN_EVENTSINK_MAP(CSCPlayerDlg, CDialog)
- //{{AFX_EVENTSINK_MAP(CSCPlayerDlg)
- ON_EVENT(CSCPlayerDlg, IDC_WMPLAYER, 5001 /* OpenStateChange */, OnOpenStateChangeWmplayer, VTS_I4)
- //}}AFX_EVENTSINK_MAP
- END_EVENTSINK_MAP()
-
- void CSCPlayerDlg::OnOpenStateChangeWmplayer(long NewState)
- {
- // TODO: Add your control notification handler code here
- switch(NewState) {
- case 13://Media is open
- {
- double a = theApp.m_mWMPlayer.GetCurrentMedia().GetDuration();
- ((CSliderCtrl*)GetDlgItem(IDC_SLIDER))->SetRange(0,100);
- m_fStep = a/100;
- }
- }
-
- }
-
- LRESULT CSCPlayerDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
- {
- return CDialog::WindowProc(message, wParam, lParam);
- }
-
- BOOL CSCPlayerDlg::PreTranslateMessage(MSG* pMsg)
- {
- switch(pMsg->message)
- {
- case WM_KEYDOWN:
- {
- switch(pMsg->wParam)
- {
- case 70://F full screen
- {
- CWMPMedia me = theApp.m_mWMPlayer.GetCurrentMedia();
- if(me.m_lpDispatch==NULL)
- break;
- theApp.m_mWMPlayer.SetFullScreen(!theApp.m_mWMPlayer.GetFullScreen());
- theApp.m_mWMPlayer.Invalidate();
- break;
- }
- case 90://Z previous file
- {
- break;
- }
- case 88://X play
- {
- OnPlay();
- break;
- }
- case 67://C pause
- {
- OnPause();
- break;
- }
- case 86://V stop
- {
- OnStop();
- break;
- }
- case 66://B next
- {
-
- break;
- }
- }
- break;
- }
- }
- return CDialog::PreTranslateMessage(pMsg);
- }
-
- void CSCPlayerDlg::OnReleasedcaptureSlider(NMHDR* pNMHDR, LRESULT* pResult)
- {
-
- m_flagMoveSlider=TRUE;
- *pResult = 0;
- }
-
- void CSCPlayerDlg::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(m_flagMoveSlider)
- {
- ((CSliderCtrl*)GetDlgItem(IDC_SLIDER))->SetPos(pos/m_fStep);
- if(floor(pos*100) == floor(dur*100) && dur)
- KillTimer(111);
- }
- }
- break;
- }
-
- CDialog::OnTimer(nIDEvent);
- }
-
- void CSCPlayerDlg::OnSize(UINT nType, int cx, int cy)
- {
- CDialog::OnSize(nType, cx, cy);
-
- if(theApp.m_mWMPlayer.m_hWnd != 0)
- {
- theApp.m_mWMPlayer.SetRedraw(FALSE);
- CRect r;
- GetWindowRect(&r);
- theApp.m_mWMPlayer.MoveWindow(CRect(0,0,cx,cy-12));
- theApp.m_mWMPlayer.SetRedraw(TRUE);
-
- GetDlgItem(IDC_SLIDER)->MoveWindow(CRect(0,cy-12,cx,cy));
-
- if (theApp.m_mWMPlayer.GetControls().GetCurrentPosition()!=0)
- {
- r.top=r.bottom-12;
- }
- }
- }
-
- void CSCPlayerDlg::OnLButtonDown(UINT nFlags, CPoint point)
- {
- m_ptMouse = point;
- CDialog::OnLButtonDown(nFlags, point);
- }
- void CSCPlayerDlg::OnMouseMove(UINT nFlags, CPoint point)
- {
- if(nFlags&MK_LBUTTON)
- {
- CRect r;
- GetWindowRect(&r);
- r.OffsetRect(point - m_ptMouse);
- MoveWindow(&r);
- }
-
- CDialog::OnMouseMove(nFlags, point);
- }
-
- void CSCPlayerDlg::OnLButtonUp(UINT nFlags, CPoint point)
- {
-
- CDialog::OnLButtonUp(nFlags, point);
- }
-
- void CSCPlayerDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- int minpos;
- int maxpos;
- CSliderCtrl* pSlider = ((CSliderCtrl*)GetDlgItem(IDC_SLIDER));
- pSlider->GetRange(minpos, maxpos);
- int curpos = pSlider->GetPos();
-
- 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);
-
- if (floor(theApp.m_mWMPlayer.GetControls().GetCurrentPosition()) != floor(curpos*m_fStep))
- {
- theApp.m_mWMPlayer.GetControls().SetCurrentPosition(curpos*m_fStep);
- }
- CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
- }
-
- void CSCPlayerDlg::OnClose()
- {
- OnStop();
- ShowWindow(SW_HIDE);
- }
-