Chapter 8 Dialog Boxes and Property Sheet

Slides:



Advertisements
Similar presentations
Facilitator: Mrs. Nkeiruka Ojei
Advertisements

Benchmark Series Microsoft Access 2010 Level 1
Overview Lesson 1. Objectives Step-by-Step: Start Excel 1.Click the Start menu, and then click All Programs. 2.On the list of programs, click Microsoft.
Objectives © Paradigm Publishing, Inc. 1 Objectives.
User Training. Step 1 Press Ctrl-I or choose File > Login, this will open the Login window. Figure 1-1 shows the Login window. Figure 1-1 Login Window.
CPIT 102 CPIT 102 CHAPTER 1 COLLABORATING on DOCUMENTS.
Using Macros and Visual Basic for Applications (VBA) with Excel
MFC Workshop: Intro to the Document/View Architecture.
Foundation Level Course
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
Introduction to MFC. Motivation Abstract the Windows API Provides additional GUI options Insert Open Inventor into existing MFC application Document /
Automating Tasks With Macros
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Introduction to Microsoft Windows MFC Programming: the Application/Window Approach Lecture 4.
Fundamentals of Programming in Visual Basic 3.1 Visual basic Objects Visual Basic programs display a Windows style screen (called a form) with boxes into.
Chapter 5 Using Business Information Sets
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Word Project 8 Working with Macros and Visual Basic for Applications (VBA)
Printing and Page Formatting ITSW 1401, Intro to Word Processing Instructor: Glenda H. Easter.
COMPREHENSIVE Excel Tutorial 8 Developing an Excel Application.
WORKING WITH MACROS CHAPTER 10 WORKING WITH MACROS.
Chapter 3 Maintaining a Database
© 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.
Microsoft Office 2003 Illustrated Brief Document Creating a.
XP New Perspectives on Microsoft Office FrontPage 2003 Tutorial 4 1 Microsoft Office FrontPage 2003 Tutorial 4 – Using Shared Borders and Themes.
Visual C++ Lecture 11 Friday, 29 Aug Windows Graphic User Interface l Event driven programming environment l Windows graphic libraries (X11 on Unix,
1 2 Lab 2: Organizing Your Work. 2 Competencies 3 After completing this lab, you will know how to: 1. Use Explorer to manage files. 2. Copy files. 3.
Microsoft Access Lesson 1 Lexington Technology Center February 11, 2003 Bob Herring On the Web at
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.
BZUPAGES.COM Visual Programming Lecture – 5 Miss. SADAF MAJEED SIAL Computer Science Department Bahauddin Zakariya University Multan.
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.
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.
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.
BZUPAGES.COM Visual Programming Lecture – 6- 7 Miss. SADAF MAJEED SIAL Computer Science Department Bahauddin Zakariya University Multan.
Microsoft PowerPoint Tutorial Created by L. George 2006.
Microsoft Publisher 2010 Chapter 1 Creating a Flyer.
XP New Perspectives on Microsoft Office FrontPage 2003 Tutorial 7 1 Microsoft Office FrontPage 2003 Tutorial 7 – Creating and Using Templates in a Web.
Moving and Copying Text Instructor: Glenda H. Easter ITSW 1401, Intro to Word Processing.
Chapter2: Drawing a Window. Review: Introducing MFC.
Chapter 8: Plotting. After completing this Chapter, you will be able to use the following features: Planning the Plot Sheet Plotting Environments Plotting.
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.
Chapter 6: FILE I/O and Serialize CFile class. FILE I/O Serialization and the CArchive Class.
Chapter 3 Automating Your Work. It is frustrating when you have to type the same passage of text repeatedly. For example your name and address. Word includes.
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.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Address Book Application Introducing Database Programming.
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.
Overview of Previous Lesson(s) Over View  Windows Programming  WinMain()  Where execution of the program begins and basic program initialization is.
Problem: Take Two Numbers, Add Them Together And Display The Results. Now To Build The Flowchart… We Probably Need One Like This… Let’s Add The Routines…
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 6 Looping and Multiple Forms.
Chapter 10 Using Macros, Controls and Visual Basic for Applications (VBA) with Excel Microsoft Excel 2013.
Part II Document/View Architecture. Chapter 9 Documents, Views, and the Single Document Interface.
Chapter 11 Enhancing an Online Form and Using Macros Microsoft Word 2013.
Fundamentals of Windows Mouse n 4 Basic Operations: –Pointing –Clicking –Double Clicking –Dragging.
Dialog Boxes and Property Sheets
Chapter 14 Windows Programming with the Microsoft Foundation Classes
Excel Tutorial 8 Developing an Excel Application
Introduction to Windows Programming
MULTIPLE DOCUMENTS AND MULTIPLE VIEWS Prosise - Chapter 11
Document/View Architecture
Message Handling in MFC
Microsoft Foundation Classes MFC
Working with Dialogs and Controls
Dialog Boxes and Property Sheets
Module 1: Getting Started with Windows 95
Chapter 12 Windows Programming with the Microsoft Foundation Classes
Chapter 4 Enhancing the Graphical User Interface
Presentation transcript:

Chapter 8 Dialog Boxes and Property Sheet

Two kinds of dialog boxes Modal dialog When appear, it takes all ownership of input. It disables the window until the dialog box is dismissed. Modeless dialog It behaves more like a conventional window. It activates together with other windows.

Modal Dialog box MFC Class Heirarchy

Modal dialog box How to create and show it ① Design a dialog box template  Resource View ② Create a CDialog derived class using the template  Use [Project] [add class] menu ③ Call CDialog::DoModal() function to show the dialog box

Modal dialog box Main Virtual functions of CDialog class WM_INITDIALOG message handler When initializes the dialog box Good place for initializing other controls IDOK message handler (when pressing OK button) Good place for updating variables before closing the dialog box, virtual BOOL CDialog::OnInitDialog ( ); virtual void CDialog::OnOK ( );

Modal dialog box Main Virtual functions of CDialog class IDCANCEL message handler (when pressing cancel button) Close the dialog box virtual void CDialog::OnCancel ( );

DDX/DDV What you have to: IDC_STR IDC_COLOR ① ② Dialog box m_str m_color Dialog variables Parent variables ③ ④ When showing dialog box When pressing OK button

DDX/DDV An automatic way: DDX(Dialog Data eXchange) IDC_STR IDC_COLOR ① ② Dialog box m_str m_color Dialog variables Parent variables ③ ④ Automation?

DDX/DDV Implementation of DDX Connecting a variable with a control Use DDX_* MACRO void CMyDialog::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CMyDialog) DDX_Text(pDX, IDC_STR, m_str); DDX_Text(pDX, IDC_COLOR, m_color); //}}AFX_DATA_MAP }

DDX/DDV OnInitDialog(), OnOK() implementation BOOL CDialog::OnInitDialog() { ... UpdateData(FALSE); // Give the values to the controls } void CDialog::OnOK() UpdateData(TRUE); // Retrieve the values // from the controls

DDX/DDV DDV(Dialog Data Validation) Automation of the validation of the data Check the range of the data Use DDV_* MACRO void CMyDialog::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CMyDialog) DDX_Text(pDX, IDC_STR, m_str); DDV_MaxChars(pDX, m_str, 10); DDX_Text(pDX, IDC_COLOR, m_color); DDV_MinMaxInt(pDX, m_color, 0, 255); //}}AFX_DATA_MAP }

Coding Practice Create a dialog box as shown below and show it when pressing mouse left button Type on the edit control and choose a text color value from the radio buttons

Two types of dialog boxes Modal dialog When appear, it takes all ownership of input. It disables the window until the dialog box is dismissed. Modaless dialog It behaves more like a conventional window. It activates together with other windows.

Modaless Dialog Box Same thing: Different thing: Create a dialog template and add a CDialog-derived class. Different thing: Do not use CDialog::DoModal() function Use CDialog::Create() function for initialization Ex: CDialog::Create( Resource_ID, parent_wnd); Use CDialog::ShowWindow() function for showing Use CWnd::DestroyWindow() function to close

Modaless dialog box test Create a dialog box as shown below and show it as a modaless dialog box. Type on the edit control and choose a text color value from the radio buttons

Common Dialog Boxes

Common Dialog Box MFC Class Hierarchy

Common Dialog Dlasses Class Dialog Type(s) CFileDialog Open and Save As dialog boxes CPrintDialog Print and Print Setup dialog boxes CPageSetupDialog Page Setup dialog boxes CFindReplaceDialog Find and Replace dialog boxes CColorDialog Color dialog boxes CFontDialog Font dialog boxes

CColorDialog CColorDialog dlg; dlg.DoModal(); COLORREF color = dlg.GetColor(); CColorDialog dlg(RGB(255, 0, 0), CC_FULLOPEN); dlg.DoModal(); COLORREF color = dlg.GetColor();

CFileDialog CFileDialog dlg(TRUE); if(dlg.DoModal() == IDOK) MessageBox(dlg.GetPathName()); CFileDialog dlg(FALSE); if(dlg.DoModal() == IDOK) MessageBox(dlg.GetPathName());

CFontDialog CFontDialog dlg; if(dlg.DoModal() == IDOK){ CClientDC dc(this); // Get Color COLORREF color = dlg.GetColor(); dc.SetTextColor(color); // Get Font LOGFONT lf; dlg.GetCurrentFont(&lf); CFont font; font.CreateFontIndirect(&lf); dc.SelectObject(&font); // Show Text dc.TextOut(10, 10, CString("한글 & English")); }

CPageSetupDialog CPageSetupDialog dlg; dlg.DoModal();

CPrintDialog CPrintDialog dlg(TRUE); dlg.DoModal(); CPrintDialog dlg(FALSE); dlg.DoModal();

Part II Document/View Architecture

Chapter 9 Documents, Views, and the Single Document Interface

Document/View Fundamentals Single document/view architecture

Document/View Fundamentals Application object: Provides message loop and send messages to the frame window and the view Frame Window object: Shows menu, toolbar and status bar View object: Displays(renders) data Translates mouse and keyboard input into commands to operates the data Document object: Stores data Manipulates data

SDI and MDI Single Document Interface vs. Multiple Document Interface Different in the number of documents to open at once

Document Template Document Template MFC Class Hierarchy Identifies the document class, view class and frame window class. Stores the resource ID for menu, tool bar and other resources for the frame window MFC Class Hierarchy SDI MDI

Document Template Initial Setting for an application: InitInstance() BOOL CExFileApp::InitInstance() { ... CSingleDocTemplate* pDocTemplate; pDocTemplate = new CSingleDocTemplate( IDR_MAINFRAME, RUNTIME_CLASS(CExFileDoc), RUNTIME_CLASS(CMainFrame), RUNTIME_CLASS(CExFileView)); AddDocTemplate(pDocTemplate); }

Single Document Interface Example (1/4) New Project: Single Document + Document/View Support

Single Document Interface Example (2/4) Change OnDraw function of View Class void CExFileView::OnDraw(CDC* pDC) { CExFileDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); pDC->SetMapMode(MM_LOMETRIC); pDC->Ellipse(100, -100, 600, -600); }

Single Document Interface Example (3/4) Result

Single Document Interface Example (4/4) 실행 결과 (cont'd)

SDI Application A Simple Structure CWinApp CFrameWnd CSingleDocTemplate CDocument CView

SDI Application A structure with two views CWinApp CSingleDocTemplate CDocument CView 1 CFrameWnd CView 2

GetFirstViewPosition GetFirstDocTemplatePosition SDI Application How to refer each other Document Object View Frame Window GetFirstViewPosition & GetNextView GetDocument GetActiveDocument GetActiveView Application AfxGetMainWnd AfxGetApp m_pMainWnd GetParentFrame Document Template GetFirstDocTemplatePosition & GetNextDocTemplate GetDocTemplate GetFirstDocPosition & GetNextDoc

SDI Application Key Functions CWinApp* AfxGetApp ( ); Return the pointer to the application object CWnd* AfxGetMainWnd ( ); Return the pointer to the frame window object CView* CFrameWnd::GetActiveView ( ); Return the pointer to the view object CDocument* CView::GetDocument ( ); Return the pointer to the document object POSITION CDocument::GetFirstViewPosition ( ); CView* CDocument::GetNextView (POSITION& rPosition); Access to the view object(s) Document Object m_viewList View #1 View #2 View #3 NULL

Document/View in detail Create a new application as a SDI Edit the document template string

Document/View in detail Document template string ExSDI\n\nExSDI\nExSDI 파일 (*.sdi)\n.sdi\nExSDI.Document ① ② ③ ④ ⑤ ⑥ \nExSDI Document ⑦ No. Description 1 Title shown on the title bar 2 A initial name of the document. If skipped, “untitled” will be given 3 Brief name of the document 4 Brief name of the document in file dialog box 5 Default extension name 6 Document ID used in the windows registry 7 Document name used in the windows registry

Document Class Key CDocument operations Function Description GetFirstViewPosition Returns a POSITION value that can be passed to GetNextView to begin enumerating the views associated with this document GetNextView Returns a CView pointer to the next view in the list of views associated with this document GetPathName Retrieves the document's file name and path—for example, "C:\Documents\Personal\MyFile.doc"; returns an empty string if the document hasn't been named GetTitle Retrieves the document's title—for example, "MyFile"; returns an empty string if the document hasn't been named IsModified Returns a nonzero value if the document contains unsaved data or 0 if it doesn't SetModifiedFlag Sets or clears the document's modified flag, which indicates whether the document contains unsaved data UpdateAllViews Updates all views associated with the document by calling each view's OnUpdate function

Document Class Key CDocument Overrides Function Description OnNewDocument Called by the framework when a new document is created. Override to apply specific initializations to the document object each time a new document is created. OnOpenDocument Called by the framework when a document is loaded from disk. Override to apply specific initializations to the document object each time a document is loaded. DeleteContents Called by the framework to delete the document's contents. Override to free memory and other resources allocated to the document before it is closed. Serialize Called by the framework to serialize the document to or from disk. Override to provide document-specific serialization code so that documents can be loaded and saved.

Document class What happens when: [FILE]->[New] [FILE]->[Open...] [FILE]->[Save] or [File]->[Save as...] DeleteContents()  OnNewDocument() DeleteContents()  Serialize()  OnOpenDocument() Serialize()

View Class Key CView Overrides Function Description OnDraw Called to draw the document's data. Override to paint views of a document. OnInitialUpdate Called when a view is first attached to a document. Override to initialize the view object each time a document is created or loaded. OnUpdate Called when the document's data has changed and the view needs to be updated. Override to implement "smart" update behavior that redraws only the part of the view that needs redrawing rather than the entire view.

Coding practice Using Document/View architecture, make an application which draws circles and save/load it Things to change CView:: OnDraw() CDocument:: OnNewDocument() Serialize()