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

  1. // CPlayerControlDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "SCPlayer.h"
  6. #include "PlayerControlDlg.h"
  7. #include "PlayListDlg.h"
  8. #include "math.h"
  9. #include "wmpsettings.h"
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CPlayerControlDlg dialog
  18.  
  19.  
  20. CPlayerControlDlg::CPlayerControlDlg(CWnd* pParent /*=NULL*/)
  21.     : CDialog(CPlayerControlDlg::IDD, pParent),m_bIsMoved(FALSE)
  22. {
  23.     //{{AFX_DATA_INIT(CPlayerControlDlg)
  24.     //}}AFX_DATA_INIT
  25. }
  26.  
  27.  
  28. void CPlayerControlDlg::DoDataExchange(CDataExchange* pDX)
  29. {
  30.     CDialog::DoDataExchange(pDX);
  31.     //{{AFX_DATA_MAP(CPlayerControlDlg)
  32.     //DDX_Text(pDX, IDC_CURFILE, m_strCurFile);
  33.     DDX_Text(pDX, IDC_CURTIME, m_strCurTime);
  34.     //}}AFX_DATA_MAP
  35. }
  36.  
  37.  
  38. BEGIN_MESSAGE_MAP(CPlayerControlDlg, CDialog)
  39.     //{{AFX_MSG_MAP(CPlayerControlDlg)
  40.     ON_BN_CLICKED(IDC_PLAYBUT, OnPlaybut)
  41.     ON_BN_CLICKED(IDC_PLAYLIST, OnPlaylist)
  42.     ON_BN_CLICKED(IDC_OPENFILE, OnOpenfile)
  43.     ON_BN_CLICKED(IDC_STOPBUT, OnStopbut)
  44.     ON_BN_CLICKED(IDC_PAUSEBUT, OnPausebut)
  45.     ON_BN_CLICKED(IDC_NEXTBUT, OnNextbut)
  46.     ON_BN_CLICKED(IDC_PREVBUT, OnPrevbut)
  47.     ON_WM_CLOSE()
  48.     ON_WM_LBUTTONDOWN()
  49.     ON_WM_LBUTTONUP()
  50.     ON_WM_MOUSEMOVE()
  51.     ON_WM_HSCROLL()
  52.     ON_BN_CLICKED(IDC_AMEGA_BUTTON, OnAmegaButton)
  53.     ON_WM_TIMER()
  54.     ON_WM_RBUTTONDOWN()
  55.     //}}AFX_MSG_MAP
  56. END_MESSAGE_MAP()
  57.  
  58. /////////////////////////////////////////////////////////////////////////////
  59. // CPlayerControlDlg message handlers
  60.  
  61. void CPlayerControlDlg::OnPlaylist() 
  62. {
  63.     if (!theApp.m_pPlayListDlg)
  64.     {
  65.         theApp.m_pPlayListDlg = new CPlayListDlg;
  66.         theApp.m_pPlayListDlg->Create(IDD_PLAYLIST,this);
  67.         theApp.m_pPlayListDlg->ShowWindow(SW_SHOW);
  68.     }
  69.     else
  70.     {
  71.         if (theApp.m_pPlayListDlg->IsWindowVisible())
  72.         {
  73.             theApp.m_pPlayListDlg->ShowWindow(SW_HIDE);
  74.         }
  75.         else
  76.             theApp.m_pPlayListDlg->ShowWindow(SW_SHOW);
  77.     }
  78. }
  79.  
  80. void CPlayerControlDlg::OnPlaybut() 
  81. {
  82.     SetTimer(111,10,0);
  83.     EnsurePlayerIsReady();
  84.     theApp.m_mWMPlayer.SetRedraw(FALSE);
  85.     theApp.m_mWMPlayer.GetControls().play();
  86.     theApp.m_mWMPlayer.SetRedraw(TRUE);
  87.     
  88. }
  89.  
  90. void CPlayerControlDlg::OnOpenfile() 
  91. {
  92.     CFileDialog dlg(TRUE);
  93.     
  94.     if(dlg.DoModal() == IDOK)
  95.     {
  96.         EnsurePlayerIsReady();
  97.         SetTimer(111,10,0);
  98.         CString path = dlg.GetPathName();
  99.         PlayNew(path);
  100.         m_strCurMediaName = theApp.m_mWMPlayer.GetCurrentMedia().GetName(); 
  101.         theApp.m_pPlayListDlg->AddFile(path);
  102.         theApp.m_pPlayListDlg->FillPlayList();
  103.     }
  104.     
  105. }
  106.  
  107. void CPlayerControlDlg::OnStopbut() 
  108. {
  109.     KillTimer(111);
  110.     EnsurePlayerIsReady();
  111.     theApp.m_mWMPlayer.SetRedraw(FALSE);
  112.     theApp.m_mWMPlayer.GetControls().stop();
  113.     theApp.m_mWMPlayer.SetRedraw(TRUE);    
  114.     m_strCurMediaName = "";
  115. }
  116.  
  117. void CPlayerControlDlg::OnPausebut() 
  118. {
  119.     EnsurePlayerIsReady();
  120.     theApp.m_mWMPlayer.SetRedraw(FALSE);
  121.     theApp.m_mWMPlayer.GetControls().pause();
  122.     theApp.m_mWMPlayer.SetRedraw(TRUE);    
  123. }
  124.  
  125. void CPlayerControlDlg::OnNextbut() 
  126. {
  127.     CString str = theApp.m_pPlayListDlg->GetNextMediaPath();
  128.     CWMPMedia me = theApp.m_mWMPlayer.newMedia(str);
  129.     theApp.m_pSCPlayerDlg->SetFocus();
  130.     theApp.m_mWMPlayer.SetCurrentMedia(me.operator LPDISPATCH());
  131.     SetFocus();
  132. }
  133.  
  134. void CPlayerControlDlg::OnPrevbut() 
  135. {
  136.     OnStopbut();
  137.     CString str = theApp.m_pPlayListDlg->GetPrevMediaPath();
  138.     CWMPMedia me = theApp.m_mWMPlayer.newMedia(str);
  139.     theApp.m_pSCPlayerDlg->SetFocus();
  140.     theApp.m_mWMPlayer.SetCurrentMedia(me.operator LPDISPATCH());
  141.     SetFocus();
  142. }
  143. void CPlayerControlDlg::OnTimer(UINT nIDEvent) 
  144. {
  145.     switch(nIDEvent) {
  146.     case 111://Timer for displaying the current position
  147.         {
  148.             if(!theApp.m_mWMPlayer.m_hWnd)
  149.             {
  150.                 KillTimer(111);
  151.                 break;
  152.             }
  153.             double pos = theApp.m_mWMPlayer.GetControls().GetCurrentPosition();
  154.             double dur = theApp.m_mWMPlayer.GetCurrentMedia().GetDuration();
  155.             if(theApp.m_pSCPlayerDlg->m_flagMoveSlider)
  156.             {
  157.                 ((CSliderCtrl*)theApp.m_pSCPlayerDlg->GetDlgItem(IDC_SLIDER))->SetPos(pos/(dur)*100);
  158.                 if(floor(pos*100) == floor(dur*100) && dur)
  159.                     KillTimer(111);
  160.             }
  161.             CString strTime;
  162.             strTime.Format("Current / Total time: %s --- %s",theApp.m_mWMPlayer.GetControls().GetCurrentPositionString(),theApp.m_mWMPlayer.GetCurrentMedia().GetDurationString());
  163.             m_strCurTime=strTime;
  164.             UpdateData(FALSE);
  165.         }
  166.         break;
  167.     }
  168.     
  169.     CDialog::OnTimer(nIDEvent);
  170. }
  171.  
  172.  
  173. void CPlayerControlDlg::EnsurePlayerIsReady()
  174. {
  175.     if (!theApp.m_pSCPlayerDlg)
  176.     {
  177.         theApp.m_pSCPlayerDlg = new CSCPlayerDlg;
  178.         theApp.m_pSCPlayerDlg->Create(IDD_SCPLAYER_DIALOG,this);
  179.         theApp.m_pSCPlayerDlg->ShowWindow(SW_SHOW);
  180.         theApp.m_pthePlayList = new CWMPPlaylist;
  181.     }
  182.     else if(!theApp.m_pSCPlayerDlg->IsWindowVisible())
  183.     {
  184.         theApp.m_pSCPlayerDlg->ShowWindow(SW_SHOW);
  185.     }
  186. }
  187.  
  188. void CPlayerControlDlg::OnClose() 
  189. {
  190.     KillTimer(111);
  191.     CDialog::OnClose();
  192. }
  193.  
  194. BOOL CPlayerControlDlg::OnInitDialog() 
  195. {
  196.     m_ToolTip.Create(this);
  197.     m_ToolTip.SetDelayTime(0);
  198.     m_ToolTip.SetMaxTipWidth(300);
  199.  
  200.     CRect r;
  201.     GetDlgItem(IDC_AMEGA_BUTTON)->GetWindowRect(&r);
  202.     m_ToolTip.AddTool(GetDlgItem(IDC_AMEGA_BUTTON),IDS_TOOLTIP);
  203.     theApp.m_pSkin->IncludeWnd((long)m_hWnd,TRUE);
  204.     
  205.     //Do it only to have a button name in dialog editor
  206.     GetDlgItem(IDC_PLAYBUT)->SetWindowText("");
  207.     theApp.m_pSkin->SetCustomSkinWnd((long)GetDlgItem(IDC_PLAYBUT)->m_hWnd,"PlayButton",FALSE);
  208.  
  209.     //Do it only to have a button name in dialog editor
  210.     GetDlgItem(IDC_STOPBUT)->SetWindowText("");
  211.     theApp.m_pSkin->SetCustomSkinWnd((long)GetDlgItem(IDC_STOPBUT)->m_hWnd,"StopButton",FALSE);
  212.  
  213.     //Do it only to have a button name in dialog editor
  214.     GetDlgItem(IDC_PAUSEBUT)->SetWindowText("");
  215.     theApp.m_pSkin->SetCustomSkinWnd((long)GetDlgItem(IDC_PAUSEBUT)->m_hWnd,"PauseButton",FALSE);
  216.  
  217.     //Do it only to have a button name in dialog editor
  218.     GetDlgItem(IDC_PREVBUT)->SetWindowText("");
  219.     theApp.m_pSkin->SetCustomSkinWnd((long)GetDlgItem(IDC_PREVBUT)->m_hWnd,"PrevButton",FALSE);
  220.  
  221.         //Do it only to have a button name in dialog editor
  222.     GetDlgItem(IDC_NEXTBUT)->SetWindowText("");
  223.     theApp.m_pSkin->SetCustomSkinWnd((long)GetDlgItem(IDC_NEXTBUT)->m_hWnd,"NextButton",FALSE);
  224.     
  225.     GetDlgItem(IDC_OPENFILE)->SetWindowText("");
  226.     theApp.m_pSkin->SetCustomSkinWnd((long)GetDlgItem(IDC_OPENFILE)->m_hWnd,"OpenButton",FALSE);
  227.     
  228.     GetDlgItem(IDC_PLAYLIST)->SetWindowText("");
  229.     theApp.m_pSkin->SetCustomSkinWnd((long)GetDlgItem(IDC_PLAYLIST)->m_hWnd,"PlayListButton",FALSE);
  230.  
  231.     theApp.m_pSkin->SetCustomSkinWnd((long)GetDlgItem(IDC_VOLUME)->m_hWnd,"CustomSliders",FALSE);
  232.  
  233.     theApp.m_pSkin->SetCustomSkinWnd((long)m_hWnd,"ControlsFrame",TRUE);
  234.     theApp.m_pSkin->SetCustomSkinWnd((long)m_hWnd,"ControlsDialog",FALSE);
  235.     
  236.     GetDlgItem(IDC_AMEGA_BUTTON)->SetWindowText("");
  237.     theApp.m_pSkin->SetCustomSkinWnd((long)GetDlgItem(IDC_AMEGA_BUTTON)->m_hWnd,"AmegaButton",FALSE);
  238.     
  239.     OnPlaylist();
  240.     CDialog::OnInitDialog();
  241.  
  242.     GetDlgItem(IDC_CURFILE)->SetWindowText("");
  243.     GetDlgItem(IDC_CURTIME)->SetWindowText("");
  244.     
  245.     GetWindowRect(&r);
  246.  
  247.     SetWindowPos(NULL,100,100,r.Width(),r.Height(),SWP_NOSIZE|SWP_SHOWWINDOW);
  248.     int width = r.Height()+100;
  249.     theApp.m_pPlayListDlg->GetWindowRect(&r);
  250.     theApp.m_pPlayListDlg->SetWindowPos(NULL,100,width,r.Width(),r.Height(),SWP_NOSIZE|SWP_SHOWWINDOW);
  251.  
  252.     CSliderCtrl* pVolume = (CSliderCtrl*)GetDlgItem(IDC_VOLUME);
  253.     pVolume->SetRange(0,100);
  254.     pVolume->SetPos(50);
  255.  
  256.     return TRUE;  // return TRUE unless you set the focus to a control
  257.                   // EXCEPTION: OCX Property Pages should return FALSE
  258. }
  259.  
  260.  
  261. void CPlayerControlDlg::PlayNew(CString path)
  262. {
  263.     if(path.IsEmpty())
  264.     {
  265.         path = theApp.m_pPlayListDlg->GetCurMediaPath();
  266.     }
  267.     EnsurePlayerIsReady();
  268.     KillTimer(111);
  269.     SetTimer(111,10,0);
  270.     CWMPMedia me = theApp.m_mWMPlayer.newMedia(path);
  271.     theApp.m_mWMPlayer.SetCurrentMedia(me.operator LPDISPATCH());
  272.     GetDlgItem(IDC_CURFILE)->SetWindowText(me.GetName());
  273. }
  274.  
  275.  
  276. void CPlayerControlDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
  277. {
  278.     int minpos;
  279.     int maxpos;
  280.     CSliderCtrl* pSlider = ((CSliderCtrl*)GetDlgItem(IDC_VOLUME));
  281.     pSlider->GetRange(minpos, maxpos);
  282.     int curpos = pSlider->GetPos();
  283.  
  284.     if(!theApp.m_pSCPlayerDlg)
  285.         return;
  286.     
  287.     switch(nSBCode) 
  288.     {
  289.     case SB_THUMBPOSITION:
  290.     case SB_THUMBTRACK:
  291.         {
  292.             //m_flagMoveSlider=FALSE;
  293.             if(theApp.m_mWMPlayer.GetCurrentMedia())
  294.             {
  295.                 curpos=nPos;    
  296.             }
  297.         }
  298.         break;
  299.     case SB_LEFT:      // Scroll to far left.
  300.           curpos = minpos;
  301.           break;
  302.  
  303.     case SB_RIGHT:      // Scroll to far right.
  304.           curpos = maxpos;
  305.           break;
  306.  
  307.     case SB_ENDSCROLL:   // End scroll.
  308.           break;
  309.  
  310.     case SB_LINELEFT:      // Scroll left.
  311.           if (curpos > minpos)
  312.              curpos--;
  313.           break;
  314.  
  315.     case SB_LINERIGHT:   // Scroll right.
  316.           if (curpos < maxpos)
  317.              curpos++;
  318.           break;
  319.  
  320.     case SB_PAGELEFT:    // Scroll one page left.
  321.         {
  322.           if (curpos > minpos)
  323.           curpos = max(minpos, curpos - (int)pSlider->GetPageSize());
  324.         }
  325.           break;
  326.  
  327.     case SB_PAGERIGHT:      // Scroll one page right.
  328.         {
  329.           if (curpos < maxpos)
  330.              curpos = min(maxpos, curpos + (int) pSlider->GetPageSize());
  331.         }
  332.         break;
  333.     default:
  334.         return;
  335.     }
  336.     pSlider->SetPos(curpos);
  337.  
  338.     
  339.     theApp.m_mWMPlayer.GetSettings().SetVolume(curpos);
  340.     
  341.     CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
  342. }
  343.  
  344. void CPlayerControlDlg::OnLButtonDown(UINT nFlags, CPoint point) 
  345. {
  346.     m_ptMouse = point;
  347.     SetCapture();
  348.     m_bIsMoved = TRUE;
  349.     
  350.     CDialog::OnLButtonDown(nFlags, point);
  351. }
  352. void CPlayerControlDlg::OnMouseMove(UINT nFlags, CPoint point)
  353. {
  354.     if(nFlags&MK_LBUTTON && GetCapture()==this && m_bIsMoved)
  355.     {        
  356.         CRect r;
  357.         GetWindowRect(&r);
  358.         r.OffsetRect(point - m_ptMouse);
  359.         MoveWindow(&r);
  360.     }
  361.  
  362.     CDialog::OnMouseMove(nFlags, point);
  363. }
  364.  
  365. void CPlayerControlDlg::OnLButtonUp(UINT nFlags, CPoint point) 
  366. {
  367.     
  368.     ReleaseCapture();
  369.     m_bIsMoved = FALSE;
  370.     CDialog::OnLButtonUp(nFlags, point);
  371. }
  372.  
  373. void CPlayerControlDlg::OnAmegaButton() 
  374. {
  375.     //LoadSkin();
  376.     static int index = 0;
  377.     static CString arr[] = {"PlayerSkin-BoomBox.skf", "PlayerSkin.skf"};
  378.     
  379.     FILE* f= fopen(arr[index] ,"r");
  380.     if(f)
  381.     {
  382.         fclose(f);
  383.         theApp.m_pSkin->LoadSkinFromFile(arr[index]);
  384.         theApp.m_pSkin->ApplySkin();
  385.     }
  386.     index = !index;
  387.     //    ::ShellExecute(0,"open","http://a-megastudio.com",0,0,0);
  388. }
  389.  
  390. void CPlayerControlDlg::OnRButtonDown(UINT nFlags, CPoint point) 
  391. {
  392.     CPoint pt(GetMessagePos());
  393.     CMenu popMenu;
  394.  
  395.     if ( !popMenu.LoadMenu(IDR_POPUP_MENU) )
  396.         AfxMessageBox("Cannot create menu");
  397.  
  398.     CMenu *pMenu = popMenu.GetSubMenu(0);
  399.  
  400.     UINT mID = pMenu->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON | TPM_RETURNCMD,pt.x,pt.y,this);
  401.     pMenu->DestroyMenu();
  402.  
  403.     switch(mID)
  404.     {
  405.     case ID_MENU_CHOOSESKIN:
  406.         {
  407.             LoadSkin();
  408.             break;
  409.         }
  410.     case ID_MENU_ABOUT:
  411.         {
  412.             CAboutDlg dlg;
  413.             dlg.DoModal();
  414.         }
  415.     }
  416.     CDialog::OnRButtonDown(nFlags, point);
  417. }
  418.  
  419. void CPlayerControlDlg::LoadSkin()
  420. {
  421.     CString Filter("SkinCrafter files (*.skf)|*.skf||");
  422.  
  423.     CFileDialog dlg(TRUE, "skf", NULL, NULL, Filter);
  424.     
  425.     dlg.m_ofn.lpstrTitle = "Select file";
  426.  
  427.     if(dlg.DoModal()==IDOK)
  428.     {
  429.         CString path = dlg.GetPathName();
  430.         theApp.m_pSkin->LoadSkinFromFile(path);
  431.         theApp.m_pSkin->ApplySkin();
  432.     }
  433. }
  434.  
  435. BOOL CPlayerControlDlg::PreTranslateMessage(MSG* pMsg) 
  436. {
  437.     // TODO: Add your specialized code here and/or call the base class
  438.     
  439.     m_ToolTip.RelayEvent(pMsg);
  440.  
  441.     return CDialog::PreTranslateMessage(pMsg);
  442. }
  443.