exam3View.cpp
上传用户:z_mail1980
上传日期:2007-06-01
资源大小:647k
文件大小:5k
- // exam3View.cpp : implementation of the CExam3View class
- //
- #include "stdafx.h"
- #include "exam3.h"
- #include "exam3Doc.h"
- #include "exam3View.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CExam3View
- IMPLEMENT_DYNCREATE(CExam3View, CView)
- BEGIN_MESSAGE_MAP(CExam3View, CView)
- //{{AFX_MSG_MAP(CExam3View)
- ON_COMMAND(ID_NOMODE_DIALOG, OnNomodeDialog)
- ON_MESSAGE(WM_DELETE_POINT,OnDeletePoint)
- ON_UPDATE_COMMAND_UI(ID_NOMODE_DIALOG, OnUpdateNomodeDialog)
- ON_WM_LBUTTONUP()
- ON_WM_MOUSEMOVE()
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CExam3View construction/destruction
- CExam3View::CExam3View()
- {
- // TODO: add construction code here
- m_pPointInfo=NULL;
- }
- CExam3View::~CExam3View()
- {
- if(m_pPointInfo!=NULL)
- {
- m_pPointInfo->DestroyWindow();
- delete m_pPointInfo;
- }
- }
- BOOL CExam3View::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CExam3View drawing
- void CExam3View::OnDraw(CDC* pDC)
- {
- CExam3Doc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // TODO: add draw code for native data here
- CPen pen,*pOldPen;
- pen.CreatePen(PS_SOLID,1,RGB(255,0,0));
- pOldPen=pDC->SelectObject(&pen);
- pDC->SetBkMode(TRANSPARENT);
- pDC->SetTextColor(RGB(0,255,0));
- for(int i=0;i<m_arArray.GetSize();i++)
- {
- CPoint point=m_arArray.GetAt(i);
- pDC->MoveTo(point.x-5,point.y);
- pDC->LineTo(point.x+5,point.y);
- pDC->MoveTo(point.x,point.y-5);
- pDC->LineTo(point.x,point.y+5);
- CString szText;
- szText.Format("%d",i+1);
- pDC->TextOut(point.x+3,point.y+3,szText);
- }
- pDC->SelectObject(pOldPen);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CExam3View printing
- BOOL CExam3View::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CExam3View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CExam3View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- void CExam3View::OnInitialUpdate()
- {
- CView::OnInitialUpdate();
- m_pPointInfo=new CPointInfo(this);
- if(m_pPointInfo!=NULL)
- {
- m_pPointInfo->Create(IDD_MOUSE_POINT_DIALOG,this);
- m_pPointInfo->ShowWindow(SW_SHOW);
- }
- else
- MessageBox("创建CPointInfo对象失败!","错误",MB_OK);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CExam3View diagnostics
- #ifdef _DEBUG
- void CExam3View::AssertValid() const
- {
- CView::AssertValid();
- }
- void CExam3View::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CExam3Doc* CExam3View::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CExam3Doc)));
- return (CExam3Doc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CExam3View message handlers
- void CExam3View::OnNomodeDialog()
- {
- // TODO: Add your command handler code here
- if(m_pPointInfo!=NULL)
- {
- if(m_pPointInfo->IsWindowVisible())
- m_pPointInfo->ShowWindow(SW_HIDE);
- else
- m_pPointInfo->ShowWindow(SW_SHOW);
- }
- }
- void CExam3View::OnUpdateNomodeDialog(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->SetCheck(m_pPointInfo!=NULL&&m_pPointInfo->IsWindowVisible());
-
- }
- //看看再............................................................
- void CExam3View::OnLButtonUp(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- m_arArray.Add(point);
- CClientDC dc(this);
- CPen pen,*pOldPen;
- pen.CreatePen(PS_SOLID,1,RGB(255,0,0));
- pOldPen=dc.SelectObject(&pen);
- dc.MoveTo(point.x-5,point.y);
- dc.LineTo(point.x+5,point.y);
- dc.MoveTo(point.x,point.y-5);
- dc.LineTo(point.x,point.y+5);
- dc.SelectObject(pOldPen);
- dc.SetBkMode(TRANSPARENT);
- dc.SetTextColor(RGB(0,255,0));
- CString szText;
- szText.Format("%d",m_arArray.GetUpperBound()+1);
- dc.TextOut(point.x+3,point.y+3,szText);
- if(m_pPointInfo!=NULL)
- {
- m_pPointInfo->SendMessage(WM_ADD_POINT,0,MAKELPARAM((WORD)point.x,(WORD)point.y));
- }
- CView::OnLButtonUp(nFlags, point);
- }
- void CExam3View::OnMouseMove(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- if(m_pPointInfo!=NULL)
- {
- m_pPointInfo->SendMessage(WM_MOUSE_CHANGED,0,MAKELPARAM((WORD)point.x,(WORD)point.y));
- }
-
- CView::OnMouseMove(nFlags, point);
- }
- void CExam3View::OnDeletePoint(WPARAM wParam,LPARAM lParam)
- {
- int index=(int)lParam;
- if(index>=0&&index<m_arArray.GetSize())
- {
- m_arArray.RemoveAt(index);
- Invalidate();
- }
- }