Commit before breaking everything
[matches/honours.git] / research / transmission_spectroscopy / TOF / Win32++ / WCE samples / Scribble / MainFrm.cpp
1 #include "MainFrm.h"\r
2 #include "resource.h"\r
3 \r
4 \r
5 \r
6 CMainFrame::CMainFrame() : m_PenColor(RGB(0,0,0))\r
7 {\r
8         // Set the Resource IDs for the toolbar buttons\r
9         AddToolBarButton( 0 );                  // Separator\r
10         AddToolBarButton( IDM_RED  );\r
11         AddToolBarButton( IDM_BLUE );\r
12         AddToolBarButton( IDM_GREEN );\r
13         AddToolBarButton( IDM_BLACK );\r
14 }\r
15 \r
16 void CMainFrame::DrawLine(short x, short y)\r
17 {\r
18         CDC* pDC = GetDC();\r
19         pDC->CreatePen(PS_SOLID, 1, m_points.back().color);\r
20         pDC->MoveTo(m_points.back().x, m_points.back().y);\r
21         pDC->LineTo(x, y);\r
22 }\r
23 \r
24 BOOL CMainFrame::OnCommand(WPARAM wParam, LPARAM /*lParam*/)\r
25 {\r
26         // Respond to menu and toolbar selections\r
27         switch (LOWORD(wParam))\r
28         {\r
29         // Respond to menu items\r
30         case IDM_NEW:\r
31                 m_points.clear();\r
32                 Invalidate();\r
33                 return TRUE;\r
34         case IDM_HELP_ABOUT:\r
35                 {\r
36                         CDialog HelpDialog(IDW_ABOUT, this);\r
37                         HelpDialog.DoModal();\r
38                 }\r
39                 return TRUE;\r
40 \r
41         // Respond to ToolBar buttons\r
42         case IDM_RED:\r
43                 m_PenColor = RGB(255, 0, 0);\r
44                 TRACE(_T("Red Pen Selected \n"));\r
45                 return TRUE;\r
46         case IDM_BLUE:\r
47                 m_PenColor = RGB(0, 0, 255);\r
48                 TRACE(_T("Blue Pen Selected \n"));\r
49                 return TRUE;\r
50         case IDM_GREEN:\r
51                 m_PenColor = RGB(0, 191, 0);\r
52                 TRACE(_T("Green Pen Selected \n"));\r
53                 return TRUE;\r
54         case IDM_BLACK:\r
55                 m_PenColor = RGB(0, 0, 0);\r
56                 TRACE(_T("Black Pen Selected \n"));\r
57                 return TRUE;\r
58 \r
59         // Respond to the accelerator key\r
60         case IDW_QUIT:\r
61                 SendMessage(WM_CLOSE, 0L, 0L);\r
62                 return TRUE; \r
63         } \r
64 \r
65         return FALSE;\r
66 }\r
67 \r
68 void CMainFrame::OnDraw(CDC* pDC)\r
69 {\r
70         // Redraw our client area\r
71         if (m_points.size() > 0)\r
72         {\r
73                 bool bDraw = false;  //Start with the pen up\r
74                 for (unsigned int i = 0 ; i < m_points.size(); i++)\r
75                 {\r
76                         pDC->CreatePen(PS_SOLID, 1, m_points[i].color);\r
77                         if (bDraw)\r
78                                 pDC->LineTo(m_points[i].x, m_points[i].y);\r
79                         else\r
80                                 pDC->MoveTo(m_points[i].x, m_points[i].y);\r
81                         \r
82                         bDraw = m_points[i].PenDown;\r
83                 }\r
84         }\r
85 }\r
86 \r
87 void CMainFrame::OnInitialUpdate()\r
88 {\r
89         // Startup code goes here\r
90 }\r
91 \r
92 void CMainFrame::OnLButtonDown(WPARAM /*wParam*/, LPARAM lParam)\r
93 {\r
94         // Capture mouse input.\r
95         SetCapture();\r
96 \r
97         StorePoint(LOWORD(lParam), HIWORD(lParam), true);\r
98 }\r
99 \r
100 void CMainFrame::OnLButtonUp(WPARAM /*wParam*/, LPARAM lParam)\r
101 {\r
102         //Release the capture on the mouse\r
103         ReleaseCapture();\r
104 \r
105         StorePoint(LOWORD(lParam), HIWORD(lParam), false);\r
106 }\r
107 \r
108 void CMainFrame::OnMouseMove(WPARAM wParam, LPARAM lParam)\r
109 {\r
110         // hold down the left mouse button and move mouse to draw lines.\r
111         if (wParam & MK_LBUTTON)\r
112         {       \r
113                 TCHAR str[80];\r
114                 ::wsprintf(str, TEXT("Draw Point:  %hd, %hd\n"), LOWORD(lParam), HIWORD(lParam));\r
115                 TRACE(str);\r
116 \r
117                 DrawLine(LOWORD(lParam), HIWORD(lParam));\r
118                 StorePoint(LOWORD(lParam), HIWORD(lParam), true);\r
119         }\r
120 }\r
121 \r
122 void CMainFrame::SetPen(COLORREF color)\r
123 {\r
124         m_PenColor = color;\r
125 }\r
126 \r
127 void CMainFrame::StorePoint(int x, int y, bool PenDown)\r
128 {\r
129         PlotPoint P1;\r
130         P1.x = x;\r
131         P1.y = y;\r
132         P1.PenDown = PenDown;\r
133         P1.color = m_PenColor;\r
134 \r
135         m_points.push_back(P1); //Add the point to the vector\r
136 }\r
137 \r
138 LRESULT CMainFrame::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)\r
139 {\r
140         // handle left mouse button up/down and mouse move messages\r
141         // a seperate function for each case keeps the code tidy.\r
142         switch (uMsg)\r
143         {\r
144         case WM_LBUTTONDOWN:\r
145                 OnLButtonDown(wParam, lParam);\r
146                 break;\r
147 \r
148         case WM_MOUSEMOVE:\r
149                 OnMouseMove(wParam, lParam);\r
150         break;\r
151 \r
152     case WM_LBUTTONUP:\r
153                 OnLButtonUp(wParam, lParam);\r
154                 break;\r
155         }\r
156 \r
157         // Pass unhandled messages on to WndProcDefault\r
158         return WndProcDefault(uMsg, wParam, lParam);\r
159 }\r
160 \r
161 \r

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