Tutorial Exercise 2

advertisement
Tutorial Exercise 2
CS3162 Introduction to Computer Graphics
Helena Wong, 2001
Try to compile, run and modify a Visual C++ program. The things you learn in this exercise will also be
applied in the assignments which will be given to you later on.
1.
Create a directory in the hard disk named "c:\temp\TwoDEx". If there is already such a directory, remove it
and re-create. Download the sample program files into this directory from the course web page.
2.
Start the Visual C++ program from Start Menu \ Microsoft Visual Studio.
3.
Use the File \ Open Workspace command to open the "TwoDEx.dsw" project file in "c:\temp\TwoDEx".
4.
Use the Build \ Build TwoDEx.exe command to compile the program files into an executable
"TwoDEx.exe" file, which will be located in the directory "c:\temp\ TwoDEx \Debug".
5.
Use the Build \ Execute TwoDEx.exe command to run this program.
6.
Instead of step 5, you can also invoke "TwoDEx.exe" from windows explorer by switching to the "c:\temp\
TwoDEx \Debug" directory and double click the "TwoDEx.exe" file. – Try this.
7.
In VC++, use the Build \ Set Active Configuration command to select Win32 Release configuration, then,
the next time you compile the executable "TwoDEx.exe" file, this "TwoDEx.exe" file will be located in the
"c:\temp\ TwoDEx \Release" directory. Note that this Win32 Release configuration gives you much
smaller file size of the executable "TwoDEx.exe" file. – Try comparing these file sizes.
However, the default Win32 Debug configuration, though gives a bigger "TwoDEx.exe" file, can allow you
to do debugging tasks. – You’ll try in step 9.
8.
In the Workspace window, select FileView page, double click the "Painting.cpp"
file under Source Files in this FileView page. Try to understand the content of
the InitializeSettings and DoPainting functions in this "Painting.cpp" file.
9.
Try use the debug tools to trace the program.
A. Set “Win32 Debug Configuration” as active configuration.
B. Click at the statement “for (x=100;x<300;x=x+1)” in Painting.cpp.
C. Press F9 to set a breakpoint here (You may press F9 again to remove it).
D. Use the “Build\Start Debug\Go” command to start running.
E. When it stops at “for (x=100;x<300;x=x+1)”, use the “Debug\Step Over”
command to continue tracing.
F. Drag the word “green” in Painting.cpp to the watch window and see what
happens. (The watch window can be invoked by “View\Debug Windows”.
G. Continue using commands in the “Debug” menu to run the program.
10. Try to modify this DoPainting function to show some other dots or lines in different color. Repeat steps 4
and 5 for testing.
11. In the Workspace window, select the ResourceView page. Under TwoDEx resources, double click
IDB_BITMAP2 under Bitmap. Modify this picture. Repeat step 4 and 5 for testing.
12. Right click IDB_BITMAP2 and select Insert Bitmap to create a new bitmap called IDB_BITMAP3. Draw
something in this bitmap.
13. Switch to the "Painting.cpp" file as in Step 8. Modify the code in the DoPainting function so that it also
paints IDB_BITMAP3. Repeat step 4 and 5 for testing.
14. In the Resource View page, right click TwoDEx resources and select “Import”. Browse the c:\winnt
directory or c:\winnt\system32 directory to find some bitmap image file with the name like “*.bmp” and
import it. How to modify DoPainting to show this image file?
15. Inspect the directory “c:\temp\TwoDEx” and the sub-directories under it. Which files are essential and
which files are temporary ones? (Hints: compare the files provided to you from the course web page).
Later when you submit assignment one, you’ll only need to submit the essential files, in a single
floppy disk.
Workspace
window
Select
FileView
page
Download