MFC GDI绘制卡通人物

主要代码

// DrawFrogView.cpp : implementation of the CDrawFrogView class
//

#include "stdafx.h"
#include "DrawFrog.h"

#include "DrawFrogDoc.h"
#include "DrawFrogView.h"

#include "math.h"
#define PI 3.14

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDrawFrogView

IMPLEMENT_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 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()

/////////////////////////////////////////////////////////////////////////////
// CDrawFrogView construction/destruction

CDrawFrogView::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 cs

    return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CDrawFrogView drawing

void CDrawFrogView::OnDraw(CDC* pDC)
{
    CDrawFrogDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    // TODO: add draw code for native data here
    RedFlag();
    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 preparation
    return DoPreparePrinting(pInfo);
}

void CDrawFrogView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
    // TODO: add extra initialization before printing
}

void CDrawFrogView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
    // TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CDrawFrogView diagnostics

#ifdef _DEBUG
void CDrawFrogView::AssertValid() const
{
    CView::AssertValid();
}

void CDrawFrogView::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 handlers

void CDrawFrogView::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);//选中当前指定画刷
}

void CDrawFrogView::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);
}

}


完整visual studio工程下载

点击下方"支付宝", ¥50 查看完整内容~ (关于识别码:请任意输入识别码,您记得住就行)
THE END
分享
二维码
打赏
海报
MFC GDI绘制卡通人物
主要代码 // DrawFrogView.cpp : implementation of the CDrawFrogView class // #include "stdafx.h" #include "DrawFrog.h" #include "DrawFrogDoc.h" #i……
<<上一篇
下一篇>>