You are on page 1of 43

Windows programming

03 MFC (Microsoft Foundation Class)


Acknowledgment: The slides are modifications of ones by Uitumen .J
Amarsanaa .G School of Information Technology National University of Mongolia

Outline

Visual Studio C++ 6.0 project types MFC and its key features MFC AppWizard Dialog based application MFC Base classes Edit box, static controls, button controls

Version 6.0

VISUAL STUDIO C++

What is Visual Studio?


Microsoft Visual Studio is the main
Integrated Development Environment (IDE) from Microsoft.

It can be used to develop console and graphical user interface applications along with Windows Forms applications, web sites, web applications, and web services in both native code together with managed code for all platforms supported by Microsoft Windows, Windows Mobile, Windows CE, .NET Framework, .NET Compact Framework and Microsoft Silverlight.

This is a suite of development tools


used for application development.

Visual Studio versions


Visual Studio 97
Microsoft first released Visual Studio in 1997, bundling many of its programming tools together for the first time. Visual Studio 6.0 The next version, version 6.0, was released in June 1998 and is the last version to run on the Windows 9x platform. Visual Studio .NET (2002) Microsoft released Visual Studio .NET in Feburary 2002. The biggest change was the introduction of a managed code development environment using the .NET Framework.

Visual Studio versions [2]


Visual Studio .NET 2003
In April 2003, Microsoft introduced a minor upgrade to Visual Studio .NET called Visual Studio .NET 2003. .NET Framework, version 1.1, and is the first release to support for developing programs for mobile devices, using either ASP.NET or the .NET Compact Framework. Visual Studio 2005 Visual Studio 2005 was released online in October 2005. .NET Framework 2.0 Visual Studio 2008 Visual Studio 2008 was released to MSDN subscribers on 19 November 2007 alongside .NET Framework 3.5.

Creating MFC applications (VC++ 6.0)


To develop any type of
applications using Visual Studio, create project for solution.

Console program Windows application DLL, ATL

One solution has several

projects (Windows App, DLL library, Database )

To create an application, click Projects

Type the name of the program

Specify the Location

To create a C++ program, If targeting MS Windows > 3.X click Win32 Console Application Check Win32 Platforms. Click OK

Win32 console application wizard

What Visual Studio can do?



ATL (Active Template Library) Cluster Resource DLL Database project Dev Studio Add-ins/Plug-ins Extended Stored Procedure ISAPI MFC ActiveX control Win32 application Dynamic Link Library (DLL) Static Link Library (LIB)

Project Types
ATL COM Wizard
ATL means Active Template Library, which is Template based programming. Programs would be faster and smaller. Usually use experienced c++ programmers.

COM stands for Component Object Model. Known as DLL file mostly. Programmers use components like as independent executable in their application instead of writing that application.

The

Cluster Resource Type Wizard

Creates two projects that you can deploy on a Microsoft Cluster Server to manage and monitor resources (applications) on the cluster:
Resource DLL project Manages and monitors a specific type of resource

(application). The name of this project is the name you give to the Cluster Resource Type project.
Cluster Administrator extension DLL

Loaded by the Cluster Administrator to allow resources (applications) of this new type to be configured. This DLL project is a COM, in-process server. The name of this project has the letters "Ex" appended to the name you give to the Cluster Resource Type project.

The Cluster Resource Type Wizard


Cluster servers Client 1

Client 2

Project Types [2]


Custom App wizard
Can create your own wizard. Useful when you write similar applications often.

Database projects

Can create and design the databases

Dev studio Add-in wizard


Can develop Developer studio /VC, VB, Interdev/ plug-ins or add-ins.

Extended stored procedure

MS SQL server has a two types of procedure

Stored procedure which is in form of text or query Extended stored procedure which is in form of DLL file

Project Types [3]


ISAPI
Internet Server API which stands developing applications that use Ms IIS servers API

MFC ActiveX control


Can develop ActiveX controls that use MFC. Can be reuse, independent program that has not interface. For example windows media player on the Internet Explorer.

Win32
Win- means Windows 32 means 32 bit computer Can be develop win32 applications from early stage /beginning/.

Project Types [4]


Dynamic Link Library
Stands for DLL. Can serve multiple application. At most one copy of the DLL can reside in the memory.

Static Link Library


Stands for lib file. Linker can link this type of lib file when compiling new application.

Version 6.1

MFC (MICROSOFT FOUNDATION CLASS)

Introduction to MFC
Microsoft Foundation Class (MFC)

Advantages of MFC

Windows applications Object-orientation programming design Encapsulates Windows API programming

Elimination of function and variable name collisions Encapsulation of code and data within the class Inheritance Reduced code size resulting from well-designed class libraries Resulting classes appearing to be natural extensions of the language

Key features in MFC Library


Allow mixing traditional function call
with the use of new class libraries Complete support for all Windows functions, controls, messages, Graphic Device Interface (GDI) 2 major sections:

MFC Class Hierarchy Global functions and macros

MFC Hierarchy Chart

MFC Library Version 6.1

Key features in MFC Library [2]


MFC Class Hierarchy

Over 200 classes CObject : base class of all MFC classes CCmdTarget : encapsulates the messaging features of Windows API CWinApp : initializing, starting, running, and stopping an MFC windows application CWnd : encapsulates various Windows API functions, data types, and other others used for creating and instantiating windows CDialog : creates dialog boxes CFrameWnd : creates standard type of windowframe window

Key Parent Classes


CObject

parent for most classes in MFC optional runtime class information optional runtime creation support optional serialization support dump support for debugging based on Cobject parent class for all classes which can respond to Win32 messages

CCmdTarget

Key Parent Classes [2]


CWnd

based on CCmdTarget parent class for all windows window size and position mouse capture and keyboard focus parent/child relationships stores application-wide data can be used to access standard cursors and icons can be used to access Windows Registry and *.ini files

CWinApp

MFC Library 9.0 (Visual Studio 2008)

Key features in MFC Library [3]


Global Functions

Not a member of MFC class Prefix of Afx E.g.: AfxMessageBox() function displays a simple message box to the user Identical to MessageBox() function in CWnd Cannot use a member function before an object of the class is instantiated, => use global function

Key features in MFC Library [4]


Macro

Represents C++ code, constants, and other programming elements that executes simply by calling the macro name Using #define preprocessor directive Already exists, no need to create in MFC All uppercase letters E.g.: BEGIN_MESSAGE_MAP() and END_MESSAGE_MAP() use for handling messages

Dialog based application

MFC APPWIZARD

Public inheritance of CWinApp

Public inheritance of CDialog

TestDlg.cpp

ClassWizard

A tool that you can use


to configure classes used in MFC programs you write for Windows

ClassWizard helps you eliminate common coding errors, because much of the code can be written automatically

Add new classes Add member variables Bind resources and controls classes Add message-handling functions

Questions?

You might also like