MOUSEDRAWTESTVIEW.CPP
上传用户:cjd055
上传日期:2013-04-01
资源大小:608k
文件大小:5k
源码类别:

交通/航空行业

开发平台:

Visual C++

  1. // MouseDrawtestView.cpp : implementation of the CMouseDrawtestView class
  2. //
  3. #include "stdafx.h"
  4. #include "MouseDrawtest.h"
  5. #include "MouseDrawtestDoc.h"
  6. #include "MouseDrawtestView.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CMouseDrawtestView
  14. IMPLEMENT_DYNCREATE(CMouseDrawtestView, CScrollView)
  15. BEGIN_MESSAGE_MAP(CMouseDrawtestView, CScrollView)
  16. //{{AFX_MSG_MAP(CMouseDrawtestView)
  17. ON_WM_LBUTTONDOWN()
  18. ON_WM_MOUSEMOVE()
  19. ON_WM_LBUTTONUP()
  20. ON_WM_SETCURSOR()
  21. //}}AFX_MSG_MAP
  22. // Standard printing commands
  23. ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
  24. ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
  25. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
  26. END_MESSAGE_MAP()
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CMouseDrawtestView construction/destruction
  29. CMouseDrawtestView::CMouseDrawtestView()
  30. {
  31. // TODO: add construction code here
  32. m_Drawing=FALSE;
  33. m_Cursor=IDC_MYARROW;
  34. m_DrawOver=FALSE;
  35. }
  36. CMouseDrawtestView::~CMouseDrawtestView()
  37. {
  38. }
  39. BOOL CMouseDrawtestView::PreCreateWindow(CREATESTRUCT& cs)
  40. {
  41. // TODO: Modify the Window class or styles here by modifying
  42. //  the CREATESTRUCT cs
  43. return CScrollView::PreCreateWindow(cs);
  44. }
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CMouseDrawtestView drawing
  47. void CMouseDrawtestView::OnDraw(CDC* pDC)
  48. {
  49. CMouseDrawtestDoc* pDoc = GetDocument();
  50. ASSERT_VALID(pDoc);
  51. // TODO: add draw code for native data here
  52. if(m_Drawing)
  53. {
  54. pDC->SetROP2(R2_NOT);
  55. pDC->SelectObject(GetStockObject(NULL_BRUSH));
  56. pDC->Rectangle(m_Rect);
  57. return;
  58. }
  59. if(m_DrawOver)
  60. {
  61. pDC->SelectObject(GetStockObject(NULL_BRUSH));
  62. pDC->Rectangle(m_Rect);
  63. m_DrawOver=FALSE;
  64. return;
  65. }
  66. pDC->SelectObject(GetStockObject(NULL_BRUSH));
  67. pDC->Rectangle(m_Rect);
  68. }
  69. void CMouseDrawtestView::OnInitialUpdate()
  70. {
  71. CScrollView::OnInitialUpdate();
  72. CSize sizeTotal;
  73. // TODO: calculate the total size of this view
  74. sizeTotal.cx = sizeTotal.cy = 100;
  75. SetScrollSizes(MM_TEXT, sizeTotal);
  76. }
  77. /////////////////////////////////////////////////////////////////////////////
  78. // CMouseDrawtestView printing
  79. BOOL CMouseDrawtestView::OnPreparePrinting(CPrintInfo* pInfo)
  80. {
  81. // default preparation
  82. return DoPreparePrinting(pInfo);
  83. }
  84. void CMouseDrawtestView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  85. {
  86. // TODO: add extra initialization before printing
  87. }
  88. void CMouseDrawtestView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  89. {
  90. // TODO: add cleanup after printing
  91. }
  92. /////////////////////////////////////////////////////////////////////////////
  93. // CMouseDrawtestView diagnostics
  94. #ifdef _DEBUG
  95. void CMouseDrawtestView::AssertValid() const
  96. {
  97. CScrollView::AssertValid();
  98. }
  99. void CMouseDrawtestView::Dump(CDumpContext& dc) const
  100. {
  101. CScrollView::Dump(dc);
  102. }
  103. CMouseDrawtestDoc* CMouseDrawtestView::GetDocument() // non-debug version is inline
  104. {
  105. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMouseDrawtestDoc)));
  106. return (CMouseDrawtestDoc*)m_pDocument;
  107. }
  108. #endif //_DEBUG
  109. /////////////////////////////////////////////////////////////////////////////
  110. // CMouseDrawtestView message handlers
  111. void CMouseDrawtestView::OnLButtonDown(UINT nFlags, CPoint point) 
  112. {
  113. // TODO: Add your message handler code here and/or call default
  114. m_Rect.top=point.y;
  115. m_Rect.left=point.x;
  116. m_Rect.right=point.x;
  117. m_Rect.bottom=point.y;
  118. Invalidate();
  119. SetCapture();
  120. SetCursor(AfxGetApp()->LoadCursor(IDC_MYCROSS));
  121. // m_Cursor=IDC_MYCROSS;
  122. m_Drawing=TRUE;
  123. CScrollView::OnLButtonDown(nFlags, point);
  124. }
  125. void CMouseDrawtestView::OnMouseMove(UINT nFlags, CPoint point) 
  126. {
  127. // TODO: Add your message handler code here and/or call default
  128. if(m_Drawing)
  129. {
  130. CSize sizeTotal;
  131. // TODO: calculate the total size of this view
  132. sizeTotal.cx = point.x+20;
  133. sizeTotal.cy = point.y+20;
  134. SetScrollSizes(MM_TEXT, sizeTotal);
  135. SetCursor(AfxGetApp()->LoadCursor(IDC_MYCROSS));
  136. // m_Cursor=IDC_MYCROSS;
  137. //擦除原有矩形:
  138. Invalidate();
  139. m_Rect.right=point.x;
  140. m_Rect.bottom=point.y;
  141. //重绘矩形:
  142. Invalidate();
  143. }
  144. CScrollView::OnMouseMove(nFlags, point);
  145. }
  146. void CMouseDrawtestView::OnLButtonUp(UINT nFlags, CPoint point) 
  147. {
  148. // TODO: Add your message handler code here and/or call default
  149. if(m_Drawing)
  150. {
  151. Invalidate();
  152. m_Rect.right=point.x;
  153. m_Rect.bottom=point.y;
  154. ReleaseCapture();
  155. m_Cursor=IDC_MYARROW;
  156. m_Drawing=FALSE;
  157. m_DrawOver=TRUE;
  158. Invalidate();
  159. }
  160. CScrollView::OnLButtonUp(nFlags, point);
  161. }
  162. BOOL CMouseDrawtestView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
  163. {
  164. // TODO: Add your message handler code here and/or call default
  165. HCURSOR hc=AfxGetApp()->LoadCursor(m_Cursor);
  166. SetCursor(hc);
  167. return TRUE;
  168. // return CScrollView::OnSetCursor(pWnd, nHitTest, message);
  169. }