home *** CD-ROM | disk | FTP | other *** search
/ Master Visual C++ 1.5 / MASTERVC15.ISO / vcprog / original / ch34 / circleit / circlvw.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-10  |  3.6 KB  |  155 lines

  1. // circlvw.cpp : implementation of the CCircleitView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "circleit.h"
  6.  
  7. #include "circldoc.h"
  8. #include "circlvw.h"
  9.  
  10. #ifdef _DEBUG
  11. #undef THIS_FILE
  12. static char BASED_CODE THIS_FILE[] = __FILE__;
  13. #endif
  14.  
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CCircleitView
  17.  
  18. IMPLEMENT_DYNCREATE(CCircleitView, CView)
  19.  
  20. BEGIN_MESSAGE_MAP(CCircleitView, CView)
  21.     //{{AFX_MSG_MAP(CCircleitView)
  22.     ON_WM_LBUTTONDOWN()
  23.     //}}AFX_MSG_MAP
  24.     // Standard printing commands
  25.     ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  26.     ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  27. END_MESSAGE_MAP()
  28.  
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CCircleitView construction/destruction
  31.  
  32. CCircleitView::CCircleitView()
  33. {
  34.     // TODO: add construction code here
  35. }
  36.  
  37. CCircleitView::~CCircleitView()
  38. {
  39. }
  40.  
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CCircleitView drawing
  43.  
  44. void CCircleitView::OnDraw(CDC* pDC)
  45. {
  46.     CCircleitDoc* pDoc = GetDocument();
  47.     ASSERT_VALID(pDoc);
  48.  
  49.     // TODO: add draw code for native data here
  50.  
  51.  
  52.      //////////////////////
  53.      // MY CODE STARTS HERE
  54.      //////////////////////
  55.  
  56.    CString MyString =
  57.        "Push the left button of the mouse to draw a circle";
  58.  
  59.     pDC->TextOut( 10,
  60.                   20,
  61.                   MyString );
  62.  
  63.  
  64.  
  65.      ////////////////////
  66.      // MY CODE ENDS HERE
  67.      ////////////////////
  68.  
  69. }
  70.  
  71. /////////////////////////////////////////////////////////////////////////////
  72. // CCircleitView printing
  73.  
  74. BOOL CCircleitView::OnPreparePrinting(CPrintInfo* pInfo)
  75. {
  76.     // default preparation
  77.     return DoPreparePrinting(pInfo);
  78. }
  79.  
  80. void CCircleitView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  81. {
  82.     // TODO: add extra initialization before printing
  83. }
  84.  
  85. void CCircleitView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  86. {
  87.     // TODO: add cleanup after printing
  88. }
  89.  
  90. /////////////////////////////////////////////////////////////////////////////
  91. // CCircleitView diagnostics
  92.  
  93. #ifdef _DEBUG
  94. void CCircleitView::AssertValid() const
  95. {
  96.     CView::AssertValid();
  97. }
  98.  
  99. void CCircleitView::Dump(CDumpContext& dc) const
  100. {
  101.     CView::Dump(dc);
  102. }
  103.  
  104. CCircleitDoc* CCircleitView::GetDocument() // non-debug version is inline
  105. {
  106.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCircleitDoc)));
  107.     return (CCircleitDoc*)m_pDocument;
  108. }
  109. #endif //_DEBUG
  110.  
  111. /////////////////////////////////////////////////////////////////////////////
  112. // CCircleitView message handlers
  113.  
  114. void CCircleitView::OnLButtonDown(UINT nFlags, CPoint point)
  115. {
  116.     // TODO: Add your message handler code here and/or call default
  117.  
  118.  
  119.      //////////////////////
  120.      // MY CODE STARTS HERE
  121.      //////////////////////
  122.  
  123.     CDC* pDC = GetDC();
  124.  
  125.        // Create a new pen
  126.        CPen NewPen (PS_SOLID,            // The Style
  127.                     10,                  // The width
  128.                     RGB(255, 0, 0) );    // The color
  129.  
  130.        // Set the new pen (and save the original pen)
  131.        CPen* pOriginalPen = pDC->SelectObject ( &NewPen );
  132.  
  133.  
  134.        // Create a rectangle object
  135.        CRect theRect ( point.x-20,
  136.                        point.y-20,
  137.                        point.x+20,
  138.                        point.y+20 );
  139.  
  140.        // Draw the Circle
  141.        pDC->Ellipse ( &theRect );
  142.  
  143.        // Restore the original pen
  144.         pDC->SelectObject ( pOriginalPen );
  145.  
  146.  
  147.     ReleaseDC (pDC);
  148.  
  149.      ////////////////////
  150.      // MY CODE ENDS HERE
  151.      ////////////////////
  152.  
  153.     CView::OnLButtonDown(nFlags, point);
  154. }
  155.