Commit before breaking everything
[matches/honours.git] / research / transmission_spectroscopy / TOF / Win32++ / tutorials / Tutorial7 / View.cpp
diff --git a/research/transmission_spectroscopy/TOF/Win32++/tutorials/Tutorial7/View.cpp b/research/transmission_spectroscopy/TOF/Win32++/tutorials/Tutorial7/View.cpp
new file mode 100644 (file)
index 0000000..0fefb09
--- /dev/null
@@ -0,0 +1,125 @@
+//////////////////////////////////////////////\r
+// View.cpp\r
+//  Definitions for the CView class\r
+\r
+#include "view.h"\r
+#include "resource.h"\r
+\r
+\r
+CView::CView() : m_PenColor(RGB(0,0,0))\r
+{\r
+       m_Brush.CreateSolidBrush(RGB(255,255,230));\r
+}\r
+\r
+CView::~CView()\r
+{\r
+}\r
+\r
+void CView::DrawLine(int x, int y)\r
+{\r
+       CClientDC dcClient(this);\r
+       dcClient.CreatePen(PS_SOLID, 1, m_points.back().color);\r
+       dcClient.MoveTo(m_points.back().x, m_points.back().y);\r
+       dcClient.LineTo(x, y);\r
+}\r
+\r
+void CView::OnDraw(CDC* pDC)\r
+{\r
+       if (m_points.size() > 0)\r
+       {\r
+               bool bDraw = false;  //Start with the pen up\r
+               for (unsigned int i = 0 ; i < m_points.size(); i++)\r
+               {\r
+                       pDC->CreatePen(PS_SOLID, 1, m_points[i].color);\r
+                       if (bDraw)\r
+                               pDC->LineTo(m_points[i].x, m_points[i].y);\r
+                       else\r
+                               pDC->MoveTo(m_points[i].x, m_points[i].y);\r
+                       \r
+                       bDraw = m_points[i].PenDown;\r
+               }\r
+       }\r
+}\r
+\r
+void CView::PreCreate(CREATESTRUCT &cs)\r
+{\r
+       // Set the extra style to provide a sunken edge\r
+       cs.dwExStyle = WS_EX_CLIENTEDGE;\r
+}\r
+\r
+void CView::PreRegisterClass(WNDCLASS &wc)\r
+{\r
+       // Set the background brush and cursor\r
+       wc.hbrBackground = m_Brush;\r
+       wc.lpszClassName = _T("Scribble Window");\r
+       wc.hCursor = ::LoadCursor(GetApp()->GetInstanceHandle(), MAKEINTRESOURCE(IDC_CURSOR1));\r
+}\r
+\r
+void CView::SetPen(COLORREF color)\r
+{\r
+       m_PenColor = color;\r
+}\r
+\r
+void CView::StorePoint(int x, int y, bool PenDown)\r
+{\r
+       PlotPoint P1;\r
+       P1.x = x;\r
+       P1.y = y;\r
+       P1.PenDown = PenDown;\r
+       P1.color = m_PenColor;\r
+\r
+       m_points.push_back(P1); //Add the point to the vector\r
+}\r
+\r
+void CView::OnLButtonDown(LPARAM lParam)\r
+{\r
+       // Capture mouse input.\r
+       SetCapture();\r
+\r
+       StorePoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), true);\r
+}\r
+\r
+void CView::OnLButtonUp(LPARAM lParam)\r
+{\r
+       {\r
+               //Release the capture on the mouse\r
+               ReleaseCapture();\r
+\r
+               StorePoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), false);\r
+       }\r
+}\r
+\r
+void CView::OnMouseMove(WPARAM wParam, LPARAM lParam)\r
+{\r
+       // hold down the left mouse button and move mouse to draw lines.\r
+       if ( (wParam & MK_LBUTTON) && (GetCapture() == this) )\r
+       {\r
+               DrawLine(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));\r
+               StorePoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), true);\r
+       }\r
+}\r
+\r
+LRESULT CView::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)\r
+{\r
+       switch (uMsg)\r
+       {\r
+       case WM_LBUTTONDOWN:\r
+               OnLButtonDown(lParam);\r
+               break;\r
+\r
+       case WM_MOUSEMOVE:\r
+               OnMouseMove(wParam, lParam);\r
+        break;\r
+\r
+    case WM_LBUTTONUP:\r
+               OnLButtonUp(lParam);\r
+               break;\r
+       }\r
+\r
+       //Use the default message handling for remaining messages\r
+       return WndProcDefault(uMsg, wParam, lParam);\r
+}\r
+\r
+\r
+\r
+\r

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