Chapter 12 Windows Programming with the Microsoft Foundation Classes

Slides:



Advertisements
Similar presentations
Prof. Yitzchak Rosenthal
Advertisements

Introduction to Computers Section 6A. home The Operating System (OS) The operating system (OS) is software that controls the interaction between hardware.
MFC Workshop: Intro to the Document/View Architecture.
© by Pearson Education, Inc. All Rights Reserved.
Visual Basic 2010 How to Program. © by Pearson Education, Inc. All Rights Reserved.2.
 2006 Pearson Education, Inc. All rights reserved Introduction to the Visual C# 2005 Express Edition IDE.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
KEAN UNIVERSITY Visual C++ Dr. K. Shahrabi. Developer studio Is a self-contain environment for creating, compiling, linking and testing windows program.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter One An Introduction to Visual Basic 2010.
1 ENG236: ENG236: C++ Programming Environment (2) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY.
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.
Microsoft Visual Basic 2005: Reloaded Second Edition
Computing IV Visual C Introduction with OpenCV Example Xinwen Fu.
Using Visual Basic 6.0 to Create Web-Based Database Applications
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide.
MFC Windows Programming: Document/View Approach More detailed notes at: 360/notes-html/class15.htm.
Copyright © 2010 Wolters Kluwer Health | Lippincott Williams & Wilkins Introduction to Windows Chapter 2.
Overview of Previous Lesson(s) Over View  Microsoft Foundation Classes (MFC)  A set of predefined classes upon which Windows programming with Visual.
1 Pointer A pointer is a variable that stores an address of another variable of a particular type. A pointer has a variable name just like any other variable.
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.
Lecture Set 2 Part A: Creating an Application with Visual Studio – Solutions, Projects, Files.
Chapter Two Creating a First Project in Visual Basic.
Using Microsoft Visual Studio 2005 Original by Suma Rao Revised by John G. McMahon ( 9/6/2008 )
Microsoft Visual Basic 2005 BASICS Lesson 1 A First Look at Microsoft Visual Basic.
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter One An Introduction to Visual Basic 2008.
Lecture Set 2 Part A: Creating an Application with Visual Studio – Solutions, Projects, Files 8/10/ :35 PM.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 3 Building an Application in the Visual Basic.NET Environment.
Overview of Previous Lesson(s) Over View 3 Program.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
Overview of Previous Lesson(s) Over View  Windows Programming  WinMain()  Where execution of the program begins and basic program initialization is.
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
COMPREHENSIVE Getting Started with Microsoft Office 2007.
Fundamentals of Windows Mouse n 4 Basic Operations: –Pointing –Clicking –Double Clicking –Dragging.
Dive Into® Visual Basic 2010 Express
Chapter 14 Windows Programming with the Microsoft Foundation Classes
Document/View Architecture
Microsoft Foundation Classes MFC
Getting Started with Microsoft Office 2007
Chapter 2: The Visual Studio .NET Development Environment
INF230 Basics in C# Programming
Customizing custom.
Computer Terms Review from what language did C++ originate?
Getting Started with Windows 10
Chapter 1: An Introduction to Visual Basic 2015
New Perspectives on Microsoft Windows 10
Program and Graphical User Interface Design
1. Introduction to Visual Basic
Introduction to the Visual C# 2005 Express Edition IDE
Getting Started with Microsoft Office 2010
Program and Graphical User Interface Design
Introduction to Microsoft Windows
Introducing Microsoft Office 2010
Chapter 2 – Introduction to the Visual Studio .NET IDE
CIS16 Application Development Programming with Visual Basic
Finding Magazine and Journal Articles in
Microsoft Visual Studio
Electronics II Physics 3620 / 6620
Microsoft PowerPoint 2007 – Unit 2
Tonga Institute of Higher Education
Computer Terms Review from what language did C++ originate?
Exploring Microsoft Word 2003
Chapter 4 Enhancing the Graphical User Interface
Midterm Exam (2).
Microsoft Windows 7 Basics
Chapter 4 Enhancing the Graphical User Interface
Exploring Microsoft Word 2003
An Introduction to the Windows Operating System
Presentation transcript:

Chapter 12 Windows Programming with the Microsoft Foundation Classes

Elements of a Window (P.581) Let us go through them to be sure we have a common understanding of what the terms mean. parent window, child window border, size grip title bar, title bar icon, status bar system menu click the title bar icon, or right-click the title bar client area x increasing from left to right, y increasing from top to bottom minimize, maximize, close buttons

The Microsoft Foundation Classes (P.605) MFC are a set of predefined classes. These classes provides an object-oriented approach to Windows programming that encapsulates the Windows API. Easy to use Data Members & Member Functions You will apply techniques you learned from the previous chapters, particularly those involving class inheritance and virtual functions.

MFC Notation (P.605) All the classes in MFC have names beginning with C CDocument CView Data members of an MFC class are prefixed with m_ m_lpCmdLine Explicitly showing the type of a variable in its name was important in the C environment, because of the lack of type checking Hungarian notation (P.813, P.836) However, C++ has strong type checking, so this kind of notation isn’t essential, and will not be used heavily in this book. However, the p prefix for pointers will be retained because this helps the code more readable.

The Document/View Concept in MFC Document (P.614) – the collection of data A document is not limited to text. It could be the data for a game, or the distribution of orange trees in California. View – how the data is to be displayed in a window, and how the user can interact with it. A document object can have as many view objects associated with it as you want.

A Document with Two Views (P.615)

Document Interfaces SDI – Single Document Interface Your application only open one document at a time. MDI – Multiple Document Interface. Multiple documents can be opened in your application. Each document is displayed in a child window of the application window.

Document Template Classes MFC has two classes for defining document templates: CSingleDocTemplate for SDI CMultiDocTempalte for MDI

Linking a Document and Its Views MFC incorporates a mechanism for integrating a document with its views a document object automatically maintains a list of pointers to its associated views a view object has a pointer to the document a frame window with a view a frame window has a pointer to the currently active view object

Document Templates (P.616) A document template object creates document objects and frame window objects If you have two or more documents of the same type, you need only one document template to manage them. View of a document are created by a frame window object. The application object creates the document template object.

Your Application and MFC (P.617) Four basic classes that will appear in almost all your MFC-based Windows applications: The application class The document class The view class The frame window class

Document / View Classes Your document class is derived from the CDocument class in the MFC library You will add your own data members to store items that your application requires, and member functions to support processing of that data. Your view class is derived from the CView class. You define how data in your document will be displayed in a window.

The Application Class The class CWinApp is fundamental to any Windows program written using MFC. An object of this class includes everything necessary for starting, initializing, running and closing the application. class CMyApp: public CWinApp { public: virtual BOOL InitInstance(); };

The Window Class The CFrameWnd class provides everything for creating and managing a window for your application All you need to add to the derived window class is a constructor. class CMyWnd: public CFrameWnd { public: // Constructor CMyWnd() Create(0, L”Our Dumb MFC Application”); } };

Creating MFC Applications You don’t need to worry about which classes you need to have in your program. Visual C++ 2013 will take care of that for you.

Installing Visual C++ 2013 You will receive a DVD-ROM. Circulate that between your classmates and install Visual Studio 2013 to your PC. The Visual Studio purchased by NCNU only covers the license for computers in classrooms and laboratories. It does not cover students’ computers at home/dormitory. Department of CSIE purchases an additional license, so that CSIE students can install and use Visual Studio 2013 on their own computer at home, even after graduated. Please do not disseminate the software to your friends arbitrarily. If Microsoft detects that we violate the license, our license may be terminated totally.

Run the Installation Program

You Need Not Sign-in.

Choose Visual C++

Start Visual Studio

Create a New MFC Project Create a new project File > New > Project Crtl + Shift + N Choose MFC as the project type and MFC Application as the template.

Creating an SDI Application The appearance of an SDI application

Share DLL (Dynamic Link Library) Share DLL (Chapter 20) Your program links to MFC library routines at run-time. This reduces the size of the executable file. When several programs are running simultaneously, they share a single copy of the library in memory. Statically linked The library is included in the executable program you built. This runs slightly faster, with the cost that the file size is larger.

User Interface Features

Advanced Features The File menu will has the following items Page Setup Print Preview Print The Application wizard also provides code to support these functions.

Generated Classes

Choose CEditView as the Base class

Code Generated by the MFC Application Wizard All the files are stored in the TextEditor project folder which is a sub-folder to the solution folder with the same name. Class definitions are in .h files. Resource files are in the res sub-folder to the project folder. Bitmaps, icons, menus, and dialog boxes. Member functions are defined in .cpp files.

Viewing Classes You see four basic classes: CMainFrame CTextEditorApp CTextEditorDoc CTextEditorView Global Functions and Variables contains two definitions: theApp – the application object indicators – an array of indicators recording the status of caps lock, num lock and scroll lock.

Project Property Right-click TextEditor project in the Solution Explorer pane, and select Property from the pop-up menu:

Creating an Executable Module To compile and link the program Build > Build Solution Ctrl + Shift + B <F7> Click the Build icon in the Toolbar In case you did not see them, choose VIEW – Toolbars - Build

Precompiled Header Files (P.637, P.37) The first time you compile and link a program, it will take some time. The second and subsequent times it should be faster. A feature of Visual C++ 2013 called precompiled headers will save the output from compiling header files in a special file with the extension .pch. On subsequent builds, this file is reused if the source in the headers has not changed, thus saving the compilation time for the headers. This is another advantage for you to define your classes in different .h files.

Running the Program Ctrl + F5 This is a fully functioning, simple text editor. All the items under all menus are fully operational Save / Open files Cut / Paste text Print Toolbar Tool tip System menu

Floating/Dockable Solution Explorer

Adding Debug code Solution Configurations #ifdef _DEBUG //Debug code Release #ifdef _DEBUG //Debug code #endif 會有程式示範

Solution Configurations

Debug Mode vs. Release Mode #include <iostream> using std::cin; using std::cout; using std::endl; int main() { int sum = 0; int i; for (i=1; i<=10; i++) sum += i; #ifdef _DEBUG cout << "i = " << i << endl; #endif } cout << sum << endl; return 0;

Same Trick on STU clang++ -D_DEBUG a.cpp clang++ a.cpp Debug mode Release mode

Exercises P.635 Ex4: Create the simple text editor program. Build both debug and release versions, and examine the types and sizes of the files produced in each case. Q: Where is the EXE file? Note that debug and release versions are located under different directories. Q: What is the function of the ilk files? Ex5: Generate the text editor application several times, trying different window styles from the User Interface Features in Application wizard. Minimize/Maximize box Printing and print preview Projects\TextEditor\Debug\TextEditor.exe 236,544 bytes Projects\TextEditor\Release\TextEditor.exe 119,808