ex55View.cpp
资源名称:VC6.0.rar [点击查看]
上传用户:qdhmjx
上传日期:2022-07-11
资源大小:2226k
文件大小:4k
源码类别:
书籍源码
开发平台:
Visual C++
- // ex55View.cpp : implementation of the CEx55View class
- //
- #include "stdafx.h"
- #include "ex55.h"
- #include "ex55Doc.h"
- #include "ex55View.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CEx55View
- IMPLEMENT_DYNCREATE(CEx55View, CView)
- BEGIN_MESSAGE_MAP(CEx55View, CView)
- //{{AFX_MSG_MAP(CEx55View)
- // 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()
- /////////////////////////////////////////////////////////////////////////////
- // CEx55View construction/destruction
- CEx55View::CEx55View()
- {
- // TODO: add construction code here
- }
- CEx55View::~CEx55View()
- {
- }
- BOOL CEx55View::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CEx55View drawing
- void CEx55View::OnDraw(CDC* pDC)
- {
- CEx55Doc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // TODO: add draw code for native data here
- int i;
- //绘制一组彩色点
- pDC->TextOut(20,20,"point");
- pDC->SetPixel(100,20,RGB(255,0,0));
- pDC->SetPixel(110,20,RGB(0,255,0));
- pDC->SetPixel(120,20,RGB(0,0,255));
- pDC->SetPixel(130,20,RGB(255,255,0));
- pDC->SetPixel(140,20,RGB(255,0,255));
- pDC->SetPixel(150,20,RGB(0,255,255));
- pDC->SetPixel(160,20,RGB(0,0,0));
- //绘制一组彩色线
- //设置颜色表
- struct tagColor
- {
- int r,g,b;
- }color[7]={{255,0,0},{0,255,0},{0,0,255},{255,255,0},{255,0,255},{0,255,255},{0,0,0}};
- //定义两个指向画笔的指针
- CPen* pNewPen;
- CPen* pOldPen;
- for(i=0;i<7;i++)
- {
- pNewPen=new CPen; //构造画笔并初始化
- if(pNewPen->CreatePen(PS_SOLID,2,RGB(color[i].r,color[i].g,color[i].b)))
- {
- //把新创建的画笔选入设备描述表,同时保存原来的画笔
- pOldPen=pDC->SelectObject(pNewPen);
- //用新画笔绘图
- pDC->MoveTo(20,60+i*10);
- pDC->LineTo(160,60+i*10);
- //恢复设备描述表中的原有画笔
- pDC->SelectObject(pOldPen);
- }
- else
- {
- AfxMessageBox("Create Pen Error!");
- }
- delete pNewPen; //删除新画笔,以便再另外分配
- }
- //绘制圆弧
- for(i=0;i<8;i++)
- pDC->Arc(260-5*i,70-5*i,260+5*i,70+5*i,260+5*i,70,260+5*i,70);
- CBrush* pNewBrush;
- CBrush* pOldBrush;
- for(i=8;i>1;i--)
- {
- pNewBrush=new CBrush;
- if(pNewBrush->CreateSolidBrush(RGB(color[8-i].r,color[8-i].g,color[8-i].b)))
- {
- pOldBrush=pDC->SelectObject(pNewBrush);
- pDC->Ellipse(260-10*i,200-5*i,260+10*i,200+5*i);
- pDC->SelectObject(pOldPen);
- }
- delete pNewBrush;
- }
- //绘制矩形和圆角矩形
- pDC->Rectangle(190,270,250,310);
- pDC->RoundRect(260,270,330,310,30,20);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CEx55View printing
- BOOL CEx55View::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CEx55View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CEx55View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CEx55View diagnostics
- #ifdef _DEBUG
- void CEx55View::AssertValid() const
- {
- CView::AssertValid();
- }
- void CEx55View::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CEx55Doc* CEx55View::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEx55Doc)));
- return (CEx55Doc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CEx55View message handlers