Introduction To Visual C++

by
Matthew Martin
Contents
Creating
Applications With App Wizard
Step
1
Step
2
Step
3
Step
4
Step
5
Step
6
New
Project Information
Looking
At Your First Visual C++ Program
Running
Your Program
About
The IDE

In this course we will be using Microsoft’s development
tool, Visual C++ (v6). C++ is an extension of the programming language
C. C++ gets its name from the fact that it is an iteration of C. C++ was
developed by Stroustrup, who now has a chair at MIT. There are number
of development tools available for C++, Microsoft’s Visual C++ is
but one of these.
Unlike C, there is no agreed ANSI standard for C++. In
fact there are a number of standards preferred by different programmers
and for different development tools. Since we are using Microsoft’s
development tool, we will be using Microsoft’s preferred programming
standards. We will explore these later in the course.
top
of page

Creating Applications With App Wizard
Visual C++ not just used by the programmer entering code,
it can also automatically generate code. Although App Wizard will not
do all the work for you, it helps a great deal. App Wizard can help in
creating a range of different programs.
Starting The App Wizard
To start App Wizard:
Choose File, New and click the Projects tab in the New dialog box.
Enter a name for the project. It is important to choose
a good, meaningful name, since this will be used for classes and files
used in the project. Then choose MFC AppWizard (EXE) from the list box
on the left, fill in a project name, and click OK. AppWizard will work
through a number of steps. At each step, you make a decision about what
kind of application you want and then click Next. At any time, you can
click Back to return to a previous decision, Cancel to abandon the whole
process, Help for more details, or Finish to skip to the end and create
the application without answering any more questions.
Throughout the App Wizard use the Next button to advance
(do not use the Finish button).
top
of page
Step 1 – Types of Document
Single Document Interface A single document interface (SDI) application
(e.g. Notepad) has only one document open at a time. When you choose File,
Open, the currently open file is closed before the new one is opened.
Multiple Document Interface A multiple document interface (MDI) application
(e.g. Excel or Word) can open many documents at once. There is a Window
menu and a Close item on the File menu.
Dialog-Based A dialog-based application does not have a document at all,
there are no menus. An example is the Character Map, found in Accessories
under Windows.
Beneath these choices is a checkbox for you to indicate
whether you want support for the Document/View architecture. For the moment
we will ignore this.
Language
Make sure that the system language and the language you are programming
in are the same. If you do not match the two, you may encounter problems
later. The system language is set in Control Panel in Windows. We are
will use the default of English (US), although the system language is
English (UK), this is okay.
top
of page
Step 2 – Databases
There are four options to choose from:
Choose None if you aren't writing a database application.
If you want to have access to a database but don't want to derive your
view from CFormView or have a Record menu, choose Header Files Only.
If you want to derive your view from CFormView and have a Record menu
but don't need to serialize a document, choose Database View Without File
Support.
If you want to support databases as in the previous option but also need
to save a document on disk, choose Database View With File Support.
For our first application we will not be using a database,
so choose none.
top
of page
Step 3 – Compound Document Support
There are five options for compound document support:
Choose None if you are not writing an ActiveX application.
If you want your application to contain embedded or linked ActiveX objects,
such as Word documents or Excel worksheets, choose Container.
If you want your application to serve objects that can be embedded in
other applications, but it never needs to run as a standalone application,
choose Mini Server.
If your application serves documents and also functions as a standalone
application, choose Full Server
If you want your application to have the capability to contain objects
from other applications and also to serve its objects to other applications,
choose Both Container and Server.
N.B.: ActiveX used to be called OLE (object linking and embedding). To
build an ActiveX control you need to use the ActiveX Control Wizard. In
the App Wizard you can just make an application that is ActiveX compatible.
top
of page
Step 4 – Features
There are a number of options that provide additional features and affect
the appearance of the application. The following are the options are available:
Docking Toolbar AppWizard sets up a toolbar for you. You can edit it to
remove unwanted buttons or to add new ones linked to your own menu items.
Initial Status Bar AppWizard creates a status bar to display menu prompts
and other messages.
Printing and Print Preview Your application will have Print and Print
Preview options on the File menu, and much of the code you need in order
to implement printing will be generated by AppWizard.
Context-Sensitive Help Your Help menu will gain Index and Using Help options,
and some of the code needed to implement Help will be provided by AppWizard.
3D Controls Your application will look like a typical Windows 95 application.
If you don't select this option, your dialog boxes will have a white background,
and there will be no shadows around the edges of edit boxes, check boxes,
and other controls.
MAPI (Messaging Application Programmers Interface) Your application will
be able to use the Messaging API to send fax, email, or other messages.
Windows Sockets Your application can access the Internet directly, using
protocols like FTP and HTTP (the World Wide Web protocol).
The Advanced button provides additional features for your application,
such as defining the type of file extensions it uses, but we will not
go into the details of these here.
top
of page
Step 5 – Additional Project Options
This step deals with the some additional options.
Firstly, what style of project do you want? In most cases this is likely
to be MFC.
Secondly, do you want comments in the code? This is
always a good idea.
Thirdly, how do you want to access the MFC library? There
are two options: as a dll (Dynamic Link Library) or as a statically linked
library. A static library is easier to manage and install but is larger
than a dynamic link library. The static is easier so we will start with
this.
A Little About Dynamic Link Libraries
A dynamic link library (DLL) is a collection of functions used by many
different applications. Using a DLL makes your programs smaller but makes
the installation a little more complex. Dynamic link library files are
used a lot in Windows. They allow functions used by many applications
to be contained within a single piece of code. Clearly this has a number
of advantages, can you think what these are? Dynamic link library files
have the file extension .dll.
top
of page
Step 6 – Class & File Names
The final step is where you choose the class and file names used in the
project. The default names used are taken from the name that you gave
the project at the beginning. It is usually okay to use the defaults,
providing you chose a sensible name for your project at the beginning.
top
of page

New Project Information
At the end of the App Wizard a window is displayed showing a summary of
the project. read through this and then click OK to finish the App Wizard.
top
of page
Looking At Your First Visual C++ Project
Now that you have created your first project in Visual C++, lets take
a look at it. The integrated development environment (IDE) for Visual
C++ is shown in figure 2.
top
of page
Running Your First Program
You can run (execute) your program by hitting the button with the exclamation
mark (!). You will be asked if you want to create a debug file, do so
(OK). The program will build (compile and link). The progress of the compilation
is shown in the bottom window, the build window. If there are any errors,
these are reported in the debug window. Once the program has compiled
and linked, it will execute. Have a look at your program and look at the
menus and buttons.
top
of page

About the IDE
On the left is a panel with three tabs at the bottom. The three tabs are:
ClassView This shows the classes that are used.
ResourceView This shows the dialogues, icons, menus,
toolbars, etc used.
FileView This show all the source files, where the code
is stored.
Start by looking through the build window to review the
actions taken by the IDE during the build process. It is possible, and
sometimes useful, to build without executing. If the execution button
is used when the program needs to be built, then the build process is
automatically invoked.
Have a look at the ClassView, and reviewing the classes
used for this project. Then move onto the FileView, reviewing the source
code pf each file.

by
Matthew Martin
|