CSCI 201 Lab 3 -- Using the EzWindows interface

In this lab you write a simple C++ programs using the Visual C++ compiler. Your programs will use the EzWindows interface described in the textbook. Everything you need to know about the EzWindows routines will be described in the lab handout; however, you'll probably find it very useful to refer to Appendix F.3 (pp. 861-867) of the textbook as you work through this lab.

Libraries and include files

The compiled programs of the EzWindows system are stored in a library. Definitions of the interfaces of these programs are stored in include directories. Your lab instructor will tell you a bit more about these.

If you install the EzWindows interface on your home PC using the textbook's CD-ROM and use the standard installation options, the EzWindows library will be stored in

and the EzWindows include files, in the directory

However, a different setup is used in our lab. The library is stored in

and the include files in

Cleaning up

Check to see if there is a directory C:\FILES\stonehenge on your PC. If one exists, delete it now.

Creating your first EzWindows application

There are six steps to complete to create and execute an EzWindows application:
  1. Create a Visual C++ project
  2. Add the EzWindows library to your project
  3. Modify the project so that the EzWindows include files are used
  4. Create a C++ program
  5. Writing a C++ program
  6. Build and execute your program
Usually you'll need to repeat the last two steps over and over and over.

In each the remaining labs of the course you'll be building and running Visual C++ programs. In this lab, the programming process will be explained in great detail. You should master these steps so that you can do them without reference to this lab handout in the future. In fact, you should be able to answer CSCI 201 exam questions about the steps.

Creating the project

The procedure for creating a project are explained in CSCI 201 Lab 1 and in Section F.3.1 of your textbook. However, for completeness, we'll include a review here. If you don't need a review, go ahead and create a project named stonehenge of type Win32 Console Application in the directory C:\FILES and skip to the next section.

Starting Visual C++

If you're still hanging around for the review, start up the Visual C++ development system. This is done by following the following sequence of menu selections from the Start button

You should see a large window, the primary window of the Visual C++ development environment.
Visual C++ main window
You may also see a second smaller floating window displaying the InfoViewer. Go ahead and terminate the InfoViewer window by pressing on the X in its upper right hand corner. We will not use the InfoViewer window in CSCI 201 labs.
Visual C++ InfoViewer window

Creating a project

From the Visual C++ menu bar, work through the menu choices File » New. A dialog window will be displayed. If necessary, select the Projects tab. Move to the Location box and type C:\files. This is the directory in which your project will be stored. Next move to the Project name box and type stonehenge, the name of your new project.
New projects dialog box
Click on OK to create the project.

The sub-panel in the upper-left hand corner of your Visual C++ window is called the Workspace window. It should now look like:
Press on the lower tab on the Workspace window labeled FileView. This will bring up outline-like display of the files of your project. Right now you haven't added any files to your project, so don't expect to see much.

Adding the EzWindows library

Adding the EzWindows library to your project isn't easy. Start with the menu choices Project » Add to Project » Files to raise the Insert Files into Project dialog. Press on the small down arrow just at the end of the Files of type choice. You'll see a long list of selections. You'll need to scroll down the list until you file the choice Library Files (.lib). Mash it.

Now press the down arrow at the end of the Look in choice. You'll see an explorer-type file menu. Navigate through the menu until you find the EzWindows library. Remember that, in the RH 142 lab, the library is stored in

but, on your home PC, you'll probably find it at Eventually you should reach
Adding a library to the project
Then you can just punch OK.

Go back to the Workspace window and select the FileView. If there is a plus sign to the left of your project name, press it. It should change to a minus sign. Now you should be able to see that the EzWindows library has been added to your project.
ClassView with project

For more information on adding projects, see section F.3.2 of the textbook.

Adding the EzWindows include directory

You need to change the project options to include the EzWindows library. This is explained fully in section F.3.3 of the text.

Start with the menu choices Tools » Options.... to raise the Options dialog menu. Select the Directories tab.
Directory Options
If you've done this before, you may already see the EzWindows include directory, in which case you can skip on to the next section.

At the end of the Directories list, you should see a blank entry. Move your mouse into that blank and double click. The blank entry will be replaced by a new larger blank followed by a box with three dots.
ex-Blank Entry

Believe it or not, if you click on the three dots, you'll get a Choose Directory dialog. Select the appropriate directory. In the RH 142 lab, it's

At home, you'll probably want
Include directory chosen
Click OK a couple of times and the include directory will be set properly.

Creating a C++ source file

Add a new C++ source files called
stonehenge.cpp to your project. Start this by going through Project » Add to Project » New menu choices. This brings up a dialog box entitled New.

Select the Files tab and then select C++ Source File as the file type. Go into the File name and enter the file name stonehenge.cpp.
Adding a new C++ file

Press OK. Your Workspace window should now show the new file.
FileView with new C++ file

Writing a C++ source file

Normally, you just start writing C++ statements into the blank program source window.
Empty C++ program window
however, today we'll give you a head start.

Load up our version of the program stonehenge.cpp by pressing on the link. Of course, once you've done that you can't read this page, so you better come back and read a little ahead.

OK. You've followed the link and have our version of stonehenge.cpp in your Netscape browser. Make the menu selections Edit » Select All. This should cause the entire program to be high-lighted. Now do Edit » Copy. This makes Windows stash the program away. By the way, the control character keystrokes ^A ^C do the same thing. Now come back to this Netscape page and stop reading ahead.

Move your mouse into Visual's empty C++ program window and Edit » Paste through the menus or ^V through the keyboard.

About that program

The calls similar to
SimpleWindow MyWin("Your name's winder", 18.0, 11.0) ;
MyWin.Open() ;
create a titled window that is 18 by 11 centimeters in size and display it on the screen. The calls
RectangleShape Column1(MyWin, 4.0, 8.0, Blue, 2.0, 6.0) ;
Column1.Draw() ;
create a blue rectangle (see page 375 for possible colors) that is centered at a point 4 cm from the left edge of the window and 8 cm from the top edge. This rectangle is 2 by 6 cm in size. The silliness at the beginning of the program about having to enter the number makes sure the console window is displayed before the application window. (Well of least sometimes it does.)

Building and executing the program

You can build your program with either the menu selections Build » Build stonehenge.exe, the toolbar build icon Build icon, or the key F7. Any errors that were uncovered in building your program will be displayed in the Output window at the bottom of the Visual C++ main window.
Output window with an error
If you have errors, you'll need to use the output window's scroll bars to actually see the error messages.
Scrolled Output window

You execute your program with the menu selections Build » Execute stonehenge.exe, the toolbar execute icon !, or the odd control keystroke ^F5.

By the way, the reasons we have mentioned the keystroke shortcuts in this section is that we know that you will be re-building your program many times.

Running this program

When you start running the program, you should see a console window asking you to: Type an number and then you'll see four blue columns.
Early version of Stonehenge
This is an accurate representation of a recently discovered initial design made by one of the Project Stonehenge engineers. (Actually, the engineer really specified grey columns, but EzWindows doesn't support that color.)

To terminate the display, bring your mouse into the original console window and type a control-C (^C).

Lab Assignment and Checkoff

Your job is to modify your program so that it gives a more accurate rendition of the final version of Project Stonehenge.
Final version of Stonehenge
You do this by adding four statements to your C++ programs. These statements will define RectangleShape objects for the two spans and draw them into the window.

You may have to dust off your high school geometry skills to figure out how to size and place the spans.

What can go wrong?

The 201 lab instructors have encountered few problems testing this assignment on the Windows NT computers in their offices. However, a couple of problems have cropped up when using the Windows 95 computers in the lab.

First of all, make absolutely sure that you have terminated execution of your program before you try to modify and rebuild it. If you don't, you will get the error message:

Unfortunately, we have also noticed times in which the stonehenge application continues to run even after it has been terminated. We've also noticed that sometime the application doesn't wait for you to enter a number from the console and instead flashes its graphics.

We don't know what causes these problems, but we prefer to blame it on factors, such as the Novell file system, that are beyond our control. We do know a couple of extreme measures which seem to help.

  1. Save your C++ program to a floppy disk and create a new project. Add the EzWindows library file and include directory and your C++ program into the project.
  2. If you are a seasoned Windows 95 user, type the Microsoft three-fingered salute and then use the Task Manager to see if any rouge copies of stonehenge are running. If so, select and terminate them.

Return to CSCI 201 page
CSCI logo Return to the UNCA Computer Science home page