MyDrawView.cpp
Upload User: szbeng
Upload Date: 2022-05-22
Package Size: 1883k
Code Size: 3k
Category:

Graph Drawing

Development Platform:

Visual C++

  1. // MyDrawView.cpp : implementation of the CMyDrawView class
  2. //
  3. #include "stdafx.h"
  4. #include "MyDraw.h"
  5. #include "MyDrawDoc.h"
  6. #include "MyDrawView.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CMyDrawView
  14. IMPLEMENT_DYNCREATE(CMyDrawView, CView)
  15. BEGIN_MESSAGE_MAP(CMyDrawView, CView)
  16. //{{AFX_MSG_MAP(CMyDrawView)
  17. ON_WM_LBUTTONDOWN()
  18. ON_WM_MOUSEMOVE()
  19. ON_WM_LBUTTONUP()
  20. //}}AFX_MSG_MAP
  21. // Standard printing commands
  22. ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  23. ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  24. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  25. END_MESSAGE_MAP()
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CMyDrawView construction/destruction
  28. CMyDrawView::CMyDrawView()
  29. {
  30. // TODO: add construction code here
  31. m_bDragging=false;
  32. m_hCross=AfxGetApp()->LoadStandardCursor(IDC_CROSS);
  33. }
  34. CMyDrawView::~CMyDrawView()
  35. {
  36. }
  37. BOOL CMyDrawView::PreCreateWindow(CREATESTRUCT& cs)
  38. {
  39. // TODO: Modify the Window class or styles here by modifying
  40. //  the CREATESTRUCT cs
  41. return CView::PreCreateWindow(cs);
  42. }
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CMyDrawView drawing
  45. void CMyDrawView::OnDraw(CDC* pDC)
  46. {
  47. CMyDrawDoc* pDoc = GetDocument();
  48. ASSERT_VALID(pDoc);
  49. // TODO: add draw code for native data here
  50. }
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CMyDrawView printing
  53. BOOL CMyDrawView::OnPreparePrinting(CPrintInfo* pInfo)
  54. {
  55. // default preparation
  56. return DoPreparePrinting(pInfo);
  57. }
  58. void CMyDrawView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  59. {
  60. // TODO: add extra initialization before printing
  61. }
  62. void CMyDrawView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  63. {
  64. // TODO: add cleanup after printing
  65. }
  66. /////////////////////////////////////////////////////////////////////////////
  67. // CMyDrawView diagnostics
  68. #ifdef _DEBUG
  69. void CMyDrawView::AssertValid() const
  70. {
  71. CView::AssertValid();
  72. }
  73. void CMyDrawView::Dump(CDumpContext& dc) const
  74. {
  75. CView::Dump(dc);
  76. }
  77. CMyDrawDoc* CMyDrawView::GetDocument() // non-debug version is inline
  78. {
  79. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDrawDoc)));
  80. return (CMyDrawDoc*)m_pDocument;
  81. }
  82. #endif //_DEBUG
  83. /////////////////////////////////////////////////////////////////////////////
  84. // CMyDrawView message handlers
  85. void CMyDrawView::OnLButtonDown(UINT nFlags, CPoint point) 
  86. {
  87. // TODO: Add your message handler code here and/or call default
  88. SetCapture();
  89. ::SetCursor(m_hCross);
  90. m_ptOrigin=point;
  91. m_bDragging=TRUE;
  92. CView::OnLButtonDown(nFlags, point);
  93. }
  94. void CMyDrawView::OnMouseMove(UINT nFlags, CPoint point) 
  95. {
  96. // TODO: Add your message handler code here and/or call default
  97. if(m_bDragging)
  98. {
  99. CClientDC dc(this);
  100. dc.MoveTo(m_ptOrigin);
  101. dc.LineTo(point);
  102. m_ptOrigin=point;
  103. }
  104. CView::OnMouseMove(nFlags, point);
  105. }
  106. void CMyDrawView::OnLButtonUp(UINT nFlags, CPoint point) 
  107. {
  108. // TODO: Add your message handler code here and/or call default
  109. if(m_bDragging)
  110. {
  111. m_bDragging=false;
  112. ReleaseCapture();
  113. }
  114. CView::OnLButtonUp(nFlags, point);
  115. }