Introduction to Visual Studio 2005

A Visual Guide to the Basics of using Visual Studio 2005
  1. Starting Visual Studio 2005
  2. The Visual Studio 2005 Welcome Screen
  3. Starting a New Project
    1. Creating a Win32 Console Application
    2. Project Settings: Step 1
    3. Project Settings: Step 2
    4. Project/Solution Explorer
  4. Adding files to a Project
    1. Selecting the File Type & Naming
    2. The Empty File
  5. "Hello World!"
    1. Building "Hello World!"
    2. The Build Output
    3. Running "Hello World!"
    4. The Output of "Hello World!"
  6. Creating a ZIP File of Your Entire Project
    1. Creating a ZIP Step 1
    2. Creating a ZIP Step 2

1. Starting Visual Studio 2005

After you login, you can start Microsoft Visual Studio 2005 by doing the following:
  1. Click the START button
  2. Select the All Programs folder
  3. Select the Computer Science folder
  4. Select the Microsoft Visual Studio 2005 folder
  5. Click the Microsoft Visual Studio 2005 icon

2. The Visual Studio 2005 Welcome Screen

After you start Visual Studio, you'll see the following:
  • A narrow window on the right called the Solution Explorer, which will be empty initially. When you start a new Project (or open an existing one), the files of that project will be displayed here in a manner similar to that when you browse your filesystem.
  • A wide window on the bottom called the Code Definition window. The purpose of this window will change as you do various things, some of which will be discussed below.
  • The Start Page, which will take up most of the screen. This could be called (loosely) the work area, and is where you will actually write most of your code. Whenever you add new files to a project or open existing ones, you'll see the file opened here.
The configuration described above (and what you see to the right) can be configured to your liking. This is simply the default configuration.

3. Starting a New Project

When writing software in Visual Studio there may be many source files and various resource files. The notion of a Project in Visual Studio is a way of encapsulating all of the files that are part of a piece of software into a single entity. Thus, before you can ever start to program in Visual Studio, you must create a Project.

To start a new project, do the following:
  1. Click the File button in the top-right
  2. Select New
  3. Click Project...
After doing that, a series of windows will pop-up asking you what type of project you would like to create, what name you would like to give the project, and what options you would like to setup initially for the project. See below for details.

3.1. Creating a Win32 Console Application

Although Visual Studio 2005 can assist you in creating large, complex pieces of software, for the purpose of this class we are starting small, and creating a simple Console Application (one where all input & output is done via a simple terminal).

To create such an application, do the following:
  1. Make sure that in the Project Types window on the left, Visual C++ is selected and expanded.
    See 1 in the image to the right.
  2. Make sure that the Win32 option is then selected
    See 2 in the image to the right.
  3. Then, in the Templates section, make sure you have selected Win32 Console Application
    See 3 in the image to the right.
  4. Now you must give the project a name. For the purpose of this class, you asked to use the following format:
    LabXTaskY-FirstnameLastname
    where X is the lab number and Y is the task you are doing. As an example, suppose this project was for Task 2 of Lab 3. The name used should be
    Lab3Task2-RyanFlannery

    See 4 in the image to the right.
  5. Make sure that you are saving the project in a location where you will remember it. A good idea is to save it somewhere in your My Documents folder.
    See 5 in the image to the right.
After you have done the above, click the OK button in the bottom right to continue.

You should know that to encapsulate all of the files associated with the project, Visual Studio will create a directory named whatever you named project (in step 4), and all files associated with the project will be placed within this directory. The directory will be created in the location specified in step 5.

3.2. Project Settings: Step 1

For this step, simply click the Next button in the bottom right.

3.3. Project Settings: Step 2

Here we could setup a few different types of applications which are quite common when developing software on Windows. Again, for the purpose of this class, we want to create a simple console application with no assistance from Visual Studio.

To do that, make sure you select the following:
  1. Make sure that the Application Type is set to Console Application.
    See 1 in the image to the right.
  2. Under Additional Settings, make sure Empty Project is selected.
    See 2 in the image to the right.
  3. If you have done the above two options correctly, neither of the Common Header Files should be available for selection.
Once you have finished the above, click the Finish button in the lower right.

3.4. Project/Solution Explorer

After you have completed the steps above, you'll return to Visual Studio 2005 and in the narrow window on the left (the Solution Explorer) you'll now see the project you have just created. Within that project will be a few default directories where we can now add source code to actually do something.

4. Adding Files to a Project

Before writing source code, we must add a file to the project where we can store the source code.
  1. Right-click on the Source Files directory of your project (in the Solution Explorer window)
  2. Select the Add option
  3. Click New Item...

4.1. Selecting the File Type & Naming

In the window that appears, you must do the following:
  1. On the left side of the screen in the Categories window, make sure that the Code option is selected
    See 1 in the image to the right.
  2. On the right side of the screen in the Templates window, make sure that C++ File (.cpp) is selected
    See 2 in the image to the right.
  3. Finally, near the bottom of the window you must provide a name for your file. The name shouild be something that describes what the file will contain.
    See 3 in the image to the right.
Once you are finished with the above, click the Add button in the lower right corner of the window.

4.2. The Empty File

After you have completed the steps above, you'll return to the main Visual Studio window and see the following:
  • A new file appears in the Source Files folder of your project in the Solution Explorer window.
    See 1 in the image to the right.
  • The file will actually be opened for editting, although it will appear initially blank. As you can open multiple files at the same time in Visual Studio, a tab appears at the top of the work area to to let you browse through each opened file.
    See 2 in the image to the right.
  • To close the opened file (but not close Visual Studio), you can click the X in the top-right of the work window.
    See 3 in the image to the right.

5. "Hello World!"

Now that you have successfully created a Project and added files to the project, it's time to start programming. The following is a simple program that all students first learn to write, called the "Hello World!" program.

Open the file that you just added to the Project (if you haven't closed it, it should still be open), and type in the code that you see in the image on the right.

Note that the color of the code is added automatically by Visual Studio, and simply serves to help people read and understand the code more easily.

5.1. Building "Hello World!"

After you have added the code as you see above, it's time to build the program that your source code specifies (this is also called compiling). To do this:
  1. Click the Build menu at the top of Visual Studio
  2. Select the Build Solution option in the menu that appears

5.2. The Build Output

When building your source code into a program, Visual Studio will report any errors or warnings in the Output window at the bottom of the screen.

The last line of the output is a summary of all of the previous lines. If you have typed everything in correctly, you should see 1 succeeded, like in the image to the right.

Otherwise, you have typed something in that is not "correct" C++, and Visual Studio will tell you where your error is at.

5.3. Running "Hello World!"

After you have successfully built your solution as described in the previous step, you have a program that you can run.

To run your program, do the following:
  1. Click the Debug menu at the top of Visual Studio
  2. Click the Start Without Debugging option
After that, a terminal window will open and you will see your program running.

5.4. The Output of "Hello World!"

When you run your program, you will see the output of it in the terminal window. For the "Hello World!" program, this is simply
      Hello World!
      Press any key to continue . . .
   
Note that the "Press any key to continue . . ." is added by Visual Studio, so that you window does not automatically close after the program completes.

NOTE: If you have your projects stored in your My Documents folder (the default location), you'll see a warning similar to the one in the image to the right. While this warning message is annoying, it will not cause any serious problems and can be safely ignored.

6. Creating a ZIP File of Your Entire Project

Now that you have successfully created a Project with source code that runs a program, you might be asked to submit a digital copy of everything for grading.

To do this, open up Windows Explorer and traverse to the directory where you saved the project.
NOTE: This location is the exact same directory that you specified in step 5 of 3.1 Creating a Win32 Console Application above!
In the image to the right, you'll see that the location shown at the top of Windows Explorer is exactly the same as what we specified in step 5 of 3.1 Creating a Win32 Console Application above.

Once you have browsed to the correct location, you'll see a directory with the same name as the project you created.

To create a ZIP archive of this entire project, do the following:
  1. Right-click on the directory that corresponds to the project you want to ZIP
  2. Click the Add to archive... option
You will then be asked a few questions about what type of archive you would like to create. See below for details.

NOTE: You should close Visual Studio when creating this ZIP file. If you do not, the archiver may give an error saying that "some files are currently in use and cannot be archived".

6.1 Creating a ZIP Step 1

The arvhiver can produce two different types of archives... RAR format archives and ZIP format archives. To create a ZIP version, make sure that the ZIP option is selected in the Archive Format window in the image to the right.

Once you have done that, click the OK button in the bottom right of the window, and the ZIP file will be created.

6.2 The ZIP File Itself

After you have completed the above, you'll see a new file in the projects directory. It will have the same name as the project directory, but it will be a single file (a ZIP file), and not a directory.
See the image to the right.

It is this ZIP file that you should submit whenever a digital copy of your code or project is required.



Ryan Flannery (ryan.flannery@gmail.com), 10 April 2008