ChildView.cpp
上传用户:tangyu_668
上传日期:2014-02-27
资源大小:678k
文件大小:7k
源码类别:

多媒体编程

开发平台:

Visual C++

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