画图View.cpp
上传用户:tjxl888
上传日期:2022-07-19
资源大小:7312k
文件大小:3k
源码类别:

绘图程序

开发平台:

Visual C++

  1. // 画图View.cpp : C画图View 类的实现
  2. //
  3. #include "stdafx.h"
  4. #include "画图.h"
  5. #include "画图Doc.h"
  6. #include "画图View.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #endif
  10. // C画图View
  11. IMPLEMENT_DYNCREATE(C画图View, CView)
  12. BEGIN_MESSAGE_MAP(C画图View, CView)
  13. // 标准打印命令
  14. ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
  15. ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
  16. ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CView::OnFilePrintPreview)
  17. ON_WM_LBUTTONDOWN()
  18. ON_WM_LBUTTONUP()
  19. ON_WM_MOUSEMOVE()
  20. END_MESSAGE_MAP()
  21. // C画图View 构造/析构
  22. C画图View::C画图View()
  23. : m_point(0)
  24. , m_b(false)
  25. {
  26. m_point=0;// TODO: 在此处添加构造代码
  27. }
  28. C画图View::~C画图View()
  29. {
  30. }
  31. BOOL C画图View::PreCreateWindow(CREATESTRUCT& cs)
  32. {
  33. // TODO: 在此处通过修改
  34. //  CREATESTRUCT cs 来修改窗口类或样式
  35. return CView::PreCreateWindow(cs);
  36. }
  37. // C画图View 绘制
  38. void C画图View::OnDraw(CDC* /*pDC*/)
  39. {
  40. C画图Doc* pDoc = GetDocument();
  41. ASSERT_VALID(pDoc);
  42. if (!pDoc)
  43. return;
  44. // TODO: 在此处为本机数据添加绘制代码
  45. }
  46. // C画图View 打印
  47. BOOL C画图View::OnPreparePrinting(CPrintInfo* pInfo)
  48. {
  49. // 默认准备
  50. return DoPreparePrinting(pInfo);
  51. }
  52. void C画图View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  53. {
  54. // TODO: 添加额外的打印前进行的初始化过程
  55. }
  56. void C画图View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  57. {
  58. // TODO: 添加打印后进行的清理过程
  59. }
  60. // C画图View 诊断
  61. #ifdef _DEBUG
  62. void C画图View::AssertValid() const
  63. {
  64. CView::AssertValid();
  65. }
  66. void C画图View::Dump(CDumpContext& dc) const
  67. {
  68. CView::Dump(dc);
  69. }
  70. C画图Doc* C画图View::GetDocument() const // 非调试版本是内联的
  71. {
  72. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(C画图Doc)));
  73. return (C画图Doc*)m_pDocument;
  74. }
  75. #endif //_DEBUG
  76. // C画图View 消息处理程序
  77. void C画图View::OnLButtonDown(UINT nFlags, CPoint point)
  78. {
  79. m_point=point;// TODO: 在此添加消息处理程序代码和/或调用默认值
  80.     m_b=TRUE;
  81. CView::OnLButtonDown(nFlags, point);
  82. }
  83. void C画图View::OnLButtonUp(UINT nFlags, CPoint point)
  84. {
  85. // TODO: 在此添加消息处理程序代码和/或调用默认值
  86.     /*CDC *pDC=GetDC();
  87. pDC->MoveTo(m_point);
  88. pDC->LineTo(point);
  89. ReleaseDC(pDC);*/
  90.     /*CBitmap bitmap;
  91. bitmap.LoadBitmap(IDB_BITMAP1);
  92. CBrush brush(&bitmap);
  93. dc.FillRect(CRect(m_point,point),&brush);*/
  94. /*CClientDC dc(this);
  95. CBrush brush(RGB(0,255,0));
  96. dc.Rectangle(CRect(m_point,point));
  97. dc.SelectObject(brush);*/
  98.     m_b=FALSE;
  99. CView::OnLButtonUp(nFlags, point);
  100. }
  101. void C画图View::OnMouseMove(UINT nFlags, CPoint point)
  102. {
  103. CClientDC dc(this);
  104. CPen pen(PS_SOLID,1,RGB(255,0,0));
  105. CPen *pOldpen=dc.SelectObject(&pen);
  106. if(m_b==TRUE)
  107. {
  108. dc.MoveTo(m_point);
  109. dc.LineTo(point);
  110. m_point=point;
  111. }
  112. dc.SelectObject(pOldpen);
  113. // TODO: 在此添加消息处理程序代码和/或调用默认值
  114. CView::OnMouseMove(nFlags, point);
  115. }