home *** CD-ROM | disk | FTP | other *** search
/ Master Visual C++ 1.5 / MASTERVC15.ISO / vcprog / original / ch17 / drawit / drawivw.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-24  |  2.3 KB  |  109 lines

  1. // drawivw.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "drawit.h"
  6. #include "drawivw.h"
  7.  
  8. #ifdef _DEBUG
  9. #undef THIS_FILE
  10. static char BASED_CODE THIS_FILE[] = __FILE__;
  11. #endif
  12.  
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CDrawitView
  15.  
  16. IMPLEMENT_DYNCREATE(CDrawitView, CFormView)
  17.  
  18. CDrawitView::CDrawitView()
  19.     : CFormView(CDrawitView::IDD)
  20. {
  21.     //{{AFX_DATA_INIT(CDrawitView)
  22.     m_NumberOfMoves = 0;
  23.     //}}AFX_DATA_INIT
  24. }
  25.  
  26. CDrawitView::~CDrawitView()
  27. {
  28. }
  29.  
  30. void CDrawitView::DoDataExchange(CDataExchange* pDX)
  31. {
  32.     CFormView::DoDataExchange(pDX);
  33.     //{{AFX_DATA_MAP(CDrawitView)
  34.     DDX_Text(pDX, IDC_EDIT1, m_NumberOfMoves);
  35.     //}}AFX_DATA_MAP
  36. }
  37.  
  38.  
  39. BEGIN_MESSAGE_MAP(CDrawitView, CFormView)
  40.     //{{AFX_MSG_MAP(CDrawitView)
  41.     ON_WM_MOUSEMOVE()
  42.     ON_WM_LBUTTONDOWN()
  43.     //}}AFX_MSG_MAP
  44. END_MESSAGE_MAP()
  45.  
  46.  
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CDrawitView message handlers
  49.  
  50.  
  51. void CDrawitView::OnMouseMove(UINT nFlags, CPoint point)
  52. {
  53.     // TODO: Add your message handler code here and/or call default
  54.  
  55.      //////////////////////
  56.      // MY CODE STARTS HERE
  57.      //////////////////////
  58.  
  59.  
  60.     if ( (nFlags & MK_LBUTTON) == MK_LBUTTON )
  61.        {
  62.        // This code is executed provided that:
  63.        // 1. The mouse moved inside the client area.
  64.        // 2. The left button of the mouse was pushed down.
  65.  
  66.         // Create a dc object
  67.         CClientDC dc(this);
  68.  
  69.        // dc.SetPixel(point.x, point.y, RGB(0,0,0));
  70.  
  71.        dc.MoveTo(m_PrevX, m_PrevY);
  72.        dc.LineTo(point.x, point.y);
  73.        m_PrevX = point.x;
  74.        m_PrevY = point.y;
  75.  
  76.        // Increment the counter
  77.        m_NumberOfMoves++;
  78.  
  79.        // Update the screen
  80.        UpdateData(FALSE);
  81.  
  82.        }   
  83.        
  84.      ////////////////////
  85.      // MY CODE ENDS HERE
  86.      ////////////////////
  87.     
  88.     CFormView::OnMouseMove(nFlags, point);
  89. }
  90.  
  91. void CDrawitView::OnLButtonDown(UINT nFlags, CPoint point)
  92. {
  93.     // TODO: Add your message handler code here and/or call default
  94.  
  95.      //////////////////////
  96.      // MY CODE STARTS HERE
  97.      //////////////////////
  98.  
  99.      m_PrevX = point.x;
  100.  
  101.      m_PrevY = point.y;
  102.  
  103.      ////////////////////
  104.      // MY CODE ENDS HERE
  105.      ////////////////////
  106.     
  107.     CFormView::OnLButtonDown(nFlags, point);
  108. }
  109.