home *** CD-ROM | disk | FTP | other *** search
- // drawview.cpp : implementation of the CDrawView class
- //
-
- #include "stdafx.h"
- #include "draw.h"
-
- #include "drawdoc.h"
- #include "drawview.h"
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CDrawView
-
- IMPLEMENT_DYNCREATE(CDrawView, CView)
-
- BEGIN_MESSAGE_MAP(CDrawView, CView)
- //{{AFX_MSG_MAP(CDrawView)
- ON_COMMAND(ID_DRAW_LINE, OnDrawLine)
- ON_COMMAND(ID_DRAW_CIRCLE, OnDrawCircle)
- ON_COMMAND(ID_DRAW_RECTANGLE, OnDrawRectangle)
- ON_COMMAND(ID_DRAW_CLEAR, OnDrawClear)
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CDrawView construction/destruction
-
- CDrawView::CDrawView()
- {
- // TODO: add construction code here
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- m_Shape = 0;
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
- }
-
- CDrawView::~CDrawView()
- {
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CDrawView drawing
-
- void CDrawView::OnDraw(CDC* pDC)
- {
- CDrawDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
-
- // TODO: add draw code for native data here
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- // Beep (to demonstrate that the OnDraw() function
- // was executed)
- // MessageBeep(-1);
-
-
- // Draw the line.
- if ( m_Shape == 1 )
- {
-
- // Create a new pen
- CPen NewPen (PS_SOLID, // The Style
- 10, // The width
- RGB(0,255,0) ); // The color
-
- // Set the new pen (and save the original pen)
- CPen* pOriginalPen = pDC->SelectObject ( &NewPen );
-
- pDC->MoveTo ( 10, 30 );
- pDC->LineTo ( 50, 30 );
-
- // Restore the original pen
- pDC->SelectObject ( pOriginalPen );
-
-
- // Draw a line with the original pen
- pDC->MoveTo ( 50, 30 );
- pDC->LineTo ( 80, 30 );
-
-
- }
-
-
- // Draw the circle
- if ( m_Shape == 2 )
- {
-
- // Create a new pen
- CPen NewPen (PS_SOLID, // The Style
- 40, // The width
- RGB(255, 0, 0) ); // The color
-
- // Set the new pen (and save the original pen)
- CPen* pOriginalPen = pDC->SelectObject ( &NewPen );
-
-
- // Create a rectangle object
- CRect theRect ( 20, 100, 120, 200 );
-
- // Draw the Circle
- pDC->Ellipse ( &theRect );
-
- // Restore the original pen
- pDC->SelectObject ( pOriginalPen );
-
-
- }
-
-
- // Draw the rectangle
- if ( m_Shape == 3 )
- {
- // Create a rectangle object
- CRgn theRgn;
- theRgn.CreateRectRgn ( 50, 100, 150, 200 );
-
- // Create a new brush
- CBrush MyBrush( HS_BDIAGONAL, RGB(0, 0, 255) );
-
- // Draw the rectangle
- pDC->FillRgn ( &theRgn, &MyBrush );
-
- }
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
-
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CDrawView printing
-
- BOOL CDrawView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
-
- void CDrawView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
-
- void CDrawView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CDrawView diagnostics
-
- #ifdef _DEBUG
- void CDrawView::AssertValid() const
- {
- CView::AssertValid();
- }
-
- void CDrawView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
-
- CDrawDoc* CDrawView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDrawDoc)));
- return (CDrawDoc*)m_pDocument;
- }
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // CDrawView message handlers
-
- void CDrawView::OnDrawLine()
- {
- // TODO: Add your command handler code here
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
-
- // Set the flag to 1 (Line)
- m_Shape = 1;
-
- // Trigger a call to OnDraw()
- Invalidate();
-
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
-
- }
-
- void CDrawView::OnDrawCircle()
- {
- // TODO: Add your command handler code here
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- // Set the flag to 2 (Circle)
- m_Shape = 2;
-
- // Trigger a call to OnDraw()
- Invalidate();
-
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
-
- }
-
- void CDrawView::OnDrawRectangle()
- {
- // TODO: Add your command handler code here
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- // Set the flag to 3 (Rectangle)
- m_Shape = 3;
-
- // Trigger a call to OnDraw()
- Invalidate();
-
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
- }
-
- void CDrawView::OnDrawClear()
- {
- // TODO: Add your command handler code here
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- // Set the flag to 0 (clear)
- m_Shape = 0;
-
- // Trigger a call to OnDraw()
- Invalidate();
-
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
- }
-