1 //////////////////////////////////////////////
\r
3 // Definitions for the CView class
\r
6 #include "resource.h"
\r
13 void CView::DrawLine(int x, int y)
\r
15 CClientDC dcClient(this);
\r
16 dcClient.MoveTo(m_points.back().x, m_points.back().y);
\r
17 dcClient.LineTo(x, y);
\r
20 void CView::OnDraw(CDC* pDC)
\r
22 if (m_points.size() > 0)
\r
24 bool bDraw = false; //Start with the pen up
\r
26 for (unsigned int i = 0 ; i < m_points.size(); i++)
\r
28 if (bDraw) pDC->LineTo(m_points[i].x, m_points[i].y);
\r
29 else pDC->MoveTo(m_points[i].x, m_points[i].y);
\r
30 bDraw = m_points[i].PenDown;
\r
35 void CView::StorePoint(int x, int y, bool PenDown)
\r
40 P1.PenDown = PenDown;
\r
42 m_points.push_back(P1); //Add the point to the vector
\r
45 void CView::OnLButtonDown(LPARAM lParam)
\r
47 // Capture mouse input.
\r
50 StorePoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), true);
\r
53 void CView::OnLButtonUp(LPARAM lParam)
\r
56 //Release the capture on the mouse
\r
59 StorePoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), false);
\r
63 void CView::OnMouseMove(WPARAM wParam, LPARAM lParam)
\r
65 // hold down the left mouse button and move mouse to draw lines.
\r
66 if ( (wParam & MK_LBUTTON) && (GetCapture() == this) )
\r
68 DrawLine(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
\r
69 StorePoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), true);
\r
73 LRESULT CView::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
\r
77 case WM_LBUTTONDOWN:
\r
78 OnLButtonDown(lParam);
\r
82 OnMouseMove(wParam, lParam);
\r
86 OnLButtonUp(lParam);
\r
89 // Note: No need to handle WM_DESTROY. The frame does this for us.
\r
91 // ::PostQuitMessage(0);
\r
95 //Use the default message handling for remaining messages
\r
96 return WndProcDefault(uMsg, wParam, lParam);
\r