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

多媒体编程

开发平台:

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. // ChildView.cpp : implementation of the CChildView class
  22. //
  23. #include "stdafx.h"
  24. #include "mplayerc.h"
  25. #include "ChildView.h"
  26. #include "MainFrm.h"
  27. #ifdef _DEBUG
  28. #define new DEBUG_NEW
  29. #undef THIS_FILE
  30. static char THIS_FILE[] = __FILE__;
  31. #endif
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CChildView
  34. CChildView::CChildView() : m_vrect(0,0,0,0)
  35. {
  36. m_lastlmdowntime = 0;
  37. m_lastlmdownpoint.SetPoint(0, 0);
  38. LoadLogo();
  39. }
  40. CChildView::~CChildView()
  41. {
  42. }
  43. BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs) 
  44. {
  45. if(!CWnd::PreCreateWindow(cs))
  46. return FALSE;
  47. cs.style &= ~WS_BORDER;
  48. cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS, 
  49. ::LoadCursor(NULL, IDC_HAND), HBRUSH(COLOR_WINDOW+1), NULL);
  50. return TRUE;
  51. }
  52. BOOL CChildView::PreTranslateMessage(MSG* pMsg)
  53. {
  54. if(pMsg->message >= WM_MOUSEFIRST && pMsg->message <= WM_MYMOUSELAST)
  55. {
  56. CWnd* pParent = GetParent();
  57. CPoint p(pMsg->lParam);
  58. ::MapWindowPoints(pMsg->hwnd, pParent->m_hWnd, &p, 1);
  59. bool fDblClick = false;
  60. bool fInteractiveVideo = ((CMainFrame*)AfxGetMainWnd())->IsInteractiveVideo();
  61. /*
  62. if(fInteractiveVideo)
  63. {
  64. if(pMsg->message == WM_LBUTTONDOWN)
  65. {
  66. if((pMsg->time - m_lastlmdowntime) <= GetDoubleClickTime()
  67. && abs(pMsg->pt.x - m_lastlmdownpoint.x) <= GetSystemMetrics(SM_CXDOUBLECLK)
  68. && abs(pMsg->pt.y - m_lastlmdownpoint.y) <= GetSystemMetrics(SM_CYDOUBLECLK))
  69. {
  70. fDblClick = true;
  71. m_lastlmdowntime = 0;
  72. m_lastlmdownpoint.SetPoint(0, 0);
  73. }
  74. else
  75. {
  76. m_lastlmdowntime = pMsg->time;
  77. m_lastlmdownpoint = pMsg->pt;
  78. }
  79. }
  80. else if(pMsg->message == WM_LBUTTONDBLCLK)
  81. {
  82. m_lastlmdowntime = pMsg->time;
  83. m_lastlmdownpoint = pMsg->pt;
  84. }
  85. }
  86. */
  87. if((pMsg->message == WM_LBUTTONDOWN || pMsg->message == WM_LBUTTONUP || pMsg->message == WM_MOUSEMOVE)
  88. && fInteractiveVideo)
  89. {
  90. if(pMsg->message == WM_MOUSEMOVE)
  91. {
  92. pParent->PostMessage(pMsg->message, pMsg->wParam, MAKELPARAM(p.x, p.y));
  93. }
  94. if(fDblClick)
  95. {
  96. pParent->PostMessage(WM_LBUTTONDOWN, pMsg->wParam, MAKELPARAM(p.x, p.y));
  97. pParent->PostMessage(WM_LBUTTONDBLCLK, pMsg->wParam, MAKELPARAM(p.x, p.y));
  98. }
  99. }
  100. else
  101. {
  102. pParent->PostMessage(pMsg->message, pMsg->wParam, MAKELPARAM(p.x, p.y));
  103.             return TRUE;
  104. }
  105. }
  106. return CWnd::PreTranslateMessage(pMsg);
  107. }
  108. void CChildView::SetVideoRect(CRect r)
  109. {
  110. m_vrect = r;
  111. Invalidate();
  112. }
  113. void CChildView::LoadLogo()
  114. {
  115. AppSettings& s = AfxGetAppSettings();
  116. CAutoLock cAutoLock(&m_csLogo);
  117. m_logo.Destroy();
  118. if(s.logoext)
  119. {
  120. if(AfxGetAppSettings().fXpOrBetter)
  121. m_logo.Load(s.logofn);
  122. else if(HANDLE h = LoadImage(NULL, s.logofn, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE))
  123. m_logo.Attach((HBITMAP)h); // win9x bug: Inside Attach GetObject() will return all zeros in DIBSECTION and silly CImage uses that to init width, height, bpp, ... so we can't use CImage::Draw later
  124. }
  125. if(m_logo.IsNull())
  126. {
  127. m_logo.LoadFromResource(AfxGetInstanceHandle(), s.logoid);
  128. }
  129. if(m_hWnd) Invalidate();
  130. }
  131. CSize CChildView::GetLogoSize()
  132. {
  133. CSize ret(0,0);
  134. if(!m_logo.IsNull())
  135. ret.SetSize(m_logo.GetWidth(), m_logo.GetHeight());
  136. return ret;
  137. }
  138. IMPLEMENT_DYNAMIC(CChildView, CWnd)
  139. BEGIN_MESSAGE_MAP(CChildView, CWnd)
  140. //{{AFX_MSG_MAP(CChildView)
  141. ON_WM_PAINT()
  142. ON_WM_ERASEBKGND()
  143. ON_WM_SIZE()
  144. ON_WM_WINDOWPOSCHANGED()
  145. ON_COMMAND_EX(ID_PLAY_PLAYPAUSE, OnPlayPlayPauseStop)
  146. ON_COMMAND_EX(ID_PLAY_PLAY, OnPlayPlayPauseStop)
  147. ON_COMMAND_EX(ID_PLAY_PAUSE, OnPlayPlayPauseStop)
  148. ON_COMMAND_EX(ID_PLAY_STOP, OnPlayPlayPauseStop)
  149. ON_WM_SETCURSOR()
  150. ON_WM_NCCALCSIZE()
  151. ON_WM_NCPAINT()
  152. //}}AFX_MSG_MAP
  153. END_MESSAGE_MAP()
  154. /////////////////////////////////////////////////////////////////////////////
  155. // CChildView message handlers
  156. void CChildView::OnPaint() 
  157. {
  158. CPaintDC dc(this); // device context for painting
  159. ((CMainFrame*)GetParentFrame())->RepaintVideo();
  160. // Do not call CWnd::OnPaint() for painting messages
  161. }
  162. BOOL CChildView::OnEraseBkgnd(CDC* pDC)
  163. {
  164. CRect r;
  165. CAutoLock cAutoLock(&m_csLogo);
  166. if(((CMainFrame*)GetParentFrame())->IsSomethingLoaded())
  167. {
  168. pDC->ExcludeClipRect(m_vrect);
  169. }
  170. else if(!m_logo.IsNull() /*&& ((CMainFrame*)GetParentFrame())->IsPlaylistEmpty()*/)
  171. {
  172. BITMAP bm;
  173. GetObject(m_logo, sizeof(bm), &bm);
  174. GetClientRect(r);
  175. int w = min(bm.bmWidth, r.Width());
  176. int h = min(abs(bm.bmHeight), r.Height());
  177. // int w = min(m_logo.GetWidth(), r.Width());
  178. // int h = min(m_logo.GetHeight(), r.Height());
  179. int x = (r.Width() - w) / 2;
  180. int y = (r.Height() - h) / 2;
  181. r = CRect(CPoint(x, y), CSize(w, h));
  182. int oldmode = pDC->SetStretchBltMode(STRETCH_HALFTONE);
  183. m_logo.StretchBlt(*pDC, r, CRect(0,0,bm.bmWidth,abs(bm.bmHeight)));
  184. // m_logo.Draw(*pDC, r);
  185. pDC->SetStretchBltMode(oldmode);
  186. pDC->ExcludeClipRect(r);
  187. }
  188. GetClientRect(r);
  189. pDC->FillSolidRect(r, 0);
  190. return TRUE;
  191. }
  192. void CChildView::OnSize(UINT nType, int cx, int cy)
  193. {
  194. CWnd::OnSize(nType, cx, cy);
  195. ((CMainFrame*)GetParentFrame())->MoveVideoWindow();
  196. }
  197. void CChildView::OnWindowPosChanged(WINDOWPOS* lpwndpos)
  198. {
  199. CWnd::OnWindowPosChanged(lpwndpos);
  200. ((CMainFrame*)GetParentFrame())->MoveVideoWindow();
  201. }
  202. BOOL CChildView::OnPlayPlayPauseStop(UINT nID)
  203. {
  204. if(nID == ID_PLAY_STOP) SetVideoRect();
  205. return FALSE;
  206. }
  207. BOOL CChildView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
  208. {
  209. if(((CMainFrame*)GetParentFrame())->m_fHideCursor)
  210. {
  211. SetCursor(NULL);
  212. return TRUE;
  213. }
  214. return CWnd::OnSetCursor(pWnd, nHitTest, message);
  215. }
  216. void CChildView::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS* lpncsp)
  217. {
  218. if(!((CMainFrame*)GetParentFrame())->IsFrameLessWindow()) 
  219. {
  220. InflateRect(&lpncsp->rgrc[0], -1, -1);
  221. }
  222. CWnd::OnNcCalcSize(bCalcValidRects, lpncsp);
  223. }
  224. void CChildView::OnNcPaint()
  225. {
  226. if(!((CMainFrame*)GetParentFrame())->IsFrameLessWindow()) 
  227. {
  228. CRect r;
  229. GetWindowRect(r);
  230. r.OffsetRect(-r.left, -r.top);
  231. CWindowDC(this).Draw3dRect(&r, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT)); 
  232. }
  233. }