用VC++制作播放AVI视频流的动画按钮(4)
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类和按钮控件的自画功能的结合,本实例实现了动画按钮,如果该类和工具条、状态条等控件结合,还可以实现在上述控件上播放动画视频流的效果。