📄 frameview.cpp
字号:
// FrameView.cpp : implementation of the CFrameView class
//
#include "stdafx.h"
#include "Frame.h"
#include "FrameDoc.h"
#include "FrameView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include "Dib.h"
/////////////////////////////////////////////////////////////////////////////
// CFrameView
IMPLEMENT_DYNCREATE(CFrameView, CView)
BEGIN_MESSAGE_MAP(CFrameView, CView)
//{{AFX_MSG_MAP(CFrameView)
ON_WM_CREATE()
ON_WM_TIMER()
ON_WM_DESTROY()
ON_COMMAND(IDM_PAUSE, OnPause)
ON_UPDATE_COMMAND_UI(IDM_PAUSE, OnUpdatePause)
ON_COMMAND(IDM_PLAY, OnPlay)
ON_UPDATE_COMMAND_UI(IDM_PLAY, OnUpdatePlay)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFrameView construction/destruction
CFrameView::CFrameView()
{
// TODO: add construction code here
m_nCurrentFrame = 0;
m_bPlay = TRUE;
}
CFrameView::~CFrameView()
{
for(int i = 0; i < m_nTotalFrames; i++)
{
CDib* pDib = (CDib*)m_frameArray.GetAt(i);
delete pDib;
}
m_frameArray.RemoveAll();
}
BOOL CFrameView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CFrameView drawing
void CFrameView::OnDraw(CDC* pDC)
{
// TODO: add draw code for native data here
CRect rect;
GetClientRect(&rect);
int nClientWidth = rect.Width();
int nClientHeight = rect.Height();
CDC memDC;
memDC.CreateCompatibleDC(pDC);
CBitmap bitmap;
bitmap.CreateCompatibleBitmap(pDC, nClientWidth, nClientHeight);
CBitmap* pOldBitmap = memDC.SelectObject(&bitmap);
CBrush* pBrush = new CBrush(RGB(0, 0, 0));
memDC.FillRect(rect, pBrush);
delete pBrush;
CDib* pDib = (CDib*)m_frameArray.GetAt(m_nCurrentFrame);
int nWidth = (int)pDib->GetWidth();
int nHeight = (int)pDib->GetHeight();
pDib->Draw(memDC.m_hDC, (nClientWidth - nWidth) / 2 , (nClientHeight - nHeight) / 2, nWidth, nHeight, 0, 0, nWidth, nHeight, DIB_RGB_COLORS, SRCCOPY);
pDC->BitBlt(0, 0, nClientWidth, nClientHeight, &memDC, 0, 0, SRCCOPY);
memDC.SelectObject(pOldBitmap);
bitmap.DeleteObject();
}
/////////////////////////////////////////////////////////////////////////////
// CFrameView diagnostics
#ifdef _DEBUG
void CFrameView::AssertValid() const
{
CView::AssertValid();
}
void CFrameView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CFrameDoc* CFrameView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CFrameDoc)));
return (CFrameDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CFrameView message handlers
int CFrameView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
m_nTotalFrames = 26;
for(int i = 0; i < m_nTotalFrames; i++)
{
CString strFileName = "flame";
if(i < 10)strFileName += "0";
CString strItoa;
strItoa.Format("%d", i);
strFileName += (strItoa + ".bmp");
CDib* pDib = new CDib(strFileName);
m_frameArray.Add(pDib);
}
SetTimer(1, 30, NULL);
return 0;
}
void CFrameView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
m_nCurrentFrame++;
m_nCurrentFrame = m_nCurrentFrame % m_nTotalFrames;
Invalidate(FALSE);
CView::OnTimer(nIDEvent);
}
void CFrameView::OnDestroy()
{
CView::OnDestroy();
// TODO: Add your message handler code here
if(m_bPlay)KillTimer(1);
}
void CFrameView::OnPause()
{
// TODO: Add your command handler code here
m_bPlay = FALSE;
KillTimer(1);
}
void CFrameView::OnUpdatePause(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if(!m_bPlay)
pCmdUI ->SetCheck(TRUE);
else
pCmdUI ->SetCheck(FALSE);
}
void CFrameView::OnPlay()
{
// TODO: Add your command handler code here
m_bPlay = TRUE;
SetTimer(1, 30, NULL);
}
void CFrameView::OnUpdatePlay(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if(m_bPlay)
pCmdUI ->SetCheck(TRUE);
else
pCmdUI ->SetCheck(FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -