Introduction to Microsoft Windows MFC Programming: the Application/Window Approach Lecture 4.

Slides:



Advertisements
Similar presentations
Introduction to Visual Basic.NET Uploaded By: M.Sheraz anjum.
Advertisements

MFC Workshop: Intro to the Document/View Architecture.
CA 121 Intro to Programming Tariq Aziz and Kevin Jones GUI Programming in Visual Studio.NET Chapter 1 Tariq Aziz and Kevin Jones.
Advanced Object-Oriented Programming Features
Compunet Corporation Programming with Visual Basic.NET GUI Week # 11 Tariq Ibn Aziz.
On the Duality of Operating System Structures Hugh C. Lauer Xerox Corporation Roger M. Needham Cambridge University Presented By: Ashwini Kulkarni.
MFC Workshop: Intro to MFC. What is MFC? Microsoft Foundation Classes C++ wrappers to the Windows SDK An application framework A useful set of extensions.
Microsoft Visual Basic 2005 CHAPTER 1 Introduction to Visual Basic 2005 Programming.
Visual Basic Chapter 1 Mr. Wangler.
INTRODUCTION TO VC++ As the Microsoft Windows 3.X and then 5.5 operating system was becoming popular, many programmers were interested in creating graphical.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
An Object-Oriented Approach to Programming Logic and Design
Building an MFC Application Using the Wizard. Terms Solution – A container for related projects – An executable or DLL – May be constructed from multiple.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
STIP Chapter#10 Mastering Windows Forms Created By, Vishwesh Patel.
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC BUILDING BLOCKS Bilal Munir Mughal 1 Chapter-5.
Visual C++ Lecture 11 Friday, 29 Aug Windows Graphic User Interface l Event driven programming environment l Windows graphic libraries (X11 on Unix,
Automating Database Processing Chapter 6. Chapter Introduction Design and implement user-friendly menu – Called navigation form Macros – Automate repetitive.
C++ MFCs CS 123/CS 231. MFC: Writing Applications for Windows zClasses in MFC make up an application framework zFramework defines the skeleton of an application.
Prepared by Fareeha Lecturer DCS IIUI 1 Windows API.
BZUPAGES.COM Visual Programming Lecture – 5 Miss. SADAF MAJEED SIAL Computer Science Department Bahauddin Zakariya University Multan.
Getting Started The structure of a simple wxWidgets program, Look at where and how a wxWidgets application starts and ends, how to show the main window,
Overview of Previous Lesson(s) Over View  Visual C++ provides us with 3 basic ways of creating an interactive Windows application  Using the Windows.
Tutorial 111 The Visual Studio.NET Environment The major differences between Visual Basic 6.0 and Visual Basic.NET are the latter’s support for true object-oriented.
Chapter 1: Hello, MFC Your first MFC Application Department of Digital Contents Sang Il Park.
MFC Windows Programming: Document/View Approach More detailed notes at: 360/notes-html/class15.htm.
Overview of Previous Lesson(s) Over View  Microsoft Foundation Classes (MFC)  A set of predefined classes upon which Windows programming with Visual.
Microsoft Foundation Classes. What is MFC? Set of C++ classes written by MS Simplifies writing complex programs Covers many areas: – GUI – I/O – O/S interfaces.
Object Oriented Software Development 9. Creating Graphical User Interfaces.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
CE Operating Systems Lecture 3 Overview of OS functions and structure.
BZUPAGES.COM Visual Programming Lecture – 6- 7 Miss. SADAF MAJEED SIAL Computer Science Department Bahauddin Zakariya University Multan.
GAM666 – Introduction To Game Programming You must use special libraries (aka APIs – application programming interfaces) to make something other than a.
CNS 1410 Graphical User Interfaces. Obectives Students should understand the difference between a procedural program and an Event Driven Program. Students.
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC PROGRAMMING FUNDAMENTALS Bilal Munir Mughal 1 Chapter-8.
CITA 342 Section 2 Visual Programming. Allows the use of visual expressions (such as graphics, drawings, or animation) in the process of programming.
Chapter2: Drawing a Window. Review: Introducing MFC.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Introduction to OOP CPS235: Introduction.
Chapter 7 Controls. 2 Introduction (1/4) Control –Special kind of window –Designed to convey information to the user or to acquire input –Reduce the tedium.
Chapter 8 Dialog Boxes and Property Sheet
INFORMATION SYSTEM – SOFTWARE TOPIC: GRAPHICAL USER INTERFACE.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 14 Event-Driven Programming with Graphical User Interfaces.
Overview of Previous Lesson(s) Over View 3 Program.
Chapter 6: FILE I/O and Serialize CFile class. FILE I/O Serialization and the CArchive Class.
Microsoft Foundation Classes
Overview of Previous Lesson(s) Over View  Windows Programming  WinMain()  Where execution of the program begins and basic program initialization is.
Part II Document/View Architecture. Chapter 9 Documents, Views, and the Single Document Interface.
Sockets A popular API for client-server interaction.
CPS120: Introduction to Computer Science Lecture 16A Object-Oriented Concepts.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Threads and Thread Synchronization. Introduction In windows the basic unit of execution is the thread. It is the smallest schedulable unit of execution.
Visual Info Processing Programming Guide
Chapter 14 Windows Programming with the Microsoft Foundation Classes
Introduction to Windows Programming
Document/View Architecture
Message Handling in MFC
Microsoft Foundation Classes MFC
Visit for more Learning Resources
Steps to Build Frame Window Recipe Application
Chapter Topics 15.1 Graphical User Interfaces
Introduction to Visual Basic 2008 Programming
Working with Dialogs and Controls
Introduction to Windows Programming with Microsoft Framework Classes (MFC) Jim Fawcett Summer 2004 Syracuse University.
Microsoft Access 2003 Illustrated Complete
Microsoft Access Illustrated
Chapter 2 Visual Basic Interface
Chapter 15: GUI Applications & Event-Driven Programming
Chapter 12 Windows Programming with the Microsoft Foundation Classes
Presentation transcript:

Introduction to Microsoft Windows MFC Programming: the Application/Window Approach Lecture 4

MFC Windows Programming (App/Window Approach) MFC stands for “The Microsoft Foundation Class Library” Object oriented interface to windows. A Hierarchy of C++ classes designed to facilitate Windows programming An alternative to using Win32 API functions A Visual C++ Windows application can use either Win32 API, MFC, or both Lecture 4

Relationship between Windows MFC and Win32 API Programming Lecture 4

Microsoft Foundation Classes About 200 MFC classes (versus 2000+ API functions ) Also called “Application Frame work” Provide a framework upon which to build Windows applications Encapsulate most of the Win32 API in a set of logically organized classes MFC organizes the WIN32 API. it groups related functionality into a class. Wraps the windows API and windows objects with classes Lecture 4

MFC Characteristics 1. Convenience of reusable code: Many tasks common to all Windows apps are provided by MFC Our programs can inherit and modify this functionality as needed We don't need to recreate these tasks 2. Produce smaller executables: Typically 1/3 the size of their API counterparts Lecture 4

MFC Characteristics (contd) 3. Can lead to faster program development: Make creation of windows application with C++ easy Make access to Windows API features easier 4. MFC Programs must be written in C++ require the use of classes Programmer must have good grasp of: How classes are declared, instantiated, and used Encapsulation Inheritance Polymorphism--virtual functions Lecture 4

MFC Notations Classes names begins with ‘C’ CFrameWnd CView Variable names begin with ‘m_’ m_pFrameWnd Functions name begins with Afx AfxMessageBox() Lecture 4

MFC Class Hierarchy Two categories of classes CObject Derived from CObject Not Derived from CObject CObject At top of hierarchy ("Mother of all classes") Provides features like: Serialization Streaming object’s persistent data to or from a storage medium (disk reading/writing) Diagnostic & Debugging support All its functionality is inherited by any classes derived from it Lecture 4

Important Derived Classes— CFile: Support for file operations CDC: Encapsulates the device context (Graphical Drawing) CGdiObject: Base class for various drawing objects (brushes, pens, fonts, etc.) CMenu: Encapsulates menu management Lecture 4

CCmdTarget: Encapsulates message passing process& is parent of: CWnd: Encapsulates many important windows functions and data members Example: m_hWnd stores the window’s handle Base class all windows are derived from Most common: CFrameWindow: Can contain other windows ("normal" kind of window we've used) CView: Encapsulates process of displaying and interacting with data CDialog: Encapsulates dialog boxes Lecture 4

CCmdTarget also parent of: CWinThread: Defines a thread of execution and is the parent of: CWinApp: Most important class dealt with in MFC applications: Encapsulates an MFC application Controls following aspects of Windows programs: Startup, initialization, execution, shutdown An application should have one CWinApp object When instantiated, application begins to run CDocument Encapsulates the data associated with a program Lecture 4

Not Derived from CObject • Provide valuable additional services for MFC: OLE Classes Simple Data Type Classes CImage CRect CString etc. Synchronization classes CSemaphore CMutex Lecture 4

Applications can also call API functions directly Use Global Scope Resolution Operator, for example: ::UpdateWindow(hWnd); Usually more convenient to use MFC member functions Lecture 4

Simplest MFC programs must contain two classes derived from hierarchy: A Minimal MFC Program Simplest MFC programs must contain two classes derived from hierarchy: 1. An application class derived from CWinApp Defines the application provides the message loop Three common methods are InitApplication(); InitInstance(); Run(); These methods created automatically when object is created. Lecture 4

2. A window class usually derived from CFrameWnd Defines the application's main window Referred as frame window Tasks: Creation of window Management of window It creates window and attach it to our program These & other MFC classes brought in by using #include <Afxwin.h> Lecture 4

#include <afxwin.h> class CMyApp : public CWinApp { public: virtual BOOL InitInstance(); }; Lecture 4

class CMainFrame : public CFrameWnd { public: CMainFrame() Create(NULL, "MFC Fundamentals"); } }; BOOL CMyApp ::InitInstance() m_myWnd * CMainFrame ; m_myWnd = new CMainFrame; m_myWnd ->ShowWindow(SW_NORMAL); m_pMainWnd= m_myWnd ; return TRUE; CMyApp a; Lecture 4

Message Processing under MFC Like API programs, MFC programs must handle messages from Windows API mechanism: big switch/case statement MFC mechanism: "message maps" (lookup tables) Lecture 4

Messages in an application can be send in 2 ways Directly Queued Message queue and message loop both are by passed Windows directly call WndProc() ::SendMessage ::PostMessage Lecture 4

System Defined Messages Windows uses these messages Each of the system defined messages has unique numeric identifier Corresponding identifier macro definition System defined message macro prefix BM Button control Messages CB Combo Box control Messages EM Edit Box control Messages LB List Box control Messages WM General Window Messages Lecture 4

Message Handler Message handler methods receive notification from the application object when some event occurs Three types of messages processed in Message handler Windows Messages Control Notification Messages Command Messages Send by window to application Starts with WM_* WM_COMMAND exception Lecture 4

Control Notification Messages Send from child window Control has no message queue and loop Whatever activity notify directly to parent Use message loop and queue of parent Command Messages Include WM_COMMAND Notification from user interface object like menu buttons toolbar buttons Lecture 4

Message Maps Mechanism for handling messaging with in a process Object Oriented alternative to “switch-case” of window procedure Table entries: Message number Pointer to a derived class member message-processing function These are members of CWnd You override the ones you want your app to respond to Known as “Message handler” Lecture 4

Message Mapping Programs must: Declaration Implementation DECLARE_MESSAGE_MAP() Implementation BEGIN_MESSAGE_MAP( FC_Tutorial_Window, CFrameWnd)       ON_WM_LBUTTONDOWN() //Macro to map the left button click to the handler END_MESSAGE_MAP() Lecture 4

Message Mapping Programs must: Declare message-processing functions e.g., OnWhatever() for WM_WHATEVER message Map them to messages app is going to respond to Mapping done by "message-mapping macros” Bind a message to a handler function e.g., ON_WM_WHATEVER() Most MFC application windows use a window procedure, WndProc(), supplied by the library Message maps enable library window procedure to find the function corresponding to the current msg. Lecture 4

Lecture 4