ex55View.cpp
上传用户:qdhmjx
上传日期:2022-07-11
资源大小:2226k
文件大小:4k
源码类别:

书籍源码

开发平台:

Visual C++

  1. // ex55View.cpp : implementation of the CEx55View class
  2. //
  3. #include "stdafx.h"
  4. #include "ex55.h"
  5. #include "ex55Doc.h"
  6. #include "ex55View.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CEx55View
  14. IMPLEMENT_DYNCREATE(CEx55View, CView)
  15. BEGIN_MESSAGE_MAP(CEx55View, CView)
  16. //{{AFX_MSG_MAP(CEx55View)
  17. // NOTE - the ClassWizard will add and remove mapping macros here.
  18. //    DO NOT EDIT what you see in these blocks of generated code!
  19. //}}AFX_MSG_MAP
  20. // Standard printing commands
  21. ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  22. ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  23. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  24. END_MESSAGE_MAP()
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CEx55View construction/destruction
  27. CEx55View::CEx55View()
  28. {
  29. // TODO: add construction code here
  30. }
  31. CEx55View::~CEx55View()
  32. {
  33. }
  34. BOOL CEx55View::PreCreateWindow(CREATESTRUCT& cs)
  35. {
  36. // TODO: Modify the Window class or styles here by modifying
  37. //  the CREATESTRUCT cs
  38. return CView::PreCreateWindow(cs);
  39. }
  40. /////////////////////////////////////////////////////////////////////////////
  41. // CEx55View drawing
  42. void CEx55View::OnDraw(CDC* pDC)
  43. {
  44. CEx55Doc* pDoc = GetDocument();
  45. ASSERT_VALID(pDoc);
  46. // TODO: add draw code for native data here
  47. int i;
  48. //绘制一组彩色点
  49.     pDC->TextOut(20,20,"point");
  50. pDC->SetPixel(100,20,RGB(255,0,0));
  51. pDC->SetPixel(110,20,RGB(0,255,0));
  52. pDC->SetPixel(120,20,RGB(0,0,255));
  53. pDC->SetPixel(130,20,RGB(255,255,0));
  54. pDC->SetPixel(140,20,RGB(255,0,255));
  55. pDC->SetPixel(150,20,RGB(0,255,255));
  56. pDC->SetPixel(160,20,RGB(0,0,0));
  57. //绘制一组彩色线
  58. //设置颜色表
  59. struct tagColor
  60. {
  61. int r,g,b;
  62. }color[7]={{255,0,0},{0,255,0},{0,0,255},{255,255,0},{255,0,255},{0,255,255},{0,0,0}};
  63. //定义两个指向画笔的指针
  64. CPen* pNewPen;
  65. CPen* pOldPen;
  66. for(i=0;i<7;i++)
  67. {
  68. pNewPen=new CPen; //构造画笔并初始化
  69. if(pNewPen->CreatePen(PS_SOLID,2,RGB(color[i].r,color[i].g,color[i].b)))
  70. {
  71. //把新创建的画笔选入设备描述表,同时保存原来的画笔
  72. pOldPen=pDC->SelectObject(pNewPen);
  73. //用新画笔绘图
  74. pDC->MoveTo(20,60+i*10);
  75. pDC->LineTo(160,60+i*10);
  76. //恢复设备描述表中的原有画笔
  77. pDC->SelectObject(pOldPen);
  78. }
  79. else
  80. {
  81. AfxMessageBox("Create Pen Error!");
  82. }
  83. delete pNewPen; //删除新画笔,以便再另外分配
  84. }
  85. //绘制圆弧
  86. for(i=0;i<8;i++)
  87. pDC->Arc(260-5*i,70-5*i,260+5*i,70+5*i,260+5*i,70,260+5*i,70);
  88. CBrush* pNewBrush;
  89. CBrush* pOldBrush;
  90. for(i=8;i>1;i--)
  91. {
  92. pNewBrush=new CBrush;
  93. if(pNewBrush->CreateSolidBrush(RGB(color[8-i].r,color[8-i].g,color[8-i].b)))
  94.    {
  95. pOldBrush=pDC->SelectObject(pNewBrush);
  96. pDC->Ellipse(260-10*i,200-5*i,260+10*i,200+5*i);
  97. pDC->SelectObject(pOldPen);
  98.    }
  99. delete pNewBrush;
  100. }
  101. //绘制矩形和圆角矩形
  102. pDC->Rectangle(190,270,250,310);
  103. pDC->RoundRect(260,270,330,310,30,20);
  104. }
  105. /////////////////////////////////////////////////////////////////////////////
  106. // CEx55View printing
  107. BOOL CEx55View::OnPreparePrinting(CPrintInfo* pInfo)
  108. {
  109. // default preparation
  110. return DoPreparePrinting(pInfo);
  111. }
  112. void CEx55View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  113. {
  114. // TODO: add extra initialization before printing
  115. }
  116. void CEx55View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  117. {
  118. // TODO: add cleanup after printing
  119. }
  120. /////////////////////////////////////////////////////////////////////////////
  121. // CEx55View diagnostics
  122. #ifdef _DEBUG
  123. void CEx55View::AssertValid() const
  124. {
  125. CView::AssertValid();
  126. }
  127. void CEx55View::Dump(CDumpContext& dc) const
  128. {
  129. CView::Dump(dc);
  130. }
  131. CEx55Doc* CEx55View::GetDocument() // non-debug version is inline
  132. {
  133. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEx55Doc)));
  134. return (CEx55Doc*)m_pDocument;
  135. }
  136. #endif //_DEBUG
  137. /////////////////////////////////////////////////////////////////////////////
  138. // CEx55View message handlers