Downloading Horstmann's Graphics Libraries and Creating a Visual C++ project that Uses Them

for Visual Studio 2005
JL Popyack

NOTE: These directions are very similar to, but not identical to, the directions for earlier versions of Visual C++ .NET. (In particular, some of the tasks must be performed in a different order.) If you follow those instructions, your project will not work in Visual Studio 2005. Please pay close attention!

 

Before you can do graphics, you need to do some code library installation.

Download the following zip file: , which contains Horstamnn's code libraries for graphics, and also other code used in his text.
(NOTE: This is a local copy; the original can be found at http://www.horstmann.com/ccc/ccc3e.zip)

Unzip these files in a reasonable spot on your hard drive.

Create a new project. Select Visual C++, Win32 Project.

Under "Application Settings", select Windows application, Empty project. DO NOT CREATE A "CONSOLE" APPLICATION. DO NOT ADD SUPPORT FOR ATL OR MFC.

Add the cccfiles directory to the include path. To do this, perform the following steps:

  1. Select your project in the Solution Explorer. This should be the first item immediately under the item named "Solution". If the Solution Explorer is not visible, select "View -> Solution Explorer (Ctrl+Alt+L)".

  2. Add ccc_win.h, ccc_msw.cpp and ccc_shap.cpp to the project (also ccc_msw.h and ccc_shap.h), by clicking on Project -> Add Existing Item..., and selecting these files.

  3. Choose "View->Property Pages".

    In the window that appears, Select "Configuration Properties -> General" in the list box on the left, and make sure the setting for "Character Set" is "Not Set". This is important! If you leave it set on "Use Unicode Character Set", you will wind up a confused, embittered old man with long, inexplicable gaps in your memory.

    turn off Unicode

  4. Next, select "C/C++ -> General" in the list box on the left.

  5. Click on the empty box to the right of the box that says "Additional Include Directories". No visual cues there, eh?
  6. A button with ellipsis ("...") will magically appear (see figure below). Click on this button (we did NOT design this user interface), and who knows? maybe you'll end up at the official "..." website. No? Just another window? OK, read on...

  7. In the window that appears, click on the blank line below the row of icons.
  8. Another button with ellipsis will appear - click on this button.
    BEFORE AFTER

  9. Navigate to the place where you unzipped the Horstmann code library.
  10. Select the "cccfiles" directory.
  11. Click the button that says "Open".
  12. Hit OK as many times as needed to return the main window.

Your aerobic activities should have you near a "jogger's high" by now. Think you're done? Don't you wish! Open the ccc_msw.cpp file and edit it. You have to make two changes:

At this point, you should have a project that is configured to use Horstmann's graphics utilities. To find out if it works properly, create a new source file containing the code shown below, and add it to the project. In the example shown below, our program is named "test_graphics.cpp".

#include "ccc_win.h"

int ccc_win_main()
{
  Point origin(0,0) ;
  Point p(4, 2.5);
  Line myLine(origin, p);
  Circle smallCircle(p, 2.2);
  Circle bigCircle(origin, 6);
  cwin << origin << p << myLine
       << smallCircle << bigCircle;

  return 0;
}

 

Compile and run your program. If you're lucky, all goes well, you should produce a graphics window with the following output:

So that you don't have to go through this hassle every time you want to create a graphics program, you should save your entire project folder somewhere safe so that you can re-use it again and again. When you want to use it, simply remove your test program (e.g., you can select "test_graphics.cpp" in the Solution Explorer window and hit the "Del" key or select "Edit->Remove") and add a new program to the project.