Commit before breaking everything
[matches/honours.git] / research / transmission_spectroscopy / TOF / Win32++ / tutorials / Tutorial5 / View.cpp
diff --git a/research/transmission_spectroscopy/TOF/Win32++/tutorials/Tutorial5/View.cpp b/research/transmission_spectroscopy/TOF/Win32++/tutorials/Tutorial5/View.cpp
new file mode 100644 (file)
index 0000000..0fb0f5e
--- /dev/null
@@ -0,0 +1,101 @@
+//////////////////////////////////////////////\r
+// View.cpp\r
+//  Definitions for the CView class\r
+\r
+#include "view.h"\r
+#include "resource.h"\r
+\r
+\r
+CView::CView()\r
+{\r
+}\r
+\r
+void CView::DrawLine(int x, int y)\r
+{\r
+       CClientDC dcClient(this);\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
+\r
+               for (unsigned int i = 0 ; i < m_points.size(); i++)\r
+               {\r
+                       if (bDraw) pDC->LineTo(m_points[i].x, m_points[i].y);\r
+                       else pDC->MoveTo(m_points[i].x, m_points[i].y);\r
+                       bDraw = m_points[i].PenDown;\r
+               }\r
+       }\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
+\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
+       // Note: No need to handle WM_DESTROY. The frame does this for us.\r
+       //      case WM_DESTROY:\r
+       //      ::PostQuitMessage(0);\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