UB CS 400 - Microsoft Foundation Classes

Unformatted text preview:

The Microsoft Foundation Class Library (MFC) is an "application framework" for programming in Microsoft Windows. Written in C++, MFC provides much of the code necessary for managing windows, menus, and dialog boxes; performing basic input/output; storing collections of data objects; and so on. All you need to do is add your application-specific code into this framework.Class OverviewThe CObject Base ClassThe Document/View ArchitectureGraphics Drawing SupportDialog SupportOther User Interface FeaturesCObject*MFC common base classMFC HandoutPurpose: Handout to understand the basic concepts of MFC ( Microsoft Foundation ClassesIntended Audience: Students interested to learn advanced OOPS programming using RAD (Rapid Application Development) tools. Prerequisites: C++, Visual Studio (VB, VC++)MFC Overview:The Microsoft Foundation Class Library (MFC) is an "application framework" for programming in Microsoft Windows. Written in C++, MFC provides much of the code necessary for managing windows, menus, and dialog boxes; performing basic input/output; storing collections of data objects; and so on. All you need to do is add yourapplication-specific code into this framework.Class OverviewMFC contains well over 200 classes. These can be divided into several categories. A number of classes are involved in creating a graphical application user interface, such as frames, views, menus, dialogs and dialog controls. Other categories include graphics drawing classes, file and socket classes, database access classes, thread support and synchronization classes, OLE (Object Linking and Embedding) support classes, Internet support classes, collection classes such as arrays, lists, and maps, and a large number of other support classes.The CObject Base ClassMost MFC classes are subclasses of CObject. This class provides a number of important services. The first of these is object creation with a CRuntimeClass object. An instance of CRuntimeClass contains the method CreateObject() that uses a function pointer data member to create an instance of some CObject subclass that supports dynamic creation. The CObject subclasses contain a CRuntimeClass reference, so that the exact subclass of any object can be determined at run time.Another importart concept supported by CObject is serialization, the ability to store and retrieve instances of the class to and from external storage, such as files. This can be usedto implement object persistence, OLE, and other useful mechanisms. Also, non-homogenous, type-safe collections of CObject subclasses are supported.The Document/View ArchitectureAll graphical MFC applications have to be based on MFC's document/view structure. Theapplication defines one or more document templates (CDocTemplate subclass) that contain CRuntimeClass references the following three classes:- a document class (CDocument subclass), - a frame class (CFrameWnd subclass), - a view class (CView subclass). The document class contains the internal representation of the application data. An instance is created by the framework for each new or opened document. The frame class describes the user interface of document windows of the application, typically multiple-document interface (MDI) frames. The view class shows a graphical representation of thedocument type. All classes as CObject subclasses.A number of overridable methods in each of these classes allow the application to represent almost any kind of document. This basic structure is supported by a large number of support services, such as transparent printing and print preview support and OLE support.Graphics Drawing SupportThe graphics drawing support classes are modeled on the Win32 Graphics Device Interface (GDI). A number of convenience classes as well as overloaded constructors provide more flexible tools for drawing than the Win32 API, although the basic concepts are the same in MFC. Allocating and deallocating GDI resources and other error-prone tasks are simplified as the standard overridable methods in the CView class provide a default structure for implementing drawing accepting user input in a graphical application.Dialog SupportMFC contains numerous classes for creating forms and other dialogs. The standard Windows controls are supported as well as the standard Windows common dialogs. Also, the Windows 95 new common controls and common dialogs are supported. MFC defines a standard dialog data exchange and dialog data validation (DDX/DDV) mechanism that provides a default structure for manipulating dialog data entered by the user. The record set and record view classes work with the database access classes, simplifying the displayand editing of database rows presented on forms.Other User Interface FeaturesThe menu, toolbar, tabbed dialog, and status bar classes implement the latest Windows look and feel. The visual editing server and container classes, automation server and client classes, and other OLE support classes help implement object linking and embedding, the Windows standard data exchange between applications. The basic structure for an OLE support is present in these and the document/view classes, but a lot of work is left for the application codeMFC Hierarchy:CObject* MFC common base classCGdiObject* Graphical device interface classCPen Class used for drawing patterns and colorsCBrush Class that represents fill patterns and colorsCFont Font classCBitmap Bitmap classCDC* Device context base classCClientDC Client area device context classCPaintDC Painting area device context classCMenu Menu classCCmdTarget* Event-messages target base classCWnd* Window base classCDialog Dialog box window classCStatic Static control class( for text labels)CButton Button control classCListBox List box control classCComboBox Combo box control classCEdit Edit box control classCFrameWnd Frame window classCWinThread* Task thread base classCWinApp Windows application classMFC Example:Creating a MFC Project using VB.NET Step 1: Select File New ProjectMFC Application and press OK. As shown belowStep 2: Select Dialog Based as application type and make sure MFC standard and Use MFC in a shared DLL are selected. Finally click on Finish button to create a project.You will get a Dialog,where you can create your own dialog controls like List Box, Buttons, Combo Box etc.,Step 3: Let us create a simple MFC application to understand the controls and event handling in MFC.a. Click on the "TODO" text to select it. Press the Delete key to delete it. b.


View Full Document

UB CS 400 - Microsoft Foundation Classes

Download Microsoft Foundation Classes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Microsoft Foundation Classes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Microsoft Foundation Classes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?