用VC制作播放AVI视频流的动画按钮3节能
民生历史 2020-11-15 04:19 字号: 大 中 小
三、实现代码
/////////////////////////////// AviButton.h : header file
#if !defined(AFX_AVIBUTTON_H__5E20D4EF_864E_11D7_886E_F16C81CD642B__INCLUDED_)
#define AFX_AVIBUTTON_H__5E20D4EF_864E_11D7_886E_F16C81CD642B__INCLUDED_
#if _MSC_VER 1000
#pragma once
#endif // _MSC_VER 1000
class CAviButton : public CButton
{
// Construction
public:
CAviButton();
public:
UINT m_nAviID;
CAnimateCtrl AnimateCtrl;
BOOL bPlaying;
void LoadAvi(UINT nAviID);
void DrawButton(CDC* pDC, UINT nState, CRect rect);
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAviButton)
public:
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD
dwStyle, const RECT rect, CWnd* pParentWnd, UINT nID,
CCreateContext* pContext = NULL);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CAviButton();
// Generated message map functions
protected:
//{{AFX_MSG(CAviButton)
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
#endif
////////////////////////////P文件;
#include "stdafx.h"
#include "TestAviButton.h"
#include "AviButton.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CAviButton::CAviButton(2008年)
{
m_nAviID = 0;
bPlaying = FALSE;
}
CAviButton::~CAviButton()
{}
void CAviButton::LoadAvi(UINT nAviID)
{
m_nAviID =nAviID;
}
BEGIN_MESSAGE_MAP(CAviButton, CButton)
//{{AFX_MSG_MAP(CAviButton)
ON_WM_MOUSEMOVE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
///////////////////// CAviButton message handlers
void CAviButton::DrawButton(CDC *pDC, UINT nState, CRect rect)
{
COLORREF upCol,downCol,edgeCol;
edgeCol=RGB(0,0,0); //设置按钮边缘的初始化颜色;
if ((nState ODS_SELECTED) == ODS_SELECTED)
{
//设置按钮被按下时按钮的颜色
upCol=RGB(0,0,0);
edgeCol=RGB(128,128,128);
downCol=RGB(0,0,0);
}
else
{
//设置按钮正常时按钮的颜色
upCol=RGB(255,255,255);
downCol=RGB(128,128,128);
}
CPen* pOldPen = NULL;
BOOL pen1Created;
CPen pen1;
BOOL pen2Created;
CPen pen2;
if (pen1Created = eatePen(PS_SOLID, 1, upCol))
pOldPen = pDC-SelectObject( pen1 );
//画左上边缘
pDC-MoveTo(1,ight()-1);
pDC-LineTo(1,1);
pDC-LineTo(dth()-1,1);
pDC-MoveTo(0,ight()-1);
pDC-LineTo(0,0);
pDC-LineTo(dt这当然与房产和汽车线下端过重有关h()-1,0);
if (pen2Created = eatePen(PS_SOLID, 1, downCol))
pDC-SelectObject( pen2 );
if (pen1Created)
{
leteObject();
pen1Created = FALSE;
}
//画右下边缘
pDC-MoveTo(dth()-1,0);
pDC-LineTo(dth()-1,ight()-1);
pDC-LineTo(0,ight()-1);
pDC-MoveTo(dth()-2,1);
pDC-LineTo(dth()-2,ight()-2);
pDC-LineTo(0,ight()-2);
if (pen2Created)//删除"pen2"画笔对象
{
leteObject();
pen2Created = FALSE;
}
if (pen1Created = eatePen(PS_SOLID, 1, edgeCol))
pOldPen = pDC-SelectObject( pen1 );
if (pen1Created)
{
leteObject();
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))
{
//在按钮上生成一个动画控件
eate(WS_CHILD |WS_VISIBLE,rect,this,0);
//打开avi文件并显示第一帧
en(m_nAviID);
tClientRect(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 = InRect(point);
if (bNewMouseOverButton IsWindowEnabled() )
{
if (::IsWindow(AnimateCtrl) !bPlaying)
{
ay(0,-1,1);
bPlaying = TRUE;
SetCapture();
}
}
else
{
bPlaying = FALSE;
ReleaseCapture();
}
CButton::OnMouseMove(nFlags, point);
}
/////////////////////////////////
BOOL CTestAviButtonDlg::OnInitDialog()
{
CDialog::OnInitDialog();
…………………//此处代码省略;
m_adAvi(IDR_AVI);
return TRUE; // return TRUE unless you set the focus to a control
}
四、小结
通过CAnimateCtrl类和按钮控件的自画功能的结合,本实例实现了动画按钮,如果该类和工具条、状态条等控件结合,还可以实现在上述控件上播放动画视频流的效果。查看本文来源
孩子不消化的症状有哪些复方鳖甲软肝片药效好吗四平去哪里看白癜风-
-
世界海拔最高铁人三项赛将在云南曲靖举行搭配
世界海拔最高铁人三项赛将在云南曲靖举行中新曲靖7月27日电...
2020-06-02 | 民生历史
-
-
陈忠和体验赛车感觉过瘾夫人扼杀赛道处子秀搭配
陈忠和体验赛车感觉过瘾 夫人“扼杀”赛道处子秀华奥星空晋...
2020-05-30 | 民生历史
-
-
周琦请不要再谦让打球合理并不适合现在的你搭配
周琦请不要再谦让!打球合理并不适合现在的你周琦北京时间...
2020-05-29 | 民生历史
-
-
四价宫颈癌疫苗正式在崇左开打
四价宫颈癌疫苗正式在崇左“开打”(原标题)四价宫颈癌疫...
2019-12-17 | 民生历史
-
-
全区安全生产工作紧急会议召开
全区安全生产工作紧急会议召开12月3日,全区安全生产工作紧...
2019-07-15 | 民生历史
-
-
2018年投资基金理财规划该怎么制定
2018年投资基金理财规划该怎么制定?2018年投资基金理财规划...
2019-07-07 | 民生历史