lesson 27
DESCRIPTION
LESSON 27. Overview of Previous Lesson(s). Over View. Program. Over View. Microsoft Foundation Classes ( MFC ) A set of predefined classes upon which Windows programming with Visual C++ is built. Represents an oo approach to Windows programming that encapsulates the Windows API. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/1.jpg)
LESSON 27
![Page 2: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/2.jpg)
Overview
of
Previous Lesson(s)
![Page 3: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/3.jpg)
3
Over View
Program
![Page 4: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/4.jpg)
4
Over View..
Microsoft Foundation Classes (MFC)
A set of predefined classes upon which Windows programming with Visual C++ is built.
Represents an oo approach to Windows programming that encapsulates the Windows API.
MFC does not adhere strictly to the object – oriented principles of encapsulation and data hiding.
![Page 5: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/5.jpg)
5
Over View…
Windows Form
An entity that represents a window of some kind.
A Windows form is encapsulated by a subclass of the System::Windows::Forms::Form class.
Lets try a Message box with previous Form ..
![Page 6: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/6.jpg)
TODAY’S LESSON
![Page 7: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/7.jpg)
7
Contents
Basic Elements of MFC program Documents View Document Templates Creating MFC Applications
![Page 8: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/8.jpg)
8
Basic Elements of MFC
The structure of an MFC program incorporates two application - oriented entities.
A document
A view
![Page 9: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/9.jpg)
9
What is a document ??
A document is the collection of data in our application with which the user interacts.
It could be a data for
A game A geometric model, A text file or anything we want.
![Page 10: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/10.jpg)
10
What is a document..
Document class is derived from the CDocument class in the MFC library.
Application is not limited to a single document type.
We can define multiple document classes when there are several different kinds of documents involved in application.
![Page 11: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/11.jpg)
11
Document Interfaces
The Single Document Interface (SDI), is supported by the MFC library for programs that require only one document to be open at a time.
A program using this interface is referred to as an SDI application.
MDI is used for programs needing several documents to be open at one time.
![Page 12: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/12.jpg)
12
MDI
MDI manages to handle
Multiple documents of one type.
Documents of different types simultaneously with each document displayed in its own window.
Each document is displayed in a child window of the application window.
![Page 13: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/13.jpg)
13
View A view is an object that provides a mechanism for displaying some
or all of the data stored in a document.
It defines how the data is to be displayed in a window How the user can interact with it.
Application view class be derived from the MFC class Cview.
The window in which a view appears is called a frame window.
![Page 14: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/14.jpg)
14
Views
![Page 15: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/15.jpg)
15
What is a View..
A document object can have many view objects.
Each view object can provide a different presentation of the document data or a subset of the same data.
For a program handling graphical data,
We could display all of the document data at different scales in separate windows, and also in different formats.
![Page 16: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/16.jpg)
16
Linking
MFC incorporates a mechanism for integrating
A document with its views &
Each frame window with a currently active view.
A document object automatically maintains a list of pointers to its associated views.
A view object has a data member holding a pointer to the document that relates to it.
![Page 17: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/17.jpg)
17
Linking..
Each frame window stores a pointer to the currently active view object.
The coordination among a document, a view, and a frame window is established by another MFC class of objects called document templates.
Document
FrameView
![Page 18: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/18.jpg)
18
Document Templates
A Document template manages
The document objects. The windows frames & The views associated with each of them.
One document template for each type of document.
![Page 19: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/19.jpg)
19
Over View… Document Templates
One document template is required for two or more documents of the same type.
A document template object creates
Document objects.Frame window objects.Views of a document are created by a frame window object.
![Page 20: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/20.jpg)
20
Document Templates..
![Page 21: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/21.jpg)
21
Document Template Classes
MFC has two classes for defining document templates.
For SDI applications CSingleDocTemplate Has only one document and usually just one view.
For MDI applications CMultiDocTemplate
Have multiple documents active at one time, so many views.
![Page 22: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/22.jpg)
22
Our Application & MFC
Our Application Classes
![Page 23: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/23.jpg)
23
Over View…
MFC provides several variations of the view class that provide a lot of functionality prepackaged.
Standard MFC class CSingleDocTemplate usually suffices in an SDI program.
For MDI program, our document template class is CMultiDocTemplate, which is also derived from CDocTemplate
![Page 24: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/24.jpg)
24
MFC Application For development we will use 4 primary tools.
Application Wizard for creating the basic application program code.
Project context menu in ClassView to add new classes and resources.
Class context menu in ClassView for extending and customizing the existing classes.
Resource Editor for creating or modifying objects as menus and toolbars.
![Page 25: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/25.jpg)
25
MFC Application..
![Page 26: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/26.jpg)
26
MFC Application...
![Page 27: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/27.jpg)
27
SDI Application
![Page 28: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/28.jpg)
28
SDI Application..
![Page 29: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/29.jpg)
29
SDI Application…
MFC library as a shared DLL .
Reduces the size of the executable file.
Requires the MFC DLL to be on the machine that ’ s running it.
The two modules together (.exe module and the MFC .dll ) may be bigger than statically linked the MFC library.
![Page 30: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/30.jpg)
30
SDI Application…
Static linking.
MFC library routines are included in the executable module for program when it is built.
Statically linked applications run slightly faster.
Tradeoff between memory usage and speed of execution
![Page 31: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/31.jpg)
31
SDI Application… User Interface Features
![Page 32: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/32.jpg)
32
SDI Application… Generated Classes
![Page 33: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/33.jpg)
33
View Classes View Classes capabilities depends on the base class
![Page 34: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/34.jpg)
34
Wizard Output
All the program files generated by the Application Wizard are stored in the TextEditor project folder. Subfolder to the solution folder with the same name.
There are also resource files in the res subfolder to the project folder.
The IDE provides several ways to view the information relating to project.
![Page 35: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/35.jpg)
35
Wizard Output..
![Page 36: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/36.jpg)
36
Project Files
19 files shown in the project, excluding ReadMe.txt.
Can view the contents of any of the file.
Contents of the file selected are displayed in the Editor window.
![Page 37: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/37.jpg)
37
Viewing Classes
CTextEditorDoc shows the Class View pane in its docked state
![Page 38: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/38.jpg)
38
Viewing Classes..
Select Global Functions and Variables.
The application object, theApp , appears twice
There is an extern statement for theApp in TextEditor.h and the definition for theApp is in TextEditor.cpp .
Double - click either of the appearances of theApp in Class View, it will leads to the corresponding statement.
![Page 39: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/39.jpg)
39
Viewing Classes..
Indicators is an array of indicators recording the status of
caps lock num lock scroll lock
The remaining three variables relate to the management of the toolbars in the application
![Page 40: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/40.jpg)
40
Code
These are all files for this project.
Will discuss it next time…
![Page 41: LESSON 27](https://reader036.vdocuments.net/reader036/viewer/2022062409/56814b43550346895db845c2/html5/thumbnails/41.jpg)
41
Thank You