Chapter 15. Drawing in a Window

Similar documents
# # # # % " # (. # + *, -

Chapter 14. Drawing in a Window

Index. Arrays class, 350 Arrays of objects, 97 Arrays of structures, 72 ASCII code, 131 atan2(), 288

MFC Programming Tecnics

SFU CMPT Topic: More MFC Programming

INDEX. Symbols. (OR operator), comparing variables and constants and, 100

Courses IPCx, C2: Histogram, Code Comments

Hello World from Your Name. Replace the words Your Name with your own name. Use the following steps to create your control.

Paint/Draw Tools. Foreground color. Free-form select. Select. Eraser/Color Eraser. Fill Color. Color Picker. Magnify. Pencil. Brush.

How to...create a Video VBOX Gauge in Inkscape. So you want to create your own gauge? How about a transparent background for those text elements?

Designer Reference 1

Drawing Graphics in C Sharp

Creating Vector Shapes Week 2 Assignment 1. Illustrator Defaults

Ai Adobe. Illustrator. Creative Cloud Beginner

Photocopiable/digital resources may only be copied by the purchasing institution on a single site and for their own use ZigZag Education, 2013

Painting your window

Adobe Illustrator. Quick Start Guide

Study of Map Symbol Design Sub-System in Geostar Software

L E S S O N 2 Background

Paint Tutorial (Project #14a)

Introduction To Inkscape Creating Custom Graphics For Websites, Displays & Lessons

DesignCAD 3D Max 22.1 Release Notes

DC2 File Format. 1. Header line 2. Entity line 3. Point line 4. String line

Creating a Text Frame. Create a Table and Type Text. Pointer Tool Text Tool Table Tool Word Art Tool

Controlling the Drawing Display

Memory and Pointers written by Cathy Saxton

EDITING SHAPES. Lesson overview

Learning Microsoft Word By Greg Bowden. Chapter 10. Drawing Tools. Guided Computer Tutorials

DTP with MS Publisher

3D Modeler Creating Custom myhouse Symbols

CS201 Some Important Definitions

1 Getting started with Processing

In this lesson you are going to create a drawing program similar to Windows Paint. 1. Start with a new project and remove the default cat sprite.

Learning to use the drawing tools

Corel Draw 11. What is Vector Graphics?

Custom Shapes As Text Frames In Photoshop

Labels and Envelopes in Word 2013

Simple diagrams made up of geometrical shapes can be designed directly in Delphi using the shape component from the ADDITIONAL component menu: shape

The American University in Cairo. Academic Computing Services. Word prepared by. Soumaia Ahmed Al Ayyat

AppleWorks 6.1: What s New

Generating Vectors Overview

HYPERSTUDIO TOOLS. THE GRAPHIC TOOL Use this tool to select graphics to edit. SPRAY PAINT CAN Scatter lots of tiny dots with this tool.

Faculty Development Seminar Series Constructing Posters in PowerPoint 2003 Using a Template

Java How to Program, 9/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Basic Computer Programming (Processing)

USER S MANUAL Software Usage Agreement Registered Trademarks Notes on this Manual Disclaimer

Using Arrays and Vectors to Make Graphs In Mathcad Charles Nippert

Lesson 1 Parametric Modeling Fundamentals

Shape and Line Tools. tip: Some drawing techniques are so much easier if you use a pressuresensitive

Introduction Of Classes ( OOPS )

Laboratory Exercise 11 Alternate (Intro to MFC)

Adobe InDesign CS6 Tutorial

MET 107 Drawing Tool (Shapes) Notes Day 3

A QUICK TOUR OF ADOBE ILLUSTRATOR CC (2018 RELEASE)

Document Editor Basics

No Trade Secrets. Microsoft does not claim any trade secret rights in this documentation.

MIMAKI ENGINEERING CO., LTD.

Photoshop tutorial: Final Product in Photoshop:

Drawing Tools. Drawing a Rectangle

Creating a Title Block & Border Using Chief Architect. Architectural Design & Residential Construction Penncrest High School

Let s Make a Front Panel using FrontCAD

InDesign Tools Overview

Lesson 6 Adding Graphics

User Manual Version 1.1 January 2015

We will start our journey into Processing with creating static images using commands available in Processing:

Adobe PageMaker Tutorial

Drawing shapes and lines

StickFont Editor v1.01 User Manual. Copyright 2012 NCPlot Software LLC

Band Editor User Guide Version 1.3 Last Updated 9/19/07

CMSC434. Introduction to Human-Computer Interaction. Week 10 Lecture 16 Mar 29, 2016 Engineering Interfaces II. Jon

[MS-MNPR-Diff]: Microsoft NetMeeting Protocol. Intellectual Property Rights Notice for Open Specifications Documentation

Chapter 2 Exercise Solutions

Quick Crash Scene Tutorial

Introduction. Create a New Project. Create the Main Form. Assignment 1 Lights Out! in C# GUI Programming 10 points

LinkMotion and CorelDraw 9, 10, 11, 12, X3, X4, X5, X6, X7 and X8:

Binghamton University. EngiNet. State University of New York

Pen Tool, Fill Layers, Color Range, Levels Adjustments, Magic Wand tool, and shadowing techniques

CS410. Note: VuGujranwala.com is not responsible for any solved solution, but honestly we are trying our best to Guide correctly.

DinoCapture Additional Software Instructions for Measurement models

10Tec igrid for.net 6.0 What's New in the Release

Adobe illustrator Introduction

Word 2003: Flowcharts Learning guide

ENVI Classic Tutorial: Introduction to ENVI Classic 2

Graphic Design & Digital Photography. Photoshop Basics: Working With Selection.

Scan Converting Text. Attributes of Output Primitives. CS 460/560 Computer Graphics. Binghamton University. EngiNet. Thomas J.

SETTINGS AND WORKSPACE

This document should only be used with the Apple Macintosh version of Splosh.

Vectorworks Essential Tutorial Manual by Jonathan Pickup. Sample

INFORMATION TECHNOLOGY

Adobe Flash CS3 Reference Flash CS3 Application Window

Ancient Cell Phone Tracing an Object and Drawing with Layers

Autodesk Inventor - Basics Tutorial Exercise 1

ROBO Master OPS656. USER'S MANUAL MANUAL NO. OPS656m-UM Introduction 1.1 Features System Requirements... 3

Capturing the Mouse. Dragging Example

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

Create Text Inside a Shape with Photoshop CS6

Chapter 2 - Getting Started

Edupen Pro User Manual

In this lecture we will briefly examine a few new controls, introduce the concept of scope, random numbers, and drawing simple graphics.

Learning to Draw Basic Graphics

Transcription:

Chapter 15 Drawing in a Window 1

The Window Client Area A coordinate system that is local to the window. It always uses the upper-left corner of the client area as its reference point. 2

Graphical Device Interface (GDI) You don t draw pictures directly to the screen. You must define the graphical output (lines, circles, text) using the Graphical Device Interface. The GDI enables you to program graphical output independently of the hardware Such as the display screen, printers, plotters 3

What Is a Device Context? You must use a device context to draw anything on a graphical output device. In a word, a device context is a data structure defined by Windows. A device context contains attributes such as Drawing color Background color Line thickness Font Mapping mode Your output requests are specified by deviceindependent GDI function calls. A device context contains information that allows Windows to translate those requests into actions on the particular physical output device. 4

Mapping Modes (1) MM_TEXT A logical unit is one device pixel with positive x from left to right, and positive y from top to bottom of the window client area. (0,0) 5

Mapping Modes (2) MM_LOENGLISH A logical unit is 0.01 inches with positive x from left to right, and positive y from the top of the client area upwards. Consistent with what we learned in high school. By default, the point at the upper-left corner has the coordinates (0,0) in every mapping mode. Coordinate are always 32-bit signed integers. 6

The View Class in Your Application In the class CSketcherView, the function OnDraw() is called when a WM_PAINT message is received in your program. Windows sends this message to your program whenever it requires the client area to be redrawn. The user resizes the window Part of your window was previously covered by another window 7

The OnDraw() Member Function void CSketcherView::OnDraw(CDC* pdc) { CSketcherDoc* pdoc = GetDocument(); ASSERT_VALID(pDoc); if (!pdoc) return; // TODO: add draw code for native data here } Returns the address of the document object related to the current view (P.782) Make sure the pointer pdoc contains a valid address. Make sure the pointer pdoc is not null. 8

Assertion Failed 9

The CDC Class You should do all the drawing in your program using members of the CDC class. C Class DC Device Context There are over a hundred member functions of this class. Sometimes you use objects of CClientDC It is derived from CDC, and thus contains all the members we will discuss. Its advantage is that CClientDC always contains a device context that represents only the client area of a window. 10

Current Position In a device context, you draw entities such as lines, and text relative to a current position. You may set the current position by calling the MoveTo() function. 11

MoveTo() The CDC class overloads the MoveTo() function in two versions to provide flexibility. CPoint MoveTo(int x, int y); CPoint MoveTo(POINT apoint); POINT is a structure defined as: typedef struct tagpoint { LONG x; LONG y; } POINT; CPoint is a class with data members x and y of type LONG. The return value from the MoveTo() function is a CPoint object that specifies the position before the move. This allows you to move back easily. 12

Drawing Lines 13

LineTo() The CDC class also defines two versions of the LineTo() function BOOL LineTo(int x, int y); BOOL LineTo(POINT apoint); You may use either a POINT struct or a CPoint object as the argument. 14

Ex15_1 (P.854) When the LineTo() function is executed, the current position is changed to the point specifying the end of the line. void CSketcherView::OnDraw(CDC* pdc) { CSketcherDoc* pdoc = GetDocument(); ASSERT_VALID(pDoc); if (!pdoc) return; } pdc->moveto(50,50); pdc->lineto(50,200); pdc->lineto(150,200); pdc->lineto(150,50); pdc->lineto(50,50); 15

Figure 15-5 16

Drawing Rectangles & Circles void CSketcherView::OnDraw(CDC* pdc) { CSketcherDoc* pdoc = GetDocument(); ASSERT_VALID(pDoc); if (!pdoc) return; } pdc->rectangle(50,50, 150, 150); pdc->ellipse(50,50, 150,150); 17

A circle is a special ellipse 18

Arc Another way to draw circles is to use the Arc() function. BOOL Arc(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4); (x1, y1) and (x2, y2) define the upper-left and lower-right corners of a rectangle enclosing the circle (ellipse). The points (x3, y3) and (x4, y4) define the start and end points of the arc, which is drawn counterclockwise. If (x4, y4) is identical to (x3, y3), you get a circle. BOOL Arc(LPCRECT lprect, POINT Startpt, POINT Endpt); lprect points to an object of the class CRect, which has four public data members: left, top, right, bottom. 19

Drawing with the Arc() Function void CSketcherView::OnDraw(CDC* pdc) { CSketcherDoc* pdoc = GetDocument(); ASSERT_VALID(pDoc); if (!pdoc) return; pdc->arc(50,50,150,150,100,75,150,100); } CRect* prect = new CRect(250,50,300,100); CPoint Start(275,100); CPoint End(250,75); pdc->arc(prect, Start, End); delete prect; 20

Figure 14-6 21

Drawing in Color 22

Using a Pen Declare a pen object and initialize it as a red solid pen drawing a line 2 pixels wide (P.858) CPen apen; apen.createpen(ps_solid, 2, RGB(255, 0, 0)); CPen* poldpen = pdc->selectobject(&apen); pdc->arc(50,50,150,150,100,75,150,100); pdc->selectobject(poldpen); CRect* prect = new CRect(250,50,300,100); CPoint Start(275,100); CPoint End(250,75); pdc->arc(prect, Start, End); delete prect; 23

Pen Style BOOL CreatePen(int apenstyle, int awidth, COLORREF acolor); PS_SOLID solid line PS_DASH dashed line PS_DOT dotted line PS_DASHDOT alternating dashes and dots PS_DASHDOTDOT alternating dashes and double dots. PS_NULL draw nothing 24

Creating a Brush A brush is actually an 8x8 block of patterns that s repeated over the region to be filled. All closed shapes in CDC will be filled with a brush (and a color). Select the brush into the device context by calling the SelectObject() member (similar to selecting a pen). CBrush abrush; abrush.createsolidbrush(rgb(0,255,255)); CBrush* poldbrush = static_cast<cbrush*> (pdc->selectobject(&abrush)); const int width = 50; const int height = 50; int i; for (i=0; i<6; i++) pdc->rectangle(i*2*width, 50,i*2*width+50, 150); pdc->selectobject(poldbrush); 25

Solid Brush 26

Hatching Style HS_HORIZONTAL HS_VERTICAL HS_BDIAGONAL HS_FDIAGONAL HS_CROSS HS_DIAGCROSS CBrush abrush; abrush.createhatchbrush(hs_diagcross, RGB(0,255,255)); CBrush* poldbrush = static_cast<cbrush*> (pdc->selectobject(&abrush)); 27

A Hatched Brush 28

Drawing Graphics in Practice The easiest mechanism for drawing is using just the mouse. 29

Circle 30

Rectangle 31

Curve 32

Message from the Mouse WM_LBUTTONDOWN Left mouse button is pressed WM_LBUTTONUP Left mouse button is released WM_MOUSEMOVE The mouse is moved. 33

Mouse Message Handlers Create a handler by clicking on the ID of a mouse message. Then select the down arrow in its right column. For example, select <add> OnLButtonUp for the WM_LBUTTONUP message. The wizard generates the WM_LBUTTONUP message handler: void CSketcherView::OnLButtonUp(UINT nflags, CPoint point) { // TODO: Add your message handler code here and/or call default } CView::OnLButtonUp(nFlags, point); 34

OnMouseMove() void CSketcherView::OnMouseMove(UINT nflags, CPoint point) { // TODO: Add your message handler code here and/or call default Verify the left mouse button is down if (nflags & MK_LBUTTON) { m_secondpoint = point; // Test for a previous temporary element { // We get to here if there was a previous mouse move // so add code to delete the old element } } } // Add code to create new element // and cause it to be drawn 35

nflags MK_CONTROL Ctrl key being pressed MK_LBUTTON Left mouse button being down MK_MBUTTON Middle mouse button being down MK_RBUTTON Right mouse button being down MK_SHIFT Shift key being pressed To test for the Ctrl key being pressed if (nflags & MK_CONTROL) // Do something bitwise AND operator (P.80) 36

Storing the Position of the Cursor You may store the position of the cursor in the CSketcherView class. 37

m_firstpoint & m_secondpoint Initialization in the constructor, CSketcherView::CSketcherView(): m_firstpoint(cpoint(0,0)), m_secondpoint(cpoint(0,0)) Assigning values in the message handler, void CSketcherView::OnLButtonDown(UINT nflags, CPoint point) { // TODO: Add your message handler code here and/or call default m_firstpoint = point; // Record the cursor position } 38

Defining Classes for Elements 39

Creating the CElement Class 40

Creating the CCircle Class Create element classes using CElement as the base class Choose the class category to be C++ Choose the template as C++ class 41

Create CLine, CRectangle, CCircle, CCurve 42

Storing a Temporary Element in the View In the view class, add a pointer to a CElement Right-click the CSketcherView class Add > Add Variable 43

The Add Member Variable Wizard adds some code to initialized the new variable. NULL fits nicely for us! CSketcherView::CSketcherView() : m_firstpoint(cpoint(0,0)), m_secondpoint(cpoint(0,0)), m_ptempelement(null) { // TODO: add construction code here } 44

Check SketcherView.h At the beginning, there is a line: #include atltypes.h The wizard assumed the CElement type is an ATL (Active Template Library) type. Delete this line and add the following statement: class CElement; Forward class declaration 45

SketcherView.cpp #include Elements.h before #include SketcherView.h Ensure that the definition of the CElement class is included before the CSketcherView class definition. 46

The CElement Class class CElement : public CObject { protected: COLORREF m_color; // Color of an element CElement(); public: virtual ~CElement(); virtual void Draw(CDC* pdc) {} // Virtual draw operation }; The constructor is changed from public to protected. CRect GetBoundRect(); // Get the bounding rectangle for an element 47

The CLine Class class CLine : public CElement { protected: CLine(void); // Default constructor (should not be used) CPoint m_startpoint; CPoint m_endpoint; public: ~CLine(void); virtual void Draw(CDC* pdc); // Function to display a line }; // Constructor for a line object CLine(CPoint Start, CPoint End, COLORREF acolor); 48

Implementation of the CLine Constructor CLine::CLine(CPoint Start, CPoint End, COLORREF acolor) { } m_startpoint = Start; m_endpoint = End; m_color = acolor; 49

Drawing a Line // Draw a CLine object void CLine::Draw(CDC* pdc) { // Create a pen for this object and // initialize it to the object color and line width of 1 pixel CPen apen; if(!apen.createpen(ps_solid, m_pen, m_color)) { // Pen creation failed. Abort the program AfxMessageBox(_T("Pen creation failed drawing a line"), MB_OK); AfxAbort(); } CPen* poldpen = pdc->selectobject(&apen); // Select the pen // Now draw the line pdc->moveto(m_startpoint); pdc->lineto(m_endpoint); Pen Width (set in P.879) defined in CElement If the pen cannot be created, display a message box and abort the program. } pdc->selectobject(poldpen); // Restore the old pen 50

Bounding Rectangles Positive Not exactly coincide with the enclosing rectangles which are used to draw the elements. Thickness must be taken into account. 51

Modify the CElement Class Definition class CElement : public CObject { protected: COLORREF m_color; // Color of an element CRect m_enclosingrect; // Rectangle enclosing an element int m_pen; // Pen width CElement(); public: virtual ~CElement(); virtual void Draw(CDC* pdc) {} // Virtula draw operation }; CRect GetBoundRect(); // Get the bounding rectangle for an element 52

Update the CLine Constructor CLine::CLine(CPoint Start, CPoint End, COLORREF acolor) { } m_startpoint = Start; m_endpoint = End; m_color = acolor; m_pen = 1; 53

GetBoundRect() Assuming the MM_TEXT mapping mode: // Get the bounding rectangle for an element CRect CElement::GetBoundRect() { CRect BoundingRect; // Object to store bounding rectangle BoundingRect = m_enclosingrect; // Store the enclosing rectangle } // Increase the rectangle by the pen width BoundingRect.InflateRect(m_Pen, m_pen); return BoundingRect; // Return the bounding rectangle 54

Enlarge the Enclosing Rectangle by the Pen Width BoundingRect.InflateRect(m_Pen, m_pen); BoundingRect = m_enclosingrect + CRect(m_Pen, m_pen, m_pen, m_pen); BoundingRect = m_enclosingrect; BoundingRect.top -= m_pen; BoundingRect.left -= m_pen; BoundingRect.bottom += m_pen; BoundingRect.right += m_pen; 55

Calculating the Enclosing Rectangle for a Line CLine::CLine(CPoint Start, CPoint End, COLORREF acolor) { m_startpoint = Start; m_endpoint = End; m_color = acolor; m_pen = 1; } // Define the enclosing rectangle m_enclosingrect = CRect(Start, End); 56

The CRectangle Class class CRectangle : public CElement { public: ~CRectangle(void); virtual void Draw(CDC* pdc); // Function to display a rectangle // Constructor for a rectangle object CRectangle(CPoint Start, CPoint End, COLORREF acolor); protected: CRectangle(void); // Default constructor - should not be used }; 57

The CRectangle Class Constructor Similar to that for a CLine constructor // CRectangle class constructor CRectangle:: CRectangle(CPoint Start, CPoint End, COLORREF acolor) { m_color = acolor; // Set rectangle color m_pen = 1; // Set pen width } // Define the enclosing rectangle m_enclosingrect = CRect(Start, End); 58

Drawing a Rectangle void CRectangle::Draw(CDC* pdc) { // Create a pen for this object and // initialize it to the object color and line width of 1 pixel CPen apen; if(!apen.createpen(ps_solid, m_pen, m_color)) { // Pen creation failed AfxMessageBox(_T("Pen creation failed drawing a rectangle"), MB_OK); AfxAbort(); } // Select the pen CPen* poldpen = pdc->selectobject(&apen); // Select the brush CBrush* poldbrush = (CBrush*)pDC->SelectStockObject(NULL_BRUSH); // Now draw the rectangle pdc->rectangle(m_enclosingrect); } pdc->selectobject(poldbrush); // Restore the old brush pdc->selectobject(poldpen); // Restore the old pen 59

The CCircle Class Similar to the CRectangle class class CCircle : public CElement { public: ~CCircle(void); virtual void Draw(CDC* pdc); // Function to display a circle // Constructor for a circle object CCircle(CPoint Start, CPoint End, COLORREF acolor); protected: CCircle(void); // Default constructor - should not be used }; 60

Implementing the CCircle Class The point you press the left mouse button is the center The point you release the left mouse button is a point on the circumference. We need to design the constructor to convert this to the enclosing rectangle of a circle. 61

#include <math.h> in Elements.cpp The CCircle Class Constructor CCircle::CCircle(CPoint Start, CPoint End, COLORREF acolor) { // First calculate the radius // We use floating point because that is required by the // library function (in math.h) for calculating a square root. long Radius = static_cast<long> (sqrt( static_cast<double>((end.x-start.x)*(end.x-start.x)+ (End.y-Start.y)*(End.y-Start.y)))); // Now calculate the rectangle enclosing // the circle assuming the MM_TEXT mapping mode m_enclosingrect = CRect(Start.x-Radius, Start.y-Radius, Start.x+Radius, Start.y+Radius); } m_color = acolor; // Set the color for the circle m_pen = 1; // Set pen width to 1 62

Drawing a Circle void CCircle::Draw(CDC* pdc) { // Create a pen for this object and // initialize it to the object color and line width of 1 pixel CPen apen; if(!apen.createpen(ps_solid, m_pen, m_color)) { // Pen creation failed AfxMessageBox(_T("Pen creation failed drawing a circle"), MB_OK); AfxAbort(); } CPen* poldpen = pdc->selectobject(&apen); // Select the pen // Select a null brush CBrush* poldbrush = (CBrush*)pDC->SelectStockObject(NULL_BRUSH); // Now draw the circle pdc->ellipse(m_enclosingrect); } pdc->selectobject(poldpen); // Restore the old pen pdc->selectobject(poldbrush); // Restore the old brush 63

Setting the Drawing Mode SetROP2() SetRaster OPerationto R2_BLACK All drawing is in black R2_WHITE All drawing is in white R2_NOP Drawing operations do nothing R2_COPYPEN Drawing is in the pen color. This is the default. R2_XORPEN Drawing is in the color produced by exclusive ORing the pen color and the background color. R2_NOTXORPEN Drawing is in the color that is the inverse of the R2_XORPEN color. 64

R2_NOTXORPEN If you draw the same shape again, the shape disappears. R G B Background white 1 1 1 Pen red 1 0 0 XORed 0 1 1 NOT XOR produces red 1 0 0 R G B Background red 1 0 0 Pen red 1 0 0 XORed 0 0 0 NOT XOR produces white 1 1 1 65

Coding the OnMouseMove() Handler Using the CClientDC class rather than CDC It automatically destroys the device context when you are done. void CSketcherView::OnMouseMove(UINT nflags, CPoint point) { // Define a Device Context object for the view CClientDC adc(this); // DC is for this view adc.setrop2(r2_notxorpen); // Set the drawing mode if((nflags & MK_LBUTTON) && (this == GetCapture())) { m_secondpoint = point; // Save the current cursor position if(m_ptempelement) { // Redraw the old element so it disappears from the view m_ptempelement->draw(&adc); delete m_ptempelement; // Delete the old element m_ptempelement = 0; // Reset the pointer to 0 } // Create a temporary element of the type and color that // is recorded in the document object, and draw it m_ptempelement = CreateElement();// Create a new element m_ptempelement->draw(&adc); // Draw the element defined in CSketcherView (P.873) } } will be defined on P.890 66

CreateElement() 67

Implementing CreateElement() CElement* CSketcherView::CreateElement(void) { // Get a pointer to the document for this view CSketcherDoc* pdoc = GetDocument(); // Now select the element using the type stored in the document switch(pdoc->getelementtype()) { case RECTANGLE: return new CRectangle(m_FirstPoint, m_secondpoint, pdoc->getelementcolor()); will be defined on P.891 case CIRCLE: return new CCircle(m_FirstPoint, m_secondpoint, pdoc->getelementcolor()); case LINE: return new CLine(m_FirstPoint, m_secondpoint, pdoc->getelementcolor()); } } default: // Something's gone wrong AfxMessageBox(_T("Bad Element code"), MB_OK); AfxAbort(); return NULL; 68

GetElementType() class CSketcherDoc : public CDocument { // Rest of the class definition as before // Operations public: // Get the element type unsigned int GetElementType() { return m_element; } }; // Get the element color COLORREF GetElementColor() { return m_color; } // Rest of the class definition as before 69

Dealing with WM_LBUTTONUP void CSketcherView::OnLButtonUp(UINT nflags, CPoint point) { // Make sure there is an element if (m_ptempelement) { // Call a document class function to store the element // pointed to by m_ptempelement in the document object } delete m_ptempelement; m_ptempelement = 0; } CView::OnLButtonUp(nFlags, point); 70

Exercising Sketcher Download a partially finished project sketcher-ch15.zip Uncompress the Sketcher folder to Your Documents\Visual Studio 2008\Projects CLine is implemented. You may compile and run it. Try to complete the implementation of CCircle & CCurve. 71