|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.|
Spiro Sample: Animated Drawing Game
The Spiro sample is a drawing game that shows how to work with the following features:
Memory DCs in applications requiring animation effects.
MM_LOENGLISH mapping mode.
Image lists (created using CImageList), including transparency mode and bitmap dragging and dropping.
This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.
Building and Running the Sample
To build and run the Spiro sample
Open the solution spiro.sln.
On the Build menu, click Build.
On the Debug menu, click Start Without Debugging.
The toolbar contains four ring types and seven wheel types. The rings and wheels can be combined (one and one) to create different "spirograph" drawings.
The wheels can also be used as rings. In this case, a wheel is set outside another wheel.
Once the ring and the wheel are set on the drawing area, you can click the wheel's "pen-spot" and drag it to another position on the wheel. By changing the pen-spot location, different drawings are generated. In addition, you can select which colors to use from the toolbar. Finally, you can select the width of the pen by clicking the "width setting" button on the toolbar.
Once these settings have been selected, start drawing by clicking the "Play" button. This triggers the drawing action, which can be paused with the "Pause" button. It can be "stepped" with the "step" button.
Drawing Speed The drawing speed is controlled using the "Fast Drawing" and "Slow Drawing" buttons on the toolbar.
Clearing or Repositioning the Rings Once the drawing is complete, you can remove the rings or wheel from the drawing surface by clicking the "cancel-ring" or "cancel-wheel" button on the toolbar.
Clicking the "cancel-ring" button removes the drawing wheel as well if it is present.
To reposition the wheel or ring, remove the ring and place it again.
Copying and Dragging Spirographs Completed spirographs can be dragged to different locations on the drawing area using the mouse. To copy a drawing, hold down the Ctrl key and drag it to a new location.
Removing Spirographs To remove a drawing from the drawing area, drag and drop it off the drawing surface. To accomplish this, you may need to zoom out one or more times until the limits of the drawing area are displayed on the screen.
Zooming There are two toolbar buttons to perform zoom-in and zoom-out. These buttons work even while a drawing is being created. You can zoom out several times until the limits of the drawing area are visible.
Printing You can see the drawings prior to printing using the Print Preview option on the File menu. Very nice patterns can be printed with a color printer.
Classes and Keywords
This sample demonstrates the following classes:
This sample demonstrates the following keywords:
CBitmap::CreateCompatibleBitmap, CBitmap::DeleteObject, CImageList::DragEnter, CImageList::DragLeave, CImageList::DragMove, CImageList::EndDrag, CDC::DPtoLP, CDC::LPtoDP, CDC::IsPrinting, CDC::SetWindowOrg, CDC::SetViewportOrg, CDC::FillRect, CCmdUI::Enable, CView::OnPrepareDC, CRect::SetRect, CRect::InflateRect, CToolbarCtrl::IsButtonChecked