📄 1_5view.cpp
字号:
// 1_5View.cpp : implementation of the CMy1_5View class
//
#include "stdafx.h"
#include "1_5.h"
#include "1_5Doc.h"
#include "1_5View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMy1_5View
IMPLEMENT_DYNCREATE(CMy1_5View, CView)
BEGIN_MESSAGE_MAP(CMy1_5View, CView)
//{{AFX_MSG_MAP(CMy1_5View)
ON_WM_CREATE()
ON_WM_TIMER()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMy1_5View construction/destruction
CMy1_5View::CMy1_5View()
{
// TODO: add construction code here
//获得位图
m_Bitmap.LoadBitmap(IDB_BITMAP1);
ixunhuan=0;
}
CMy1_5View::~CMy1_5View()
{
}
BOOL CMy1_5View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMy1_5View drawing
void CMy1_5View::OnDraw(CDC* pDC)
{
CMy1_5Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CDC Dc;
if(Dc.CreateCompatibleDC(pDC)==FALSE)
AfxMessageBox("Can't create DC");
//画复杂图形,有多种颜色
for(int j=0;j<25;j++)
for(int i=0;i<44;i++)
{
CBrush mybrush1;
mybrush1.CreateSolidBrush(RGB((i*20)%255,(j*20)%255,(i+j+20)%255));
//正方形
CRect myrect1(20*i,20*j,20*i+20,20*j+20);
pDC->FillRect(myrect1,&mybrush1);
//圆
pDC->Ellipse(20*i,20*j,20*i+20,20*j+20);
//小正方形
CRect myrect2(20*i+4,20*j+4,20*i+16,20*j+16);
pDC->FillRect(myrect2,&mybrush1);
//小圆
pDC->Ellipse(20*i+4,20*j+4,20*i+16,20*j+16);
//更小正方形
CRect myrect3(20*i+7,20*j+7,20*i+13,20*j+13);
pDC->FillRect(myrect3,&mybrush1);
//更小圆
pDC->Ellipse(20*i+7,20*j+7,20*i+13,20*j+13);
//最小正方形
CRect myrect4(20*i+9,20*j+9,20*i+11,20*j+11);
pDC->FillRect(myrect4,&mybrush1);
}
//在不同位置显示位图
Dc.SelectObject(m_Bitmap);
pDC->StretchBlt(70+ixunhuan,70,160,160,&Dc,0,0,71,71,SRCCOPY);
}
/////////////////////////////////////////////////////////////////////////////
// CMy1_5View printing
BOOL CMy1_5View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMy1_5View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMy1_5View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMy1_5View diagnostics
#ifdef _DEBUG
void CMy1_5View::AssertValid() const
{
CView::AssertValid();
}
void CMy1_5View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMy1_5Doc* CMy1_5View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMy1_5Doc)));
return (CMy1_5Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMy1_5View message handlers
int CMy1_5View::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
SetTimer(1,1200,NULL);
return 0;
}
void CMy1_5View::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
// TODO: Add your message handler code here and/or call default
ixunhuan=(ixunhuan+30)%400;
//如果图象回到开头,全部重画
// if(ixunhuan<40)
Invalidate();
//设置部分更新区域
// CRect r;
// r.left=70+ixunhuan-40;
// r.top=70;
// r.bottom=r.top+160;
// r.right=r.left+200;
//部分更新函数
// InvalidateRect(r,TRUE);
CView::OnTimer(nIDEvent);
}
//虚函数OnInitialUpdate() ,初始化位图变量
void CMy1_5View::OnInitialUpdate()
{
CView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -