Downloading Horstmann's Graphics Libraries and Creating a Visual C++ project that Uses Themfor Visual Studio 2005 |
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:

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.

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.


![]() |
![]() |
| BEFORE | AFTER |
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:
Find line 32, which says
long FAR PASCAL _export ccc_win_proc(HWND hwnd, UINT message, UINT wParam, LONG lParam)
and remove the word _export from it. Now it should say
long FAR PASCAL ccc_win_proc(HWND hwnd, UINT message, UINT wParam,
LONG lParam)
Remove or "comment out" line 37, which says
HINSTANCE hInstance;
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.