// DrawFrogView.cpp : implementation of the CDrawFrogView class//#include"stdafx.h"#include"DrawFrog.h"#include"DrawFrogDoc.h"#include"DrawFrogView.h"#include"math.h"#definePI3.14#ifdef_DEBUG#definenewDEBUG_NEW#undefTHIS_FILEstaticchar THIS_FILE[]=__FILE__;#endif/// CDrawFrogViewIMPLEMENT_DYNCREATE(CDrawFrogView, CView)BEGIN_MESSAGE_MAP(CDrawFrogView, CView)//{{AFX_MSG_MAP(CDrawFrogView)// NOTE - the ClassWizard will add and remove mapping macros here.// DO NOT EDIT what you see in these blocks of generated code!//}}AFX_MSG_MAP// Standard printing commandsON_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()/// CDrawFrogView construction/destructionCDrawFrogView::CDrawFrogView(){// TODO: add construction code here}CDrawFrogView::~CDrawFrogView(){}
BOOL CDrawFrogView::PreCreateWindow(CREATESTRUCT& cs){// TODO: Modify the Window class or styles here by modifying// the CREATESTRUCT csreturnCView::PreCreateWindow(cs);}/// CDrawFrogView drawingvoidCDrawFrogView::OnDraw(CDC* pDC){
CDrawFrogDoc* pDoc =GetDocument();ASSERT_VALID(pDoc);// TODO: add draw code for native data hereRedFlag();Flagpole(400,100,405,500);Flagpole(900,100,905,500);//五角星的五个点位置FiveStar(375,125,15,PI/2);FiveStar(350,110,5,-atan(3/5));FiveStar(340,120,5,-atan(1/7));FiveStar(340,135,5,-atan(2/7));FiveStar(350,145,5,-atan(4/5));//绘制绿色的青蛙GreenFrog();//奥运五环Olinpinic();}/// CDrawFrogView printing
BOOL CDrawFrogView::OnPreparePrinting(CPrintInfo* pInfo){// default preparationreturnDoPreparePrinting(pInfo);}voidCDrawFrogView::OnBeginPrinting(CDC*/*pDC*/, CPrintInfo*/*pInfo*/){// TODO: add extra initialization before printing}voidCDrawFrogView::OnEndPrinting(CDC*/*pDC*/, CPrintInfo*/*pInfo*/){// TODO: add cleanup after printing}/// CDrawFrogView diagnostics#ifdef_DEBUGvoidCDrawFrogView::AssertValid()const{CView::AssertValid();}voidCDrawFrogView::Dump(CDumpContext& dc)const{CView::Dump(dc);}
CDrawFrogDoc*CDrawFrogView::GetDocument()// non-debug version is inline{ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDrawFrogDoc)));return(CDrawFrogDoc*)m_pDocument;}#endif//_DEBUG/// CDrawFrogView message handlersvoidCDrawFrogView::RedFlag(){
CDC *pDC =GetDC();
CPen penRed(PS_SOLID,1,RGB(255,0,0));//创建一个红色画笔
CPen *pOldPen = pDC->SelectObject(&penRed);//简画笔与DC关联
CBrush brushYellow(RGB(255,0,0));//黄色画刷
CBrush *pOldBrush = pDC->SelectObject(&brushYellow);//与DC关联
pDC->SetPolyFillMode(WINDING);//多边形填充颜色
POINT pts[4]={{250,100},{400,100},{400,200},{250,200}};//绘制旗帜的大小,注意顺序
pDC->Polygon(pts,4);
pDC->SelectObject(pOldPen);//选定当前指定画笔
pDC->SelectObject(pOldBrush);//选中当前指定画刷}voidCDrawFrogView::Flagpole(int x0,int y0,int x1,int y1){
CDC *pDC =GetDC();
CBrush brushBlack(RGB(0,0,0));
CBrush *OldBrush = pDC->SelectObject(&brushBlack);
pDC->Rectangle(x0,y0,x1,y1);}}