1 //////////////////////////////////////////////
\r
3 // Definitions for the CView class
\r
6 #include "resource.h"
\r
9 CView::CView() : m_PenColor(RGB(0,0,0))
\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.CreatePen(PS_SOLID, 1, m_points.back().color);
\r
22 dcClient.MoveTo(m_points.back().x, m_points.back().y);
\r
23 dcClient.LineTo(x, y);
\r
26 void CView::OnDraw(CDC* pDC)
\r
28 if (m_points.size() > 0)
\r
30 bool bDraw = false; //Start with the pen up
\r
31 for (unsigned int i = 0 ; i < m_points.size(); i++)
\r
33 pDC->CreatePen(PS_SOLID, 1, m_points[i].color);
\r
35 pDC->LineTo(m_points[i].x, m_points[i].y);
\r
37 pDC->MoveTo(m_points[i].x, m_points[i].y);
\r
39 bDraw = m_points[i].PenDown;
\r
44 void CView::PreCreate(CREATESTRUCT &cs)
\r
46 // Set the extra style to provide a sunken edge
\r
47 cs.dwExStyle = WS_EX_CLIENTEDGE;
\r
50 void CView::PreRegisterClass(WNDCLASS &wc)
\r
52 // Set the background brush and cursor
\r
53 wc.hbrBackground = m_Brush;
\r
54 wc.lpszClassName = _T("Scribble Window");
\r
55 wc.hCursor = ::LoadCursor(GetApp()->GetInstanceHandle(), MAKEINTRESOURCE(IDC_CURSOR1));
\r
58 void CView::SetPen(COLORREF color)
\r
63 void CView::StorePoint(int x, int y, bool PenDown)
\r
68 P1.PenDown = PenDown;
\r
69 P1.color = m_PenColor;
\r
71 m_points.push_back(P1); //Add the point to the vector
\r
74 void CView::OnLButtonDown(LPARAM lParam)
\r
76 // Capture mouse input.
\r
79 StorePoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), true);
\r
82 void CView::OnLButtonUp(LPARAM lParam)
\r
85 //Release the capture on the mouse
\r
88 StorePoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), false);
\r
92 void CView::OnMouseMove(WPARAM wParam, LPARAM lParam)
\r
94 // hold down the left mouse button and move mouse to draw lines.
\r
95 if ( (wParam & MK_LBUTTON) && (GetCapture() == this) )
\r
97 DrawLine(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
\r
98 StorePoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), true);
\r
102 LRESULT CView::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
\r
106 case WM_LBUTTONDOWN:
\r
107 OnLButtonDown(lParam);
\r
111 OnMouseMove(wParam, lParam);
\r
115 OnLButtonUp(lParam);
\r
119 //Use the default message handling for remaining messages
\r
120 return WndProcDefault(uMsg, wParam, lParam);
\r