X-Git-Url: https://git.ucc.asn.au/?p=matches%2Fhonours.git;a=blobdiff_plain;f=research%2Ftransmission_spectroscopy%2FTOF%2FWin32%2B%2B%2Ftutorials%2FTutorial5%2FView.cpp;fp=research%2Ftransmission_spectroscopy%2FTOF%2FWin32%2B%2B%2Ftutorials%2FTutorial5%2FView.cpp;h=0fb0f5e62d3d80296a8db2a310b02bbbf9381ac2;hp=0000000000000000000000000000000000000000;hb=70a96cca12cb006506461d26cd112bab179fe74c;hpb=8caf60af39689a3546074f0c68d14c3a2e28191e 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 index 00000000..0fb0f5e6 --- /dev/null +++ b/research/transmission_spectroscopy/TOF/Win32++/tutorials/Tutorial5/View.cpp @@ -0,0 +1,101 @@ +////////////////////////////////////////////// +// View.cpp +// Definitions for the CView class + +#include "view.h" +#include "resource.h" + + +CView::CView() +{ +} + +void CView::DrawLine(int x, int y) +{ + CClientDC dcClient(this); + dcClient.MoveTo(m_points.back().x, m_points.back().y); + dcClient.LineTo(x, y); +} + +void CView::OnDraw(CDC* pDC) +{ + if (m_points.size() > 0) + { + bool bDraw = false; //Start with the pen up + + for (unsigned int i = 0 ; i < m_points.size(); i++) + { + if (bDraw) pDC->LineTo(m_points[i].x, m_points[i].y); + else pDC->MoveTo(m_points[i].x, m_points[i].y); + bDraw = m_points[i].PenDown; + } + } +} + +void CView::StorePoint(int x, int y, bool PenDown) +{ + PlotPoint P1; + P1.x = x; + P1.y = y; + P1.PenDown = PenDown; + + m_points.push_back(P1); //Add the point to the vector +} + +void CView::OnLButtonDown(LPARAM lParam) +{ + // Capture mouse input. + SetCapture(); + + StorePoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), true); +} + +void CView::OnLButtonUp(LPARAM lParam) +{ + { + //Release the capture on the mouse + ReleaseCapture(); + + StorePoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), false); + } +} + +void CView::OnMouseMove(WPARAM wParam, LPARAM lParam) +{ + // hold down the left mouse button and move mouse to draw lines. + if ( (wParam & MK_LBUTTON) && (GetCapture() == this) ) + { + DrawLine(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); + StorePoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), true); + } +} + +LRESULT CView::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + switch (uMsg) + { + case WM_LBUTTONDOWN: + OnLButtonDown(lParam); + break; + + case WM_MOUSEMOVE: + OnMouseMove(wParam, lParam); + break; + + case WM_LBUTTONUP: + OnLButtonUp(lParam); + break; + + // Note: No need to handle WM_DESTROY. The frame does this for us. + // case WM_DESTROY: + // ::PostQuitMessage(0); + // break; + } + + //Use the default message handling for remaining messages + return WndProcDefault(uMsg, wParam, lParam); +} + + + +