龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > VC开发 >

VC++制作播放AVI视频流的动画按钮[图](3)

时间:2009-12-30 15:42来源:未知 作者:admin 点击:
分享到:
//画右下边缘 pDC-MoveTo(rect.Width()-1,0); pDC-LineTo(rect.Width()-1,rect.Height()-1); pDC-LineTo(0,rect.Height()-1); pDC-MoveTo(rect.Width()-2,1); pDC-LineTo(rect.Width()-2,rect.Height()-2); pDC
  //画右下边缘
  pDC->MoveTo(rect.Width()-1,0);
  pDC->LineTo(rect.Width()-1,rect.Height()-1);
  pDC->LineTo(0,rect.Height()-1);
  pDC->MoveTo(rect.Width()-2,1);
  pDC->LineTo(rect.Width()-2,rect.Height()-2);
  pDC->LineTo(0,rect.Height()-2);
  if (pen2Created)//删除"pen2"画笔对象
  {
   pen2.DeleteObject();
   pen2Created = FALSE;
  }
  if (pen1Created = pen1.CreatePen(PS_SOLID, 1, edgeCol))
   pOldPen = pDC->SelectObject( &pen1 );
  if (pen1Created)
  {
   pen1.DeleteObject();
   pen1Created = FALSE;
  }
  if (pOldPen != NULL)
   pDC->SelectObject( pOldPen );
}
void CAviButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
  // TODO: Add your code to draw the specified item
  CRect rect;
  GetClientRect(rect);
  if (!::IsWindow(AnimateCtrl))
  {
   //在按钮上生成一个动画控件
   AnimateCtrl.Create(WS_CHILD |WS_VISIBLE,rect,this,0);
   //打开avi文件并显示第一帧
   AnimateCtrl.Open(m_nAviID);
   AnimateCtrl.GetClientRect(rect);
  }
  CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
  UINT nState = lpDrawItemStruct->itemState;
  CRect buttonRect;
  GetClientRect(buttonRect);
  //绘制按钮
  DrawButton(pDC, nState, buttonRect);
}
BOOL CAviButton::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD
dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
  // TODO: Add your specialized code here and/or call the base class
  return CWnd::Create(lpszClassName, lpszWindowName, dwStyle,
  rect, pParentWnd, nID, pContext);
}
void CAviButton::OnMouseMove(UINT nFlags, CPoint point)
{
  // TODO: Add your message handler code here and/or call default
  ClientToScreen(&point);
  CRect rcWindow;
  GetWindowRect(rcWindow);
  //判断鼠标是否经过按钮
  BOOL bNewMouseOverButton = rcWindow.PtInRect(point);
  if (bNewMouseOverButton && IsWindowEnabled() )
  {
   if (::IsWindow(AnimateCtrl) && !bPlaying)
   {
    AnimateCtrl.Play(0,-1,1);
    bPlaying = TRUE;
    SetCapture();
   }
  }
  else
  {
   bPlaying = FALSE;
   ReleaseCapture();
  }
  CButton::OnMouseMove(nFlags, point);
}
/////////////////////////////////
BOOL CTestAviButtonDlg::OnInitDialog()
{
  CDialog::OnInitDialog();
  …………………//此处代码省略;
  m_AviButton.LoadAvi(IDR_AVI);
  return TRUE; // return TRUE unless you set the focus to a control
}

  四、小结

  通过CAnimateCtrl类和按钮控件的自画功能的结合,本实例实现了动画按钮,如果该类和工具条、状态条等控件结合,还可以实现在上述控件上播放动画视频流的效果。

精彩图集

赞助商链接