您的位置:首页 > 科技 > IT业 > MFC GDI绘制卡通人物

MFC GDI绘制卡通人物

2024/10/6 12:24:00 来源:https://blog.csdn.net/wang161019/article/details/139872513  浏览:    关键词:MFC GDI绘制卡通人物

文章目录

    • 主要代码
    • 完整visual studio工程下载

主要代码

// 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/
// 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 csreturn CView::PreCreateWindow(cs);
}/
// CDrawFrogView drawingvoid CDrawFrogView::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 printingBOOL CDrawFrogView::OnPreparePrinting(CPrintInfo* pInfo)
{// default preparationreturn 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 handlersvoid 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工程下载


点击前往下载

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com