PlayerToolBar.cpp
上传用户:xjjlds
上传日期:2015-12-05
资源大小:22823k
文件大小:6k
源码类别:

多媒体编程

开发平台:

Visual C++

  1. /* 
  2.  * Copyright (C) 2003-2005 Gabest
  3.  * http://www.gabest.org
  4.  *
  5.  *  This Program is free software; you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation; either version 2, or (at your option)
  8.  *  any later version.
  9.  *   
  10.  *  This Program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13.  *  GNU General Public License for more details.
  14.  *   
  15.  *  You should have received a copy of the GNU General Public License
  16.  *  along with GNU Make; see the file COPYING.  If not, write to
  17.  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  18.  *  http://www.gnu.org/copyleft/gpl.html
  19.  *
  20.  */
  21. // PlayerToolBar.cpp : implementation file
  22. //
  23. #include "stdafx.h"
  24. #include "mplayerc.h"
  25. #include <math.h>
  26. #include <atlbase.h>
  27. #include <afxpriv.h>
  28. #include "PlayerToolBar.h"
  29. #include "MainFrm.h"
  30. typedef HRESULT (__stdcall * SetWindowThemeFunct)(HWND hwnd, LPCWSTR pszSubAppName, LPCWSTR pszSubIdList);
  31. // CPlayerToolBar
  32. IMPLEMENT_DYNAMIC(CPlayerToolBar, CToolBar)
  33. CPlayerToolBar::CPlayerToolBar()
  34. {
  35. }
  36. CPlayerToolBar::~CPlayerToolBar()
  37. {
  38. }
  39. BOOL CPlayerToolBar::Create(CWnd* pParentWnd)
  40. {
  41. if(!__super::CreateEx(pParentWnd,
  42. TBSTYLE_FLAT|TBSTYLE_TRANSPARENT|TBSTYLE_AUTOSIZE,
  43. WS_CHILD|WS_VISIBLE|CBRS_ALIGN_BOTTOM|CBRS_TOOLTIPS, CRect(2,2,0,3)) 
  44. || !LoadToolBar(ID_PLAYERTOOLBAR))
  45. return FALSE;
  46. GetToolBarCtrl().SetExtendedStyle(TBSTYLE_EX_DRAWDDARROWS);
  47. CToolBarCtrl& tb = GetToolBarCtrl();
  48. tb.DeleteButton(tb.GetButtonCount()-1);
  49. tb.DeleteButton(tb.GetButtonCount()-1);
  50. SetMute(AfxGetAppSettings().fMute);
  51. UINT styles[] = 
  52. {
  53. TBBS_CHECKGROUP, TBBS_CHECKGROUP, TBBS_CHECKGROUP, 
  54. TBBS_SEPARATOR,
  55. TBBS_BUTTON, TBBS_BUTTON, TBBS_BUTTON, TBBS_BUTTON, 
  56. TBBS_SEPARATOR,
  57. TBBS_BUTTON/*|TBSTYLE_DROPDOWN*/, 
  58. TBBS_SEPARATOR,
  59. TBBS_SEPARATOR,
  60. TBBS_CHECKBOX, 
  61. /*TBBS_SEPARATOR,*/
  62. };
  63. for(int i = 0; i < countof(styles); i++)
  64. SetButtonStyle(i, styles[i]|TBBS_DISABLED);
  65. m_volctrl.Create(this);
  66. if(AfxGetAppSettings().fDisabeXPToolbars)
  67. {
  68. if(HMODULE h = LoadLibrary(_T("uxtheme.dll")))
  69. {
  70. SetWindowThemeFunct f = (SetWindowThemeFunct)GetProcAddress(h, "SetWindowTheme");
  71. if(f) f(m_hWnd, L" ", L" ");
  72. FreeLibrary(h);
  73. }
  74. }
  75. return TRUE;
  76. }
  77. BOOL CPlayerToolBar::PreCreateWindow(CREATESTRUCT& cs)
  78. {
  79. if(!__super::PreCreateWindow(cs))
  80. return FALSE;
  81. m_dwStyle &= ~CBRS_BORDER_TOP;
  82. m_dwStyle &= ~CBRS_BORDER_BOTTOM;
  83. // m_dwStyle |= CBRS_SIZE_FIXED;
  84. return TRUE;
  85. }
  86. void CPlayerToolBar::ArrangeControls()
  87. {
  88. if(!::IsWindow(m_volctrl.m_hWnd)) return;
  89. CRect r;
  90. GetClientRect(&r);
  91. CRect br = GetBorders();
  92. CRect r10;
  93. GetItemRect(10, &r10);
  94. CRect vr;
  95. m_volctrl.GetClientRect(&vr);
  96. CRect vr2(r.right+br.right-60, r.top-1, r.right+br.right+6, r.bottom);
  97. m_volctrl.MoveWindow(vr2);
  98. UINT nID;
  99. UINT nStyle;
  100. int iImage;
  101. GetButtonInfo(12, nID, nStyle, iImage);
  102. SetButtonInfo(11, GetItemID(11), TBBS_SEPARATOR, vr2.left - iImage - r10.right - 11);
  103. }
  104. void CPlayerToolBar::SetMute(bool fMute)
  105. {
  106. CToolBarCtrl& tb = GetToolBarCtrl();
  107. TBBUTTONINFO bi;
  108. bi.cbSize = sizeof(bi);
  109. bi.dwMask = TBIF_IMAGE;
  110. bi.iImage = fMute?13:12;
  111. tb.SetButtonInfo(ID_VOLUME_MUTE, &bi);
  112. AfxGetAppSettings().fMute = fMute;
  113. }
  114. bool CPlayerToolBar::IsMuted()
  115. {
  116. CToolBarCtrl& tb = GetToolBarCtrl();
  117. TBBUTTONINFO bi;
  118. bi.cbSize = sizeof(bi);
  119. bi.dwMask = TBIF_IMAGE;
  120. tb.GetButtonInfo(ID_VOLUME_MUTE, &bi);
  121. return(bi.iImage==13);
  122. }
  123. int CPlayerToolBar::GetVolume()
  124. {
  125. int volume = m_volctrl.GetPos();
  126. volume = (int)((log10(1.0*volume)-2)*5000);
  127. volume = max(min(volume, 0), -10000);
  128. return(IsMuted() ? -10000 : volume);
  129. }
  130. void CPlayerToolBar::SetVolume(int volume)
  131. {
  132. /*
  133. volume = (int)pow(10, ((double)volume)/5000+2);
  134. volume = max(min(volume, 100), 1);
  135. */
  136. m_volctrl.SetPosInternal(volume);
  137. }
  138. BEGIN_MESSAGE_MAP(CPlayerToolBar, CToolBar)
  139. ON_WM_PAINT()
  140. ON_WM_SIZE()
  141. ON_MESSAGE_VOID(WM_INITIALUPDATE, OnInitialUpdate)
  142. ON_COMMAND_EX(ID_VOLUME_MUTE, OnVolumeMute)
  143. ON_UPDATE_COMMAND_UI(ID_VOLUME_MUTE, OnUpdateVolumeMute)
  144. ON_COMMAND_EX(ID_VOLUME_UP, OnVolumeUp)
  145. ON_COMMAND_EX(ID_VOLUME_DOWN, OnVolumeDown)
  146. ON_WM_NCPAINT()
  147. ON_WM_LBUTTONDOWN()
  148. END_MESSAGE_MAP()
  149. // CPlayerToolBar message handlers
  150. void CPlayerToolBar::OnPaint()
  151. {
  152. if(m_bDelayedButtonLayout)
  153. Layout();
  154. CPaintDC dc(this); // device context for painting
  155. DefWindowProc(WM_PAINT, WPARAM(dc.m_hDC), 0);
  156. {
  157. UINT nID;
  158. UINT nStyle = 0;
  159. int iImage = 0;
  160. GetButtonInfo(11, nID, nStyle, iImage);
  161. CRect ItemRect;
  162. GetItemRect(11, ItemRect);
  163. dc.FillSolidRect(ItemRect, GetSysColor(COLOR_BTNFACE));
  164. }
  165. }
  166. void CPlayerToolBar::OnSize(UINT nType, int cx, int cy)
  167. {
  168. __super::OnSize(nType, cx, cy);
  169. ArrangeControls();
  170. }
  171. void CPlayerToolBar::OnInitialUpdate()
  172. {
  173. ArrangeControls();
  174. }
  175. BOOL CPlayerToolBar::OnVolumeMute(UINT nID)
  176. {
  177. SetMute(!IsMuted());
  178. return FALSE;
  179. }
  180. void CPlayerToolBar::OnUpdateVolumeMute(CCmdUI* pCmdUI)
  181. {
  182. pCmdUI->Enable(true);
  183. pCmdUI->SetCheck(IsMuted());
  184. }
  185. BOOL CPlayerToolBar::OnVolumeUp(UINT nID)
  186. {
  187. m_volctrl.IncreaseVolume();
  188. return FALSE;
  189. }
  190. BOOL CPlayerToolBar::OnVolumeDown(UINT nID)
  191. {
  192. m_volctrl.DecreaseVolume();
  193. return FALSE;
  194. }
  195. void CPlayerToolBar::OnNcPaint() // when using XP styles the NC area isn't drawn for our toolbar...
  196. {
  197. CRect wr, cr;
  198. CWindowDC dc(this);
  199. GetClientRect(&cr);
  200. ClientToScreen(&cr);
  201. GetWindowRect(&wr);
  202. cr.OffsetRect(-wr.left, -wr.top);
  203. wr.OffsetRect(-wr.left, -wr.top);
  204. dc.ExcludeClipRect(&cr);
  205. dc.FillSolidRect(wr, GetSysColor(COLOR_BTNFACE));
  206. // Do not call CToolBar::OnNcPaint() for painting messages
  207. }
  208. void CPlayerToolBar::OnLButtonDown(UINT nFlags, CPoint point)
  209. {
  210. for(int i = 0, j = GetToolBarCtrl().GetButtonCount(); i < j; i++)
  211. {
  212. if(GetButtonStyle(i)&(TBBS_SEPARATOR|TBBS_DISABLED))
  213. continue;
  214. CRect r;
  215. GetItemRect(i, r);
  216. if(r.PtInRect(point))
  217. {
  218. __super::OnLButtonDown(nFlags, point);
  219. return;
  220. }
  221. }
  222. CMainFrame* pFrame = ((CMainFrame*)GetParentFrame());
  223. if(!pFrame->m_fFullScreen)
  224. {
  225. MapWindowPoints(pFrame, &point, 1);
  226. pFrame->PostMessage(WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x, point.y));
  227. }
  228. }