VC++ Programming @ UESTC
Lecturer,
WEI Zukuan (魏祖宽 )
mobile,138-8178-0874
eMail,anlexwee@UESTC.edu.cn
Visual C++ Programming Fundamentals
VC++ Programming @ UESTC
Visual C++ Programming Fundamentals
Prerequisites,
C++ Language
Concept of Object-Oriented Programming (OOP)
Windows Programming?
Textbook,
“Inside Visual C++” Fourth Edition
by David J,Kruglinski
Class Hours,
32 Hours for class,8 Hours for lab
Home Works:
2 home projects
Test:
As School Required
VC++ Programming @ UESTC
3
Introduction
About Content
In this class,we will cover the basic skills of windows
programming under Microsoft platform,
The students will learn step by step to use object-oriented
design (OOD) strategy to develop professional projects
There are four parts in this class,they are,
MFC document-view architecture,
Database Management,
Dynamic link library(DLL),
Graphics user interface(GUI),
VC++ Programming @ UESTC
4
Introduction
About Help in Studying
Useful Web links for Visual C++
http://msdn.microsoft.com/visualc/
http://msdn.microsoft.com/visualc/support/
http://www.funducode.com/freevc.asp
Post your questions,look at discussion and articles and
even download source codes from some expert
programmers.
Use Microsoft developer network library CDs (MSDN)
VC++ Programming @ UESTC
5
Part I Windows,Visual C++ and
Application Framework Fundamentals
Chapter 1
Microsoft Windows and Visual C++
Chapter 2
The Microsoft Foundation Class Library
Application Framework
VC++ Programming @ UESTC
6
VC++ History
In the old days,Console applications force users to do
what is given to them,There’s only one executing thread
within an application,
The basic building block for displaying information in the
Microsoft? Windows? graphical environment is the
window.
Windows applications give users a lot of choices so the
tasks are much more difficult than before,
On platforms of windows NT,Windows 95 and later,
multitask can be done with windows applications.
Chapter 1 Microsoft Windows and
Visual C++
VC++ Programming @ UESTC
7
VC++ & MFC
Visual C++ provides a professional environment for
developing the high-performance windows application.
– VC++ version 1.* (MFC2.0) released on earlier 1990’s,
VC++ Version 1.5(MFC2.5) contributed ODBC(Open
Database Connectivity) support.
– VC++ version 2.0(MFC3.0) was the first 32-bit product.
– VC++ 3.0 was skipped.
– VC++ 4.2 (MFC4.2) synchronize the product version with
MFC version.
– VC++ 5.0 (MFC4.21) does support ATL and
COM(Component Object Model).
Chapter 1 Microsoft Windows and
Visual C++
VC++ Programming @ UESTC
8
VC++ 6.0
There’re three versions of VC++ 6.0 (MFC6.0),
1) standard 2) professional 3) enterprise.
Enterprise edition has supports for
visual SourceSafe,
SQL server and
transaction server.
Chapter 1 Microsoft Windows and
Visual C++
VC++ Programming @ UESTC
9
What is Visual C++?
It is not only a simple C++ compiler plus some
visual graphics tools,
Instead it presents us a sophisticated development
environments with professional supports such as
Microsoft Foundation Class(MFC),Active
Template Library(ATL),etc,
It is a high-performance development tool from MS.
Chapter 1 Microsoft Windows and
Visual C++
VC++ Programming @ UESTC
10
Why do we choose VC++?
There’re several other choices existing on the market.
– VC++ vs Java
1,Microsoft makes a promise to support Visual C++ in the
future.
2,Microsoft products survives longer than most of the
competitors’ products partly because of its huge
economical power.
3,There’s a bigger programmer pool for Visual C++ than
Java.
Chapter 1 Microsoft Windows and
Visual C++
VC++ Programming @ UESTC
11
– VC++ vs Java
3,VC++ is Real executable (Efficiency ),Java is dependent
on Virtual Machine (Flexibility) and can run anywhere.
So there’s a tradeoff.
4,Java is more beautiful in the language design architecture
but Visual C++ is testified more widely in the real world.
5,VC++.net is easier to learn if you know VC++6.0.
Chapter 1 Microsoft Windows and
Visual C++
VC++ Programming @ UESTC
12
– VC++ vs Visual Basic
1,VB gained many third party supports and is
widely used in somewhat quick programming.
2,VB is not real Object-Oriented Language,no data
inheritance.
3,VB is single-threaded so is not efficient for heavy
jobs under the complicated situation.
Chapter 1 Microsoft Windows and
Visual C++
VC++ Programming @ UESTC
13
Windows Programming Model
– Message Processing
– The Windows GDI
– Resource-Based Programming
– Memory Mangement
– DDL (Dynamic Link Libraries)
– The Win32 API
Chapter 1 Microsoft Windows and
Visual C++
VC++ Programming @ UESTC
14
Visual C++ components
Developer Studio
– Resource Editor –Workspace ResourceView
– C/C++ Compiler
– Resource Compiler
– Linker
– Debugger
– AppWizard
– ClassWizard
– Source Browser
– Online Help
Chapter 1 Microsoft Windows and
Visual C++
VC++ Programming @ UESTC
15
Visual C++ components
Microsoft Visual C++ is two complete Windows application
development system in one product,MFC and ATL,This
class is about C++ programming within the MFC library
application framework.
Microsoft Foundation Class (MFC)
Active Template Library (ATL)
,
Chapter 1 Microsoft Windows and
Visual C++
VC++ Programming @ UESTC
16
Developer Studio is a Windows-hosted integrated
development environment(IDE) that’s shared by
Visual C++,Microsoft Visual J++,Microsoft
Visual Basic and several other products.
Workspace window is the place where
programmers to develop specific projects and used
in all of the above environment.
A project is a collection of integrated source files
that are compiled and linked to make up an
executable Windows-based program or a DLL.
Chapter 1 Microsoft Windows and
Visual C++
VC++ Programming @ UESTC
17
Chapter 1 Microsoft Windows and
Visual C++
WorkSpace
VC++ Programming @ UESTC
18
The following lists the files that is generated in the
workspace.
File Extension Description
APS Supports Resource View
BSC Browser information file
CLW Supports ClassWizard
DSP Project file
DSW Workspace file
MAK External makefile
NCB Supports ClassView
OPT Holds workspace configuration
PLG Build log file
Chapter 1 Microsoft Windows and
Visual C++
VC++ Programming @ UESTC
19
Resource Editor
Chapter 1 Microsoft Windows and
Visual C++
VC++ Programming @ UESTC
20
Chapter 1 Microsoft Windows and
Visual C++
MFC ClassWizard
VC++ Programming @ UESTC
21
Chapter 1 Microsoft Windows and
Visual C++
Source Browser
VC++ Programming @ UESTC
22
Chapter 1 Microsoft Windows and
Visual C++
Source Browser
VC++ Programming @ UESTC
23
AppWizard is a code generator that creates a working
skeleton of a Windows application with features,class
names,and source code filenames that you specify through
dialog boxes.
Types of projects
MFC AppWizard(DLL)
MFC AppWizard(EXE)
Win32 Console Application
…………..
Chapter 1 Microsoft Windows and
Visual C++
VC++ Programming @ UESTC
24
Chapter 1 Microsoft Windows and
Visual C++
AppWizard
VC++ Programming @ UESTC
25
Online help and MSDN library
Chapter 1 Microsoft Windows and
Visual C++
VC++ Programming @ UESTC
26
Chapter 1 Microsoft Windows and
Visual C++
VC++ Programming @ UESTC
27
Visual C++ components
Developer Studio
– Resource Editor –Workspace ResourceView
– C/C++ Compiler
– Resource Compiler
– Linker
– Debugger
– AppWizard
– ClassWizard
– Source Browser
– Online Help
Chapter 1 Microsoft Windows and
Visual C++
VC++ Programming @ UESTC
28
Chapter 2 The Microsoft Foundation Class Library
Application Framework
MFC library is a C++ Windows programming
interface.
Application Framework defines the structure of the
program itself.
Learning curve vs,MFC application framework
power
Message Mapping
Document and View
VC++ Programming @ UESTC
29
What is Application Framework?
It is a superset of class library,
It contains class libraries.
More importantly,it defines the programming itself.
Chapter 2 The Microsoft Foundation Class Library
Application Framework
VC++ Programming @ UESTC
30
Why do we choose MFC application framework?
Facts,there’s a big learning curve with MFC library.
What benefits can justify this effort?
Better interface than Microsoft Windows API;
Use a standard structure;
Small and fast;
Provide efficient C++ tools;
Feature-rich.
Chapter 2 The Microsoft Foundation Class Library
Application Framework
VC++ Programming @ UESTC
31
MFC Message Mapping
Why does MFC library not use virtual function for
windows messages?
vtable will consume memory for virtual message handler;
we can’t define virtual functions in a base class for menu
command message;
MFC uses macros to connect(or map) Windows
messages to a C++ member functions.
Chapter 2 The Microsoft Foundation Class Library
Application Framework
VC++ Programming @ UESTC
32
Document and View
The document-view architecture is the core of the
application framework and is based on the
Model/View/Controller mechanism.
This mechanism is widely used in today’s OOD
windows programming world such as J2EE(outside of
Microsoft world).
Chapter 2 The Microsoft Foundation Class Library
Application Framework
VC++ Programming @ UESTC
33
This document-view architecture separates data from the
user’s view of the data,
multiple views vs,one document
document relates to data
view relates how we look at them
This document-view architecture provides another abstract
layer for programming.
Chapter 2 The Microsoft Foundation Class Library
Application Framework
VC++ Programming @ UESTC
34
In an MFC library application,documents and views are
represented by instances of C++ classes.
File Open and File Save menu items interact with
document base class code.
Document is not necessarily associated with database.
Programmer may override the document class member
functions and File Open menu item to do customized work.
Chapter 2 The Microsoft Foundation Class Library
Application Framework