CSCI 201 Lab 4 -- Using the EzWindows interface

In this lab you write a simple C++ programs using the EzWindows library. Everything you need to know about the EzWindows routines will be described in this lab handout.

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.

Cleaning up

Before you start to work on a new project you must first make sure a project by the same name is not already on the computer you are using. 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 an empty C++ program
  5. Edit or type in your 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 process you will use will be explained in great detail. It is important that you master these steps now so that you can do them without reference to this lab page in the future.

Creating the project

The procedure for creating a project are explained in CSCI 201 Lab 2. 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 Application in the directory C:\FILES and skip to the next section. (We use a Win32 Application instead of a Win32 Console Application for graphics.)

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

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 start creating the project.


Empty Application

Select an empty project.


Empty Project

Hit OK to finish creating the stonehenge project.

The sub-panel in the upper-left hand corner of your Visual C++ window is called the Workspace window. It should now look something like:
ClassView
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.


FileView

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 find 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 located at :

Remember this for future labs. When you have located the library, your window should look like this:
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

Adding the EzWindows include directory

You also need to change the project options to include the EzWindows library.

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 or another student has done it on the computer you are using, 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 window. Using the dialog window, select the following directory:

If you are in the ezwin/lib directory, just click on the ezwin directory icon and then the include directory icon. Then click OK a couple of times and the include directory will be added to your project as shown below.


Include Directories

Each time you use ezwin you will need to make sure both the ezwin library and the include directory have been added to your project.

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 (the file extension .cpp will be added automatically). Make sure the Add to project box is checked.
Adding a new C++ file

Press OK. Now press the + sign by the source label. 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 this 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 code similar to
SimpleWindow MyWin("Your name's winder", 18.0, 11.0) ;
and (on the first line of ApiMain)
MyWin.Open() ;
create a window with the title, "Your name's winder," 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 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.

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. (By the way, you should not have the error shown below.)
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 run the program, you should see four blue columns displayed in a window.
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, mash the "X" in the upper-right hand conner of the window. !

Lab Assignment

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?

Make absolutely sure that you have terminated execution of your program before you try to modify and rebuild it.

Lab Checkoff

Ask your lab instructor to verify that you've modified the stonehedge program to produce the display shown above.

Extra Credit

Just to show off your knowledge of geometry, make the rectangles in Stonehenge Red and rotate the whole thing (window and rectangles) ninety degrees so that Stonehenge is standing on its side. Stonehenge will look like two C's, one above the other.

Extra Credit Checkoff

After you have modified and tested your code, ask your instructor to run it.


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