1 //////////////////////////////////////////////
\r
3 // Definitions for the CView class
\r
12 void CView::DrawLine(int x, int y)
\r
14 CClientDC dcClient(this);
\r
15 dcClient.MoveTo(m_points.back().x, m_points.back().y);
\r
16 dcClient.LineTo(x, y);
\r
19 void CView::OnDraw(CDC* pDC)
\r
21 if (m_points.size() > 0)
\r
23 bool bDraw = false; //Start with the pen up
\r
25 for (unsigned int i = 0 ; i < m_points.size(); i++)
\r
27 if (bDraw) pDC->LineTo(m_points[i].x, m_points[i].y);
\r
28 else pDC->MoveTo(m_points[i].x, m_points[i].y);
\r
29 bDraw = m_points[i].PenDown;
\r
34 void CView::StorePoint(int x, int y, bool PenDown)
\r
39 P1.PenDown = PenDown;
\r
41 m_points.push_back(P1); //Add the point to the vector
\r
44 void CView::OnLButtonDown(LPARAM lParam)
\r
46 // Capture mouse input.
\r
49 StorePoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), true);
\r
52 void CView::OnLButtonUp(LPARAM lParam)
\r
55 //Release the capture on the mouse
\r
58 StorePoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), false);
\r
62 void CView::OnMouseMove(WPARAM wParam, LPARAM lParam)
\r
64 // hold down the left mouse button and move mouse to draw lines.
\r
65 if ( (wParam & MK_LBUTTON) && (GetCapture() == this) )
\r
67 DrawLine(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
\r
68 StorePoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), true);
\r
72 LRESULT CView::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
\r
76 case WM_LBUTTONDOWN:
\r
77 OnLButtonDown(lParam);
\r
81 OnMouseMove(wParam, lParam);
\r
85 OnLButtonUp(lParam);
\r
89 //End the program when window is destroyed
\r
90 ::PostQuitMessage(0);
\r
94 //Use the default message handling for remaining messages
\r
95 return WndProcDefault(uMsg, wParam, lParam);
\r