Introduction to MFC. Motivation Abstract the Windows API Provides additional GUI options Insert Open Inventor into existing MFC application Document /

Slides:



Advertisements
Similar presentations
Microsoft Office 2007-Illustrated Introductory, Windows Vista Edition Windows XP Unit A.
Advertisements

Using Macros and Visual Basic for Applications (VBA) with Excel
Visual Basic 2010 How to Program. © by Pearson Education, Inc. All Rights Reserved.2.
Visual Basic 2010 How to Program Reference: Instructor: Maysoon Bin Duwais slides Visual Basic 2010 how to program by Deitel © by Pearson Education,
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
1 Introduction to the Visual Studio.NET IDE Powerpoint slides modified from Deitel & Deitel.
Chapter 4: Working with Windows Types of Windows –Program Windows –Message Boxes –Dialog Boxes Elements of a Window –Window Panes –Scroll Bars –Menus –Tool.
Introduction to Visual Basic. What is Visual Basic? An environment for developing Windows applications Components –A GUI (Graphical User Interface - gooey)
COMPREHENSIVE Excel Tutorial 8 Developing an Excel Application.
2. Introduction to the Visual Studio.NET IDE 2. Introduction to the Visual Studio.NET IDE Ch2 – Deitel’s Book.
Microsoft Visual Basic 2012 CHAPTER TWO Program and Graphical User Interface Design.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. WORD 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 22 Macros.
XP New Perspectives on Microsoft Office FrontPage 2003 Tutorial 4 1 Microsoft Office FrontPage 2003 Tutorial 4 – Using Shared Borders and Themes.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
Adding User Interactivity – Lesson 51 Adding User Interactivity Lesson 5.
Visual C++ Lecture 11 Friday, 29 Aug Windows Graphic User Interface l Event driven programming environment l Windows graphic libraries (X11 on Unix,
Intro to MFC. Open VS and create new project 1)Open MS Visual Studio 2008 Professional (It must be the Professional Edition, the Express Edition will.
1 Working with Menus and Dialog Boxes. 2 Objectives You will be able to Create and edit menus for Windows Forms applications. Write code to handle menu.
Visual Basic 2005 CHAPTER 2 Program and Graphical User Interface Design.
Designing Interface Components. Components Navigation components - the user uses these components to give instructions. Input – Components that are used.
Chapter 1: Hello, MFC Windows Programming Model Department of Digital Contents Sang Il Park.
Basic Computer and Word Functions, part 1 Read the information and use to answer the questions in the Basic Computer and Word Functions Study Guide.
Productivity Programs Common Features and Commands.
Copyright © 2010 Wolters Kluwer Health | Lippincott Williams & Wilkins Introduction to Windows Chapter 2.
Classic Controls Trần Anh Tuấn A. Week 1 How to create a MFC project in VS 6.0 How to create a MFC project in VS 6.0 Introduction to Classic Controls.
Tutorial 11 Five windows included in the Visual Basic Startup Screen Main Form Toolbox Project Explorer (Project) Properties.
OBJECTIVE  After completing this Lab, students will upgrade their knowledge in the field of VC++.  Students will also get the clear view about the concepts.
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.
Chapter 7 Controls.
Lection №5 Modern integrated development environment.
Microsoft Publisher 2010 Chapter 1 Creating a Flyer.
Chapter 2 – Introduction to the Visual Studio .NET IDE
1 Creating Windows GUIs with Visual Studio. 2 Creating the Project New Project Visual C++ Projects Windows Forms Application Give the Project a Name and.
CITA 342 Section 2 Visual Programming. Allows the use of visual expressions (such as graphics, drawings, or animation) in the process of programming.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Chapter 8 Dialog Boxes and Property Sheet. 2 Two kinds of dialog boxes Dialog boxes –Modal dialog When appear, it takes all ownership of input. It disables.
Microsoft Visual Basic 2010 CHAPTER TWO Program and Graphical User Interface Design.
XP Tutorial 8 New Perspectives on Microsoft Windows XP 1 Microsoft Windows XP Object Linking and Embedding Tutorial 8.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to the Visual Studio.NET IDE Outline 2.1Introduction 2.2Visual Studio.NET Integrated.
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
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
Chapter 6: FILE I/O and Serialize CFile class. FILE I/O Serialization and the CArchive Class.
Customizing Menus and Toolbars CHAPTER 12 Customizing Menus and Toolbars.
Chapter 7 Controls. List box control 3 List Box Control(1/8) Listbox control: –Display lists of text strings called items –Optionally sort the items.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
Microsoft Visual C# 2010 Fourth Edition Chapter 3 Using GUI Objects and the Visual Studio IDE.
Chapter 10 Using Macros, Controls and Visual Basic for Applications (VBA) with Excel Microsoft Excel 2013.
1 Word Processing Intermediate Using Microsoft Office 2000.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 11 Creating Web Applications and Writing Data to a Database.
Fundamentals of Windows Mouse n 4 Basic Operations: –Pointing –Clicking –Double Clicking –Dragging.
Dialog Boxes and Property Sheets
Dive Into® Visual Basic 2010 Express
Excel Tutorial 8 Developing an Excel Application
Chapter Topics 15.1 Graphical User Interfaces
Chapter 2 – Introduction to the Visual Studio .NET IDE
Program and Graphical User Interface Design
1. Introduction to Visual Basic
Working with Dialogs and Controls
Dialog Boxes and Property Sheets
Microsoft Windows XP Inside Out Second Edition
An Introduction to Computers and Visual Basic
Program and Graphical User Interface Design
Variables and Arithmetic Operations
Chapter 2 Adding Web Pages, Links, and Images
Chapter 2 – Introduction to the Visual Studio .NET IDE
An Introduction to Computers and Visual Basic
Chapter 15: GUI Applications & Event-Driven Programming
Presentation transcript:

Introduction to MFC

Motivation Abstract the Windows API Provides additional GUI options Insert Open Inventor into existing MFC application Document / View architecture MFC – Microsoft Foundation Classes API – Application Programming Interface GUI – Graphical User Interface DLL – Dynamic Link Libraries

MFC MFC is designed for event based programs Traditional applications are executed top to bottom

MFC basics

MFC basics

MFC basics

MFC basics

MFC Application structure VS creates automatically: –MyApp.cpp / h –MainFrame.cpp / h –MyAppDoc.cpp / h –MyAppView.cpp / h

MFC Application structure VS creates automatically: –MyApp.cpp / h – message loop, no data –MainFrame.cpp / h – main interface –MyAppDoc.cpp / h – data manipulation –MyAppView.cpp / h – visualization

What we need Events / Messages Dialogs GUI – data input and output

MFC messages and commands The 4 files have the following lines BEGIN_MESSAGE MAP … END_MESSAGE_MAP Every class can take care of messages They can be defined manually or automatically Messages represent OS events

Messages WM_CHARA character is input from the keyboard. WM_COMMANDThe user selects an item from a menu, or a control sends a notification to its parent. WM_CREATEA window is created. WM_DESTROYA window is destroyed. WM_LBUTTONDOWNThe left mouse button is pressed. WM_LBUTTONUPThe left mouse button is released. WM_MOUSEMOVEThe mouse pointer is moved. WM_PAINTA window needs repainting. WM_QUITThe application is about to terminate. WM_SIZEA window is resized.

Adding messages View  Class View Choose appropriate class Right click on the class  Properties

Messages BEGIN_MESSAGE MAP ON_WM_DESTROY() END_MESSAGE MAP void MyAppView::OnDestroy() { CView::OnDestroy(); // TODO: Add your message handler code here }

Commands Commands come from menus Add command to menu –View  Resource View  IDR_MyAppType Add handler –Menu  Right Click  Add Event Handler –Choose class

Commands

BEGIN_MESSAGE MAP ON_COMMAND(ID_DDD_DDD, OnDddDdd) END_MESSAGE MAP void MyAppView::OnDddDdd() { // TODO: Add your message handler code here }

Toolbar Another way to use menu View  Resource View  toolbar

Toolbar Add new icons Change the appearance of icons Add new icons Change ID of icons (add commands manually to the CPP/H files)

Controls Special windows for input / output Exists in View  Resources Control TypeWNDCLASSMFC Class Buttons"BUTTON"CButton List boxes"LISTBOX"CListBox Edit controls"EDIT"CEdit Combo boxes"COMBOBOX"CComboBox Scroll bars"SCROLLBAR"CScrollBar Static controls"STATIC"CStatic

Dialog Boxes Windows that pop up to obtain input Modal dialogs disables parent window Modeless dialog does not disable parent Create dialog in resources Add desired controls Add class

Dialog boxes

Dialog usage In a file: CMyDialog dlg; if ( dlg.DoModal() == IDOK ) { // The user clicked OK; do something ! }

Dialog usage Get data from dialog –Define class variable –Put the values from controls into the variables –Use the variables in the main file –Automatic support in Visual Studio void CMyDialog::DoDataExchange( CDataExchange* pDX){ DDX_Text (pDX, IDC_NAME, m_strName); DDX_Text (pDX, IDC_PHONE, m_strPhone); } Class variable

DDX Functions DDX FunctionDescription DDX_TextAssociates a BYTE, an int, a short, a UINT, a long, a DWORD, a CString, a string, a float, a double, a COleDateTime, or a COleCurrency variable with an edit control. DDX_CheckAssociates an int variable with a check box control. DDX_RadioAssociates an int variable with a group of radio buttons. DDX_LBStringAssociates a CString variable with a list box. DDX_LBStringExactAssociates a CString variable with a list box.

Common Dialogs ClassDialog Type(s) CFileDialogOpen and Save As dialog boxes. CPrintDialogPrint and Print Setup dialog boxes. CPageSetupDialogPage Setup dialog boxes. CFindReplaceDialogFind and Replace dialog boxes. CColorDialogColor dialog boxes. CFontDialogFont dialog boxes.

MFC & Open Inventor We will create MFCViewer.cpp Enter MFCViewer.cpp –SoWin::init(""); into InitInstance(); Enter MFCViewerView.h –#include –SoWinExaminerViewer * viewer; Modify the constructor –CMFCViewerView::CMFCViewerView() { viewer = NULL; } Modify the destructor –CMFCViewerView::CMFCViewerView() { if (viewer != NULL) delete viewer; }

MFC & Open Inventor void CMFCViewerView::OnDraw(CDC* pDC) CMFCViewerDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (viewer == NULL) { viewer = new SoWinExaminerViewer( m_hWnd ); viewer->setDecoration(FALSE); //Try TRUE viewer  setSceneGraph(pDoc  root); }

MFC & Scene Graph Enter MFCViewDoc.h –class SoSeparator; above CMFCViewDoc definition –Insert SoSeparator *root into CMFCViewDoc Include files into MFCViewerDoc.cpp Modify constructor & destructor like in View Create scene in OnNewDocument() Go to CMFCViewerView::OnDraw() SoSeparator *root = GetDocument()->root; viewer->setSceneGraph(root);