exam3View.cpp
上传用户:z_mail1980
上传日期:2007-06-01
资源大小:647k
文件大小:5k
源码类别:

SNMP编程

开发平台:

Visual C++

  1. // exam3View.cpp : implementation of the CExam3View class
  2. //
  3. #include "stdafx.h"
  4. #include "exam3.h"
  5. #include "exam3Doc.h"
  6. #include "exam3View.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CExam3View
  14. IMPLEMENT_DYNCREATE(CExam3View, CView)
  15. BEGIN_MESSAGE_MAP(CExam3View, CView)
  16. //{{AFX_MSG_MAP(CExam3View)
  17. ON_COMMAND(ID_NOMODE_DIALOG, OnNomodeDialog)
  18. ON_MESSAGE(WM_DELETE_POINT,OnDeletePoint)
  19. ON_UPDATE_COMMAND_UI(ID_NOMODE_DIALOG, OnUpdateNomodeDialog)
  20. ON_WM_LBUTTONUP()
  21. ON_WM_MOUSEMOVE()
  22. //}}AFX_MSG_MAP
  23. // Standard printing commands
  24. ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  25. ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  26. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  27. END_MESSAGE_MAP()
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CExam3View construction/destruction
  30. CExam3View::CExam3View()
  31. {
  32. // TODO: add construction code here
  33. m_pPointInfo=NULL;
  34. }
  35. CExam3View::~CExam3View()
  36. {
  37. if(m_pPointInfo!=NULL)
  38. {
  39. m_pPointInfo->DestroyWindow();
  40. delete m_pPointInfo;
  41. }
  42. }
  43. BOOL CExam3View::PreCreateWindow(CREATESTRUCT& cs)
  44. {
  45. // TODO: Modify the Window class or styles here by modifying
  46. //  the CREATESTRUCT cs
  47. return CView::PreCreateWindow(cs);
  48. }
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CExam3View drawing
  51. void CExam3View::OnDraw(CDC* pDC)
  52. {
  53. CExam3Doc* pDoc = GetDocument();
  54. ASSERT_VALID(pDoc);
  55. // TODO: add draw code for native data here
  56. CPen pen,*pOldPen;
  57. pen.CreatePen(PS_SOLID,1,RGB(255,0,0));
  58. pOldPen=pDC->SelectObject(&pen);
  59.     pDC->SetBkMode(TRANSPARENT);
  60. pDC->SetTextColor(RGB(0,255,0));
  61. for(int i=0;i<m_arArray.GetSize();i++)
  62. {
  63. CPoint point=m_arArray.GetAt(i);
  64. pDC->MoveTo(point.x-5,point.y);
  65. pDC->LineTo(point.x+5,point.y);
  66. pDC->MoveTo(point.x,point.y-5);
  67. pDC->LineTo(point.x,point.y+5);
  68. CString szText;
  69. szText.Format("%d",i+1);
  70. pDC->TextOut(point.x+3,point.y+3,szText);
  71. }
  72. pDC->SelectObject(pOldPen);
  73. }
  74. /////////////////////////////////////////////////////////////////////////////
  75. // CExam3View printing
  76. BOOL CExam3View::OnPreparePrinting(CPrintInfo* pInfo)
  77. {
  78. // default preparation
  79. return DoPreparePrinting(pInfo);
  80. }
  81. void CExam3View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  82. {
  83. // TODO: add extra initialization before printing
  84. }
  85. void CExam3View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  86. {
  87. // TODO: add cleanup after printing
  88. }
  89. void CExam3View::OnInitialUpdate()
  90. {
  91. CView::OnInitialUpdate();
  92. m_pPointInfo=new CPointInfo(this);
  93. if(m_pPointInfo!=NULL)
  94. {
  95. m_pPointInfo->Create(IDD_MOUSE_POINT_DIALOG,this);
  96. m_pPointInfo->ShowWindow(SW_SHOW);
  97. }
  98. else
  99. MessageBox("创建CPointInfo对象失败!","错误",MB_OK);
  100. }
  101. /////////////////////////////////////////////////////////////////////////////
  102. // CExam3View diagnostics
  103. #ifdef _DEBUG
  104. void CExam3View::AssertValid() const
  105. {
  106. CView::AssertValid();
  107. }
  108. void CExam3View::Dump(CDumpContext& dc) const
  109. {
  110. CView::Dump(dc);
  111. }
  112. CExam3Doc* CExam3View::GetDocument() // non-debug version is inline
  113. {
  114. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CExam3Doc)));
  115. return (CExam3Doc*)m_pDocument;
  116. }
  117. #endif //_DEBUG
  118. /////////////////////////////////////////////////////////////////////////////
  119. // CExam3View message handlers
  120. void CExam3View::OnNomodeDialog() 
  121. {
  122. // TODO: Add your command handler code here
  123. if(m_pPointInfo!=NULL)
  124. {
  125. if(m_pPointInfo->IsWindowVisible())
  126. m_pPointInfo->ShowWindow(SW_HIDE);
  127. else
  128. m_pPointInfo->ShowWindow(SW_SHOW);
  129. }
  130. }
  131. void CExam3View::OnUpdateNomodeDialog(CCmdUI* pCmdUI) 
  132. {
  133. // TODO: Add your command update UI handler code here
  134. pCmdUI->SetCheck(m_pPointInfo!=NULL&&m_pPointInfo->IsWindowVisible());
  135. }
  136. //看看再............................................................
  137. void CExam3View::OnLButtonUp(UINT nFlags, CPoint point) 
  138. {
  139. // TODO: Add your message handler code here and/or call default
  140. m_arArray.Add(point);
  141. CClientDC dc(this);
  142. CPen pen,*pOldPen;
  143. pen.CreatePen(PS_SOLID,1,RGB(255,0,0));
  144. pOldPen=dc.SelectObject(&pen);
  145. dc.MoveTo(point.x-5,point.y);
  146. dc.LineTo(point.x+5,point.y);
  147. dc.MoveTo(point.x,point.y-5);
  148. dc.LineTo(point.x,point.y+5);
  149. dc.SelectObject(pOldPen);
  150. dc.SetBkMode(TRANSPARENT);
  151. dc.SetTextColor(RGB(0,255,0));
  152. CString szText;
  153.     szText.Format("%d",m_arArray.GetUpperBound()+1);
  154. dc.TextOut(point.x+3,point.y+3,szText);
  155. if(m_pPointInfo!=NULL)
  156. {
  157. m_pPointInfo->SendMessage(WM_ADD_POINT,0,MAKELPARAM((WORD)point.x,(WORD)point.y));
  158. }
  159. CView::OnLButtonUp(nFlags, point);
  160. }
  161. void CExam3View::OnMouseMove(UINT nFlags, CPoint point) 
  162. {
  163. // TODO: Add your message handler code here and/or call default
  164. if(m_pPointInfo!=NULL)
  165. {
  166. m_pPointInfo->SendMessage(WM_MOUSE_CHANGED,0,MAKELPARAM((WORD)point.x,(WORD)point.y));
  167. }
  168. CView::OnMouseMove(nFlags, point);
  169. }
  170. void CExam3View::OnDeletePoint(WPARAM wParam,LPARAM lParam)
  171. {
  172. int index=(int)lParam;
  173. if(index>=0&&index<m_arArray.GetSize())
  174. {
  175. m_arArray.RemoveAt(index);
  176. Invalidate();
  177. }
  178. }