Commit before breaking everything
[matches/honours.git] / research / transmission_spectroscopy / TOF / Win32++ / tutorials / Tutorial6 / View.cpp
1 //////////////////////////////////////////////\r
2 // View.cpp\r
3 //  Definitions for the CView class\r
4 \r
5 #include "view.h"\r
6 #include "resource.h"\r
7 \r
8 \r
9 CView::CView()\r
10 {\r
11         m_Brush.CreateSolidBrush(RGB(255,255,230));\r
12 }\r
13 \r
14 CView::~CView()\r
15 {\r
16 }\r
17 \r
18 void CView::DrawLine(int x, int y)\r
19 {\r
20         CClientDC dcClient(this);\r
21         dcClient.MoveTo(m_points.back().x, m_points.back().y);\r
22         dcClient.LineTo(x, y);\r
23 }\r
24 \r
25 void CView::OnDraw(CDC* pDC)\r
26 {\r
27         if (m_points.size() > 0)\r
28         {\r
29                 bool bDraw = false;  //Start with the pen up\r
30 \r
31                 for (unsigned int i = 0 ; i < m_points.size(); i++)\r
32                 {\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
36                 }\r
37         }\r
38 }\r
39 \r
40 void CView::PreCreate(CREATESTRUCT &cs)\r
41 {\r
42         // Set the extra style to provide a sunken edge\r
43         cs.dwExStyle = WS_EX_CLIENTEDGE;\r
44 }\r
45 \r
46 void CView::PreRegisterClass(WNDCLASS &wc)\r
47 {\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
52 }\r
53 \r
54 void CView::StorePoint(int x, int y, bool PenDown)\r
55 {\r
56         PlotPoint P1;\r
57         P1.x = x;\r
58         P1.y = y;\r
59         P1.PenDown = PenDown;\r
60 \r
61         m_points.push_back(P1); //Add the point to the vector\r
62 }\r
63 \r
64 void CView::OnLButtonDown(LPARAM lParam)\r
65 {\r
66         // Capture mouse input.\r
67         SetCapture();\r
68 \r
69         StorePoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), true);\r
70 }\r
71 \r
72 void CView::OnLButtonUp(LPARAM lParam)\r
73 {\r
74         {\r
75                 //Release the capture on the mouse\r
76                 ReleaseCapture();\r
77 \r
78                 StorePoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), false);\r
79         }\r
80 }\r
81 \r
82 void CView::OnMouseMove(WPARAM wParam, LPARAM lParam)\r
83 {\r
84         // hold down the left mouse button and move mouse to draw lines.\r
85         if ( (wParam & MK_LBUTTON) && (GetCapture() == this) )\r
86         {\r
87                 DrawLine(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));\r
88                 StorePoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), true);\r
89         }\r
90 }\r
91 \r
92 LRESULT CView::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)\r
93 {\r
94         switch (uMsg)\r
95         {\r
96         case WM_LBUTTONDOWN:\r
97                 OnLButtonDown(lParam);\r
98                 break;\r
99 \r
100         case WM_MOUSEMOVE:\r
101                 OnMouseMove(wParam, lParam);\r
102         break;\r
103 \r
104     case WM_LBUTTONUP:\r
105                 OnLButtonUp(lParam);\r
106                 break;\r
107         }\r
108 \r
109         //Use the default message handling for remaining messages\r
110         return WndProcDefault(uMsg, wParam, lParam);\r
111 }\r
112 \r
113 \r

UCC git Repository :: git.ucc.asn.au