// testView.cpp : implementation of the CTestView class // #include "stdafx.h" #include "test.h" #include "testDoc.h" #include "testView.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CTestView IMPLEMENT_DYNCREATE(CTestView, CView) BEGIN_MESSAGE_MAP(CTestView, CView) //{{AFX_MSG_MAP(CTestView) ON_COMMAND(ID_Arc, OnArc) ON_COMMAND(ID_Line, OnLine) ON_COMMAND(ID_Rectangle, OnRectangle) ON_UPDATE_COMMAND_UI(ID_Arc, OnUpdateArc) ON_UPDATE_COMMAND_UI(ID_Line, OnUpdateLine) ON_UPDATE_COMMAND_UI(ID_Rectangle, OnUpdateRectangle) ON_COMMAND(ID_Incolor, OnIncolor) ON_COMMAND(ID_Linecolor, OnLinecolor) ON_WM_LBUTTONDOWN() 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() ///////////////////////////////////////////////////////////////////////////// // CTestView construction/destruction CTestView::CTestView() { // TODO: add construction code here arcflag = false; lineflag = false; reflag = false; incolor = RGB(0,255,255); linecolor = RGB(0,255,255); } CTestView::~CTestView() { } BOOL CTestView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CTestView drawing void CTestView::OnDraw(CDC* pDC) { CTestDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here CPen line(PS_SOLID,1,linecolor); pDC->SelectObject(&line); CBrush brush(HS_DIAGCROSS,incolor); pDC->SelectObject(&brush); if(arcflag) pDC->Arc(start.x,start.y,end.x,end.y,start.x,start.y,end.x,end.y); if(lineflag) { pDC->MoveTo(start); pDC->LineTo(end); } if(reflag) pDC->Rectangle(start.x,start.y,end.x,end.y); } ///////////////////////////////////////////////////////////////////////////// // CTestView printing BOOL CTestView::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); } void CTestView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void CTestView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } ///////////////////////////////////////////////////////////////////////////// // CTestView diagnostics #ifdef _DEBUG void CTestView::AssertValid() const { CView::AssertValid(); } void CTestView::Dump(CDumpContext& dc) const { CView::Dump(dc); } CTestDoc* CTestView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTestDoc))); return (CTestDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CTestView message handlers void CTestView::OnArc() { // TODO: Add your command handler code here lineflag = false; reflag = false; arcflag = !arcflag; } void CTestView::OnLine() { // TODO: Add your command handler code here reflag = false; arcflag = false; lineflag = !lineflag; } void CTestView::OnRectangle() { // TODO: Add your command handler code here arcflag = false; lineflag = false; reflag = !reflag; } void CTestView::OnUpdateArc(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here pCmdUI->SetCheck(arcflag); } void CTestView::OnUpdateLine(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here pCmdUI->SetCheck(lineflag); } void CTestView::OnUpdateRectangle(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here pCmdUI->SetCheck(reflag); } void CTestView::OnIncolor() { // TODO: Add your command handler code here COLORREF init(RGB(125,255,0)); CColorDialog dlg(init); if(IDOK == dlg.DoModal()) incolor = dlg.GetColor(); } void CTestView::OnLinecolor() { // TODO: Add your command handler code here COLORREF init(RGB(125,255,0)); CColorDialog dlg(init); if(IDOK == dlg.DoModal()) linecolor = dlg.GetColor(); } void CTestView::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default start = point; flag = true; CView::OnLButtonDown(nFlags, point); } void CTestView::OnLButtonUp(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default flag = false; end = point; Invalidate(); CView::OnLButtonUp(nFlags, point); } void CTestView::OnMouseMove(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default if(flag == true) { end = point; Invalidate(); } CView::OnMouseMove(nFlags, point); }