home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 November / CMCD1104.ISO / Software / Shareware / Programare / skincraft / SkinCrafter_v1.4.12_Demo.msi / _49E29CB9A65AABBF653C1037E1AA74B6 / _B3F4BD7B5D00454FBBAA29F0DE6AC41C < prev    next >
Encoding:
Text File  |  2004-03-18  |  8.9 KB  |  400 lines

  1. // SCPlayerDlg.cpp : implementation file
  2. //
  3.  
  4.  
  5. #include "stdafx.h"
  6. #include "SCPlayer.h"
  7. #include "SCPlayerDlg.h"
  8. #include "math.h"
  9. #include "wmpplaylist.h"
  10. #include "wmpmedia.h"
  11.  
  12. #ifdef _DEBUG
  13. #define new DEBUG_NEW
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17.  
  18. LPWSTR ProduceWFromA( UINT uiCodePage, LPCSTR psz ) 
  19. {
  20.     LPWSTR pszW;
  21.     int cch;
  22.  
  23.     if (psz == NULL || psz == LPSTR_TEXTCALLBACKA)
  24.         return (LPWSTR)psz;
  25.  
  26.     // The old code would call lstrlen and lstrcpy which would fault internal to the
  27.     // api, this should do about the same...
  28.     if (IsBadReadPtr(psz,1))
  29.         return NULL;    // For now lets try not setting a string...
  30.  
  31.     cch = MultiByteToWideChar(uiCodePage, 0, psz, -1, NULL, 0);
  32.  
  33.     if (cch == 0)
  34.         cch = 1;
  35.  
  36.     pszW = (LPWSTR)LocalAlloc( LMEM_FIXED, cch * sizeof(WCHAR) );
  37.  
  38.     if (pszW != NULL ) {
  39.          if (MultiByteToWideChar( uiCodePage, MB_PRECOMPOSED, psz, -1, pszW,
  40.                 cch ) == FALSE) {
  41.             LocalFree(pszW);
  42.             pszW = NULL;
  43.         }
  44.     }
  45.  
  46.     return pszW;
  47.  
  48. }
  49.  
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CAboutDlg dialog used for App About
  52.  
  53. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  54. {
  55.     //{{AFX_DATA_INIT(CAboutDlg)
  56.     //}}AFX_DATA_INIT
  57. }
  58.  
  59. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  60. {
  61.     CDialog::DoDataExchange(pDX);
  62.     //{{AFX_DATA_MAP(CAboutDlg)
  63.     //}}AFX_DATA_MAP
  64. }
  65.  
  66. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  67.     //{{AFX_MSG_MAP(CAboutDlg)
  68.         // No message handlers
  69.     //}}AFX_MSG_MAP
  70. END_MESSAGE_MAP()
  71.  
  72. /////////////////////////////////////////////////////////////////////////////
  73. // CSCPlayerDlg dialog
  74.  
  75. CSCPlayerDlg::CSCPlayerDlg(CWnd* pParent /*=NULL*/)
  76.     : CDialog(CSCPlayerDlg::IDD, pParent),m_flagMoveSlider(TRUE),m_fStep(1)
  77. {
  78.     //{{AFX_DATA_INIT(CSCPlayerDlg)
  79.         // NOTE: the ClassWizard will add member initialization here
  80.     //}}AFX_DATA_INIT
  81.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  82.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  83. }
  84.  
  85. void CSCPlayerDlg::DoDataExchange(CDataExchange* pDX)
  86. {
  87.     CDialog::DoDataExchange(pDX);
  88.     //{{AFX_DATA_MAP(CSCPlayerDlg)
  89.     DDX_Control(pDX, IDC_WMPLAYER, theApp.m_mWMPlayer);
  90.     //}}AFX_DATA_MAP
  91. }
  92.  
  93. BEGIN_MESSAGE_MAP(CSCPlayerDlg, CDialog)
  94.     //{{AFX_MSG_MAP(CSCPlayerDlg)
  95.     ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER, OnReleasedcaptureSlider)
  96.     ON_WM_TIMER()
  97.     ON_WM_SIZE()
  98.     ON_WM_LBUTTONDOWN()
  99.     ON_WM_LBUTTONUP()
  100.     ON_WM_MOUSEMOVE()
  101.     ON_WM_HSCROLL()
  102.     ON_WM_CLOSE()
  103.     //}}AFX_MSG_MAP
  104. END_MESSAGE_MAP()
  105.  
  106. /////////////////////////////////////////////////////////////////////////////
  107. // CSCPlayerDlg message handlers
  108.  
  109. BOOL CSCPlayerDlg::OnInitDialog()
  110. {
  111.     theApp.m_pSkin->IncludeWnd((long)m_hWnd,TRUE);
  112.     theApp.m_pSkin->SetCustomSkinWnd((long)m_hWnd,"PlayerFrame",TRUE);
  113.     theApp.m_pSkin->SetCustomSkinWnd((long)m_hWnd,"PlayListDialog",FALSE);
  114.     theApp.m_pSkin->SetCustomSkinWnd((long)GetDlgItem(IDC_SLIDER)->m_hWnd,"PlayerSlider",FALSE);
  115.  
  116.     CDialog::OnInitDialog();
  117.  
  118.     SetWindowText("");
  119.  
  120.     CRect r;
  121.     GetWindowRect(&r);
  122.     r.bottom+=1;
  123.     MoveWindow(&r);
  124.  
  125.     r.bottom-=40;
  126.     GetClientRect(&r);
  127.     
  128.     ((CSliderCtrl*)GetDlgItem(IDC_SLIDER))->SetPageSize(5);
  129.     
  130.     return TRUE;  // return TRUE  unless you set the focus to a control
  131. }
  132.  
  133. // If you add a minimize button to your dialog, you will need the code below
  134. //  to draw the icon.  For MFC applications using the document/view model,
  135. //  this is automatically done for you by the framework.
  136.  
  137. void CSCPlayerDlg::OnPaint() 
  138. {
  139.  
  140. }
  141.  
  142. // The system calls this to obtain the cursor to display while the user drags
  143. //  the minimized window.
  144. HCURSOR CSCPlayerDlg::OnQueryDragIcon()
  145. {
  146.     return (HCURSOR) m_hIcon;
  147. }
  148.  
  149. void CSCPlayerDlg::OnPlay() 
  150. {
  151. //    pPl->PlayFile();
  152.     static BOOL flag = TRUE;
  153.     if(flag)
  154.     {
  155.         SetTimer(111,10,0);
  156.         flag=FALSE;
  157.     }
  158.  
  159.     theApp.m_mWMPlayer.SetRedraw(FALSE);
  160.     theApp.m_mWMPlayer.GetControls().play();
  161.     theApp.m_mWMPlayer.SetRedraw(TRUE);
  162. }
  163.  
  164. void CSCPlayerDlg::OnPause() 
  165. {
  166.     theApp.m_mWMPlayer.SetRedraw(FALSE);
  167.     theApp.m_mWMPlayer.GetControls().pause();
  168.     theApp.m_mWMPlayer.SetRedraw(TRUE);
  169. }
  170.  
  171. void CSCPlayerDlg::OnStop() 
  172. {
  173.     KillTimer(111);
  174.     theApp.m_mWMPlayer.SetRedraw(FALSE);
  175.     theApp.m_mWMPlayer.GetControls().stop();
  176.     theApp.m_mWMPlayer.SetRedraw(TRUE);
  177. }
  178.  
  179. BEGIN_EVENTSINK_MAP(CSCPlayerDlg, CDialog)
  180.     //{{AFX_EVENTSINK_MAP(CSCPlayerDlg)
  181.     ON_EVENT(CSCPlayerDlg, IDC_WMPLAYER, 5001 /* OpenStateChange */, OnOpenStateChangeWmplayer, VTS_I4)
  182.     //}}AFX_EVENTSINK_MAP
  183. END_EVENTSINK_MAP()
  184.  
  185. void CSCPlayerDlg::OnOpenStateChangeWmplayer(long NewState) 
  186. {
  187.     // TODO: Add your control notification handler code here
  188.     switch(NewState) {
  189.     case 13://Media is open
  190.         {
  191.             double a = theApp.m_mWMPlayer.GetCurrentMedia().GetDuration();
  192.             ((CSliderCtrl*)GetDlgItem(IDC_SLIDER))->SetRange(0,100);
  193.             m_fStep = a/100;
  194.         }
  195.     }
  196.     
  197. }
  198.  
  199. LRESULT CSCPlayerDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
  200. {
  201.     return CDialog::WindowProc(message, wParam, lParam);
  202. }
  203.  
  204. BOOL CSCPlayerDlg::PreTranslateMessage(MSG* pMsg) 
  205. {
  206.     switch(pMsg->message) 
  207.     {
  208.         case WM_KEYDOWN:
  209.         {
  210.             switch(pMsg->wParam) 
  211.             {
  212.                 case 70://F full screen
  213.                     {
  214.                         CWMPMedia me = theApp.m_mWMPlayer.GetCurrentMedia();
  215.                         if(me.m_lpDispatch==NULL)
  216.                             break;
  217.                         theApp.m_mWMPlayer.SetFullScreen(!theApp.m_mWMPlayer.GetFullScreen());
  218.                         theApp.m_mWMPlayer.Invalidate();
  219.                         break;
  220.                     }
  221.                 case 90://Z previous file
  222.                     {
  223.                         break;
  224.                     }
  225.                 case 88://X play
  226.                     {
  227.                         OnPlay();
  228.                         break;
  229.                     }
  230.                 case 67://C pause
  231.                     {
  232.                         OnPause();
  233.                         break;
  234.                     }
  235.                 case 86://V stop
  236.                     {
  237.                         OnStop();
  238.                         break;
  239.                     }
  240.                 case 66://B next
  241.                     {
  242.                         
  243.                         break;
  244.                     }
  245.                 }
  246.             break;
  247.         }
  248.     }
  249.     return CDialog::PreTranslateMessage(pMsg);
  250. }
  251.  
  252. void CSCPlayerDlg::OnReleasedcaptureSlider(NMHDR* pNMHDR, LRESULT* pResult) 
  253. {
  254.     
  255.     m_flagMoveSlider=TRUE;
  256.     *pResult = 0;
  257. }
  258.  
  259. void CSCPlayerDlg::OnTimer(UINT nIDEvent) 
  260. {
  261.     switch(nIDEvent) {
  262.     case 111://Timer for displaying the current position
  263.         {
  264.             if(!theApp.m_mWMPlayer.m_hWnd)
  265.             {
  266.                 KillTimer(111);
  267.                 break;
  268.             }
  269.             double pos = theApp.m_mWMPlayer.GetControls().GetCurrentPosition();
  270.             double dur = theApp.m_mWMPlayer.GetCurrentMedia().GetDuration();
  271.             if(m_flagMoveSlider)
  272.             {
  273.                 ((CSliderCtrl*)GetDlgItem(IDC_SLIDER))->SetPos(pos/m_fStep);
  274.                 if(floor(pos*100) == floor(dur*100) && dur)
  275.                     KillTimer(111);
  276.             }
  277.         }
  278.         break;
  279.     }
  280.     
  281.     CDialog::OnTimer(nIDEvent);
  282. }
  283.  
  284. void CSCPlayerDlg::OnSize(UINT nType, int cx, int cy) 
  285. {
  286.     CDialog::OnSize(nType, cx, cy);
  287.     
  288.     if(theApp.m_mWMPlayer.m_hWnd != 0)
  289.     {
  290.         theApp.m_mWMPlayer.SetRedraw(FALSE);
  291.         CRect r;
  292.         GetWindowRect(&r);
  293.         theApp.m_mWMPlayer.MoveWindow(CRect(0,0,cx,cy-12));
  294.         theApp.m_mWMPlayer.SetRedraw(TRUE);
  295.         
  296.         GetDlgItem(IDC_SLIDER)->MoveWindow(CRect(0,cy-12,cx,cy));
  297.         
  298.         if (theApp.m_mWMPlayer.GetControls().GetCurrentPosition()!=0)
  299.         {
  300.             r.top=r.bottom-12;
  301.         }
  302.     }
  303. }
  304.  
  305. void CSCPlayerDlg::OnLButtonDown(UINT nFlags, CPoint point) 
  306. {
  307.     m_ptMouse = point;    
  308.     CDialog::OnLButtonDown(nFlags, point);
  309. }
  310. void CSCPlayerDlg::OnMouseMove(UINT nFlags, CPoint point)
  311. {
  312.     if(nFlags&MK_LBUTTON)
  313.     {
  314.         CRect r;
  315.         GetWindowRect(&r);
  316.         r.OffsetRect(point - m_ptMouse);
  317.         MoveWindow(&r);
  318.     }
  319.  
  320.     CDialog::OnMouseMove(nFlags, point);
  321. }
  322.  
  323. void CSCPlayerDlg::OnLButtonUp(UINT nFlags, CPoint point) 
  324. {
  325.     
  326.     CDialog::OnLButtonUp(nFlags, point);
  327. }
  328.  
  329. void CSCPlayerDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
  330. {
  331.     int minpos;
  332.     int maxpos;
  333.     CSliderCtrl* pSlider = ((CSliderCtrl*)GetDlgItem(IDC_SLIDER));
  334.     pSlider->GetRange(minpos, maxpos);
  335.     int curpos = pSlider->GetPos();
  336.  
  337.     switch(nSBCode ) 
  338.     {
  339.     case SB_THUMBPOSITION:
  340.     case SB_THUMBTRACK:
  341.         {
  342.             m_flagMoveSlider=FALSE;
  343.             if(theApp.m_mWMPlayer.GetCurrentMedia())
  344.             {
  345.                 curpos=nPos;    
  346.             }
  347.         }
  348.         break;
  349.     case SB_LEFT:      // Scroll to far left.
  350.           curpos = minpos;
  351.           break;
  352.  
  353.     case SB_RIGHT:      // Scroll to far right.
  354.           curpos = maxpos;
  355.           break;
  356.  
  357.     case SB_ENDSCROLL:   // End scroll.
  358.           break;
  359.  
  360.     case SB_LINELEFT:      // Scroll left.
  361.           if (curpos > minpos)
  362.              curpos--;
  363.           break;
  364.  
  365.     case SB_LINERIGHT:   // Scroll right.
  366.           if (curpos < maxpos)
  367.              curpos++;
  368.           break;
  369.  
  370.     case SB_PAGELEFT:    // Scroll one page left.
  371.         {
  372.           if (curpos > minpos)
  373.           curpos = max(minpos, curpos - (int)pSlider->GetPageSize());
  374.         }
  375.           break;
  376.  
  377.     case SB_PAGERIGHT:      // Scroll one page right.
  378.         {
  379.           if (curpos < maxpos)
  380.              curpos = min(maxpos, curpos + (int) pSlider->GetPageSize());
  381.         }
  382.         break;
  383.     default:
  384.         return;
  385.     }
  386.     pSlider->SetPos(curpos);
  387.  
  388.     if (floor(theApp.m_mWMPlayer.GetControls().GetCurrentPosition()) != floor(curpos*m_fStep)) 
  389.     {
  390.         theApp.m_mWMPlayer.GetControls().SetCurrentPosition(curpos*m_fStep);
  391.     }
  392.     CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
  393. }
  394.  
  395. void CSCPlayerDlg::OnClose()
  396. {
  397.     OnStop();
  398.     ShowWindow(SW_HIDE);
  399. }
  400.