1 //////////////////////////////////////////////
\r
3 // Definitions for the CView class
\r
6 #include "resource.h"
\r
11 m_Brush.CreateSolidBrush(RGB(255,255,230));
\r
18 void CView::DrawLine(int x, int y)
\r
20 CClientDC dcClient(this);
\r
21 dcClient.MoveTo(m_points.back().x, m_points.back().y);
\r
22 dcClient.LineTo(x, y);
\r
25 void CView::OnDraw(CDC* pDC)
\r
27 if (m_points.size() > 0)
\r
29 bool bDraw = false; //Start with the pen up
\r
31 for (unsigned int i = 0 ; i < m_points.size(); i++)
\r
33 if (bDraw) pDC->LineTo(m_points[i].x, m_points[i].y);
\r
34 else pDC->MoveTo(m_points[i].x, m_points[i].y);
\r
35 bDraw = m_points[i].PenDown;
\r
40 void CView::PreCreate(CREATESTRUCT &cs)
\r
42 // Set the extra style to provide a sunken edge
\r
43 cs.dwExStyle = WS_EX_CLIENTEDGE;
\r
46 void CView::PreRegisterClass(WNDCLASS &wc)
\r
48 // Set the background brush and cursor
\r
49 wc.hbrBackground = m_Brush;
\r
50 wc.lpszClassName = _T("Scribble Window");
\r
51 wc.hCursor = ::LoadCursor(GetApp()->GetInstanceHandle(), MAKEINTRESOURCE(IDC_CURSOR1));
\r
54 void CView::StorePoint(int x, int y, bool PenDown)
\r
59 P1.PenDown = PenDown;
\r
61 m_points.push_back(P1); //Add the point to the vector
\r
64 void CView::OnLButtonDown(LPARAM lParam)
\r
66 // Capture mouse input.
\r
69 StorePoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), true);
\r
72 void CView::OnLButtonUp(LPARAM lParam)
\r
75 //Release the capture on the mouse
\r
78 StorePoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), false);
\r
82 void CView::OnMouseMove(WPARAM wParam, LPARAM lParam)
\r
84 // hold down the left mouse button and move mouse to draw lines.
\r
85 if ( (wParam & MK_LBUTTON) && (GetCapture() == this) )
\r
87 DrawLine(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
\r
88 StorePoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), true);
\r
92 LRESULT CView::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
\r
96 case WM_LBUTTONDOWN:
\r
97 OnLButtonDown(lParam);
\r
101 OnMouseMove(wParam, lParam);
\r
105 OnLButtonUp(lParam);
\r
109 //Use the default message handling for remaining messages
\r
110 return WndProcDefault(uMsg, wParam, lParam);
\r