Dialog Boxes and Property Sheets

Slides:



Advertisements
Similar presentations
Microsoft Expression Web-Illustrated Unit J: Creating Forms.
Advertisements

Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Excel Project 7 Using Macros and Visual Basic for Applications (VBA) with Excel.
Using Macros and Visual Basic for Applications (VBA) with Excel
Chapter 5 Multitable Forms
Introduction to MFC. Motivation Abstract the Windows API Provides additional GUI options Insert Open Inventor into existing MFC application Document /
Microsoft Excel 2003 Illustrated Complete Excel and Advanced Worksheet Management Customizing.
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.
Tran Anh Tuan A.  Help to modify a control’s behavior by deriving classes of your own from the MFC control classes  Help to build reusable, self-contained.
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)
COMPREHENSIVE Excel Tutorial 8 Developing an Excel Application.
1 CA201 Word Application Increasing Efficiency Week # 13 By Tariq Ibn Aziz Dammam Community college.
Chapter 1 Databases and Database Objects: An Introduction
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.
Multiple Forms, Container Controls, AddHandler This presentation is based on the Forms and ContainerControls VB Projects 1.
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.
BZUPAGES.COM Visual Programming Lecture – 5 Miss. SADAF MAJEED SIAL Computer Science Department Bahauddin Zakariya University Multan.
Chapter 5 Menus, Common Dialog Boxes, and Methods Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
A First Look At Microsoft Visual Basic Lesson 1. What is Microsoft Visual Basic? Microsoft Visual Basic is a software development tool, which means it.
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.
Project Deployment IT [211 CAP] How to convert your project to a full application.
Office Management Tools II Ms Saima Gul. Office Management Tools II Ms Saima Gul.
BZUPAGES.COM Visual Programming Lecture – 6- 7 Miss. SADAF MAJEED SIAL Computer Science Department Bahauddin Zakariya University Multan.
Microsoft Access 2010 Chapter 8 Advanced Form Techniques.
XP New Perspectives on Microsoft Office FrontPage 2003 Tutorial 7 1 Microsoft Office FrontPage 2003 Tutorial 7 – Creating and Using Templates in a Web.
Microsoft FrontPage 2003 Illustrated Complete Creating a Form.
Click your mouse to continue. The Office Shortcut Bar The Office Shortcut Bar contains program buttons that, when clicked, start new documents or start.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
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.
Dialog boxes Modal and modeless dialog boxes Displaying about dialog box: case WM_COMMAND : switch (LOWORD (wParam)) { case IDM_APP_ABOUT : DialogBox (hInstance,
Chapter 8 Dialog Boxes and Property Sheet
Agency Web Site Navigation Structure. Building the agency web site Agency Web Site Navigation Structure, Slide 2Copyright © 2004, Jim Schwab, University.
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.
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…
Chapter 10 Using Macros, Controls and Visual Basic for Applications (VBA) with Excel Microsoft Excel 2013.
Creating ActiveX Controls at runtime If you need to create an ActiveX Control at runtime without a resource template entry, follow the programming steps.
Chapter 5 Using a Template to Create a Resume and Sharing a Finished Document Microsoft Word 2013.
Chapter 8 Using Document Collaboration, Integration, and Charting Tools Microsoft Word 2013.
Chapter 8 Multiple Forms, Modules, and Menus. Introduction This chapter demonstrates how to: – Add multiple forms to a project – Create a module to hold.
Chapter 11 Enhancing an Online Form and Using Macros Microsoft Word 2013.
Excel Tutorial 8 Developing an Excel Application
Visual Basic .NET BASICS
Introduction to Windows Programming
Microsoft Visual Basic 2005: Reloaded Second Edition
Forms Concepts Triggers Fired when Internal/External events occur
Steps to Build Frame Window Recipe Application
Microsoft Excel.
Chapter 1: An Introduction to Visual Basic 2015
Building a User Interface with Forms
Multiple Classes and Inheritance
3.01 Apply Controls Associated With Visual Studio Form
CHAPTER FIVE Decision Structures.
3.01 Apply Controls Associated With Visual Studio Form
Administering a Database System
Working with Dialogs and Controls
Dialog Boxes and Property Sheets
MFC Dialog Application
Microsoft Excel 2003 Illustrated Complete
Windows Desktop Applications
Chapter 7 Advanced Formatting and Merging Publications with Data
Access Chapter 5 Multi-Table Forms.
Microsoft Excel 2007 – Level 1
Chapter 7 Advanced Form Techniques
CHAPTER FIVE Decision Structures.
Microsoft Excel All editions of Microsoft office.
Multi-form applications and dialogs
Chapter 1 Databases and Database Objects: An Introduction
Object-Oriented Programming: Inheritance and Polymorphism
Shelly Cashman: Microsoft Word 2016
Presentation transcript:

Dialog Boxes and Property Sheets Jim Fawcett CSE791 – Advanced Windows Programming Summer 2002

References Programming Windows with MFC, Jeff Prosise, 2nd Edition, Microsoft Press, 1999 Derived from presentations by Kevin Devaney and Ciahua Wang, 2001

Dialog Boxes Modal Modeless Property Sheets Owner window disabled until dialog closed Modeless Owner window can be reactivated while dialog is still open Property Sheets Dialog boxes with tabbed pages

Class Hierarchy

Example Dialog Box Font dialog Controls Combo boxes List boxes Check boxes Push buttons

Create a Simple Dialog App Use MFC AppWizard Visual C++ Menu File / New / MFC AppWizard “Step 0” - Define project name and location Step 1 – Choose “Dialog-based” Other Steps – Accept defaults

Using MFC AppWizard

Add Dialog Controls Use toolbar to select controls for your dialog Click on the control you want Click on the dialog where you want to put the control Drag mouse on edges of the control to resize it Right-click on control, select properties and provide new ID

Dialog Resource File (.rc) IDD_CREDIT_DIALOG DIALOGEX 0, 0, 265, 154 STYLE DS_MODALFRAME | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_APPWINDOW CAPTION "Credit Card Calculator" FONT 8, "MS Sans Serif" BEGIN DEFPUSHBUTTON "Calculate",IDOK,198,102,41,14 PUSHBUTTON "Exit",IDCANCEL,198,126,41,14 CONTROL "Spin1",IDC_SPIN_DEBT,"msctls_updown32",UDS_ARROWKEYS,21,22,11,14 END Resource file has “dialog template” Dialog box characteristics (popup) Types of controls used in the dialog (spin) Control position, size, characteristics

Adding Shortcut Keys &Exit Right-click on control and select Properties &Exit Alt-E will activate the Exit button

Setting Tab Order In Visual C++ menu, choose Layout/Tab Order Current tab order will be shown Click on controls in desired order to set a new tab order

Responding to User Input Double-click on the control “Add Member Function” dialog will pop up Select “OK” and it will create a function for that control OnOK for OK button OnChangeEditXxxx for edit control Add code to the function to perform needed processing

Temperature Converter IDC_EDIT_INPUT IDC_EDIT_OUTPUT

OnOK Processing

How to talk to controls - 1 Use CWnd functions GetDlgItemText, SetDlgItemText CheckRadioButton, GetCheckedRadioButton CheckDlgButton, IsDlgButtonChecked This was illustrated in Temperature Converter example

How to talk to controls - 2 Use info supplied in the message handler

How to talk to controls - 3 Use common control classes CEdit, CListBox, CComboBox, CSliderCtrl, etc Use CWnd Attach function to associate control class with your control

Common Control Class Example Remember to use Detach function if you create the object on the stack

How to talk to controls - 4 Use Dynamic Data Exchange Override virtual function DoDataExchange Use DDX functions to associate member variables with controls Exchange occurs: Input (variable to control) in OnInitDialog Output (control to variable) in OnOK

DDX Example

DDX Functions DDX_Text Edit control DDX_Check Check box DDX_Radio Radio box DDX_LBIndex, DDX_LBString List box DDX_CBIndex, DDX_CBString Combo box DDX_Scroll Scroll bar

Dynamic Data Validation Dynamic data validation (DDV) works similar to DDX DDV checks that input data is within specified limits If data is outside limits, focus is passed to the control and an error message is displayed

DDV Example

DDV Functions DDV_MinMaxByte, DDV_MinMaxInt, DDV_MinMaxLong, DDV_MinMaxUInt, DDV_MinMaxDWord, DDV_MinMaxFloat, DDV_MinMaxDouble, DDV_MaxChars

Modal vs Modeless Modal Display dialog by calling CDialog::DoModal Exit by calling CDialog::OnOK or OnCancel Usually instantiated on the stack so destruction is automatic

Modal vs Modeless Modeless Display dialog by calling CDialog::Create Exit dialog by calling DestroyWindow Don’t call OnOK or OnCancel Usually instantiated on the heap (new) so the dialog is not destroyed prematurely Make sure dialog is deleted by overriding CDialog::PostNcDestroy function using “delete this” statement

Basic Modal Dialog Programming (see example p. 398) Declare dialog member variables in header file (.h) Initialize variables and setup controls in OnInitDialog Use Class Wizard to create message handler functions that get user input Perform data processing in OnOK and comment out call to Cdialog::OnOK()

Property Sheets Tabbed dialog boxes User can switch between pages using mouse MFC classes CPropertySheet CPropertyPage

Property Sheets Is a tabbed dialog box containing pages of controls that user can switch among. Encapsulated in a pair of MFC classes: CPropertySheet and CPropertyPage CPropertySheet represents the property sheet itself CPropertyPage represents a page in the property sheet. Property sheets can be modal or modeless, created with DoMomal() or Create()

How to Create a Modal Property Sheet For each page create a dialog template. For each page derive a dialog-like class from CPropertyPage that include public members linked to the page’s controls via DDX or DDV. Derive a property sheet class from CPropertySheet. Use CPropertySheet::AddPage() to add pages to the property sheet. Call the property sheet’s DoModal() to display the property sheet.

How to Create a Modal Property Sheet (cont.) MFC CPropertySheet provide functions for three buttons -- OK, Cancel and Apply. Property sheet pages should not include OK or Cancel button --when the property sheet’s OK buton is clicked, the current page’s OnOK() is called. Add message handler for Apply button, which should call the active page’s UpdateData(TRUE). Use CPropertyPage’s SetModified() to enable or disable Apply button.

How to Create a Modal Property Sheet (cont.) class CFirstPage:public CPropertyPage{ public: …. // delare member here ptotected: virtual void DoDataExchange(CDataExchange*); …. }; class CMyPropertySheet:public CProperySheet{ CFirstPage m_firstPage; // first page ….. public: …. CMyPropertySheet(…){ // constructor AddPage(&m_firstPage); …. }

Common Dialogs CFileDialog CPrintDialog CPageSetupDialog CFindReplaceDialog CColorDialog CFontDialog

CFileDialog

CFileDialog code TCHAR szFilters[] = _T("Text files (*.txt)|*.txt|All files (*.*)|*.*||") CFileDialog dlg(TRUE, _T("txt"), _T("*.txt"), OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, szFilters); if( dlg.DoModal() == IDOK ) { filename = dlg.GetPathName(); }