2 #include "resource.h"
\r
6 CMainFrame::CMainFrame() : m_PenColor(RGB(0,0,0))
\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
16 void CMainFrame::DrawLine(short x, short y)
\r
19 pDC->CreatePen(PS_SOLID, 1, m_points.back().color);
\r
20 pDC->MoveTo(m_points.back().x, m_points.back().y);
\r
24 BOOL CMainFrame::OnCommand(WPARAM wParam, LPARAM /*lParam*/)
\r
26 // Respond to menu and toolbar selections
\r
27 switch (LOWORD(wParam))
\r
29 // Respond to menu items
\r
34 case IDM_HELP_ABOUT:
\r
36 CDialog HelpDialog(IDW_ABOUT, this);
\r
37 HelpDialog.DoModal();
\r
41 // Respond to ToolBar buttons
\r
43 m_PenColor = RGB(255, 0, 0);
\r
44 TRACE(_T("Red Pen Selected \n"));
\r
47 m_PenColor = RGB(0, 0, 255);
\r
48 TRACE(_T("Blue Pen Selected \n"));
\r
51 m_PenColor = RGB(0, 191, 0);
\r
52 TRACE(_T("Green Pen Selected \n"));
\r
55 m_PenColor = RGB(0, 0, 0);
\r
56 TRACE(_T("Black Pen Selected \n"));
\r
59 // Respond to the accelerator key
\r
61 SendMessage(WM_CLOSE, 0L, 0L);
\r
68 void CMainFrame::OnDraw(CDC* pDC)
\r
70 // Redraw our client area
\r
71 if (m_points.size() > 0)
\r
73 bool bDraw = false; //Start with the pen up
\r
74 for (unsigned int i = 0 ; i < m_points.size(); i++)
\r
76 pDC->CreatePen(PS_SOLID, 1, m_points[i].color);
\r
78 pDC->LineTo(m_points[i].x, m_points[i].y);
\r
80 pDC->MoveTo(m_points[i].x, m_points[i].y);
\r
82 bDraw = m_points[i].PenDown;
\r
87 void CMainFrame::OnInitialUpdate()
\r
89 // Startup code goes here
\r
92 void CMainFrame::OnLButtonDown(WPARAM /*wParam*/, LPARAM lParam)
\r
94 // Capture mouse input.
\r
97 StorePoint(LOWORD(lParam), HIWORD(lParam), true);
\r
100 void CMainFrame::OnLButtonUp(WPARAM /*wParam*/, LPARAM lParam)
\r
102 //Release the capture on the mouse
\r
105 StorePoint(LOWORD(lParam), HIWORD(lParam), false);
\r
108 void CMainFrame::OnMouseMove(WPARAM wParam, LPARAM lParam)
\r
110 // hold down the left mouse button and move mouse to draw lines.
\r
111 if (wParam & MK_LBUTTON)
\r
114 ::wsprintf(str, TEXT("Draw Point: %hd, %hd\n"), LOWORD(lParam), HIWORD(lParam));
\r
117 DrawLine(LOWORD(lParam), HIWORD(lParam));
\r
118 StorePoint(LOWORD(lParam), HIWORD(lParam), true);
\r
122 void CMainFrame::SetPen(COLORREF color)
\r
124 m_PenColor = color;
\r
127 void CMainFrame::StorePoint(int x, int y, bool PenDown)
\r
132 P1.PenDown = PenDown;
\r
133 P1.color = m_PenColor;
\r
135 m_points.push_back(P1); //Add the point to the vector
\r
138 LRESULT CMainFrame::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
\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
144 case WM_LBUTTONDOWN:
\r
145 OnLButtonDown(wParam, lParam);
\r
149 OnMouseMove(wParam, lParam);
\r
153 OnLButtonUp(wParam, lParam);
\r
157 // Pass unhandled messages on to WndProcDefault
\r
158 return WndProcDefault(uMsg, wParam, lParam);
\r