Dialog Boxes and Property Sheets Prosise, Chapter 8 - PowerPoint PPT Presentation

1 / 37
About This Presentation
Title:

Dialog Boxes and Property Sheets Prosise, Chapter 8

Description:

This was illustrated in Temperature Converter example. How to talk to controls - 2 ... User can switch between pages using mouse. MFC classes. CPropertySheet ... – PowerPoint PPT presentation

Number of Views:227
Avg rating:3.0/5.0
Slides: 38
Provided by: kwde
Category:

less

Transcript and Presenter's Notes

Title: Dialog Boxes and Property Sheets Prosise, Chapter 8


1
Dialog Boxes and Property SheetsProsise, Chapter
8
  • Jim Fawcett
  • CSE681 Advanced Windows Programming
  • Summer 2003
  • Derived from a presentations by
  • Kevin Devaney and Ciahua Wang

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

3
Class Hierarchy
4
Example Dialog Box
  • Font dialog
  • Controls
  • Combo boxes
  • List boxes
  • Check boxes
  • Push buttons

5
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

6
Using MFC AppWizard
7
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

8
Creating MFC Dialog Application
9
Selecting Application Type
10
Resource Editor View
11
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
12
Adding Shortcut Keys
Exit
Right-click on control and select Properties
Alt-E will activate the Exit button
13
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
14
Responding to User Input
  • Double-click on the control
  • Creates the default event handler, e.g.,
    OnEnChangeEdit1 for EditBox.
  • To get more choices right click and select add
    event handler.
  • Add code to handler function to perform needed
    processing

15
Adding an Event Handler
16
Temperature Converter
IDC_EDIT_INPUT
IDC_EDIT_OUTPUT
17
OnOK Processing
18
How to talk to controls - 1
  • Use CWnd functions
  • GetDlgItemText, SetDlgItemText
  • CheckRadioButton, GetCheckedRadioButton
  • CheckDlgButton, IsDlgButtonChecked
  • This was illustrated in Temperature Converter
    example

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

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

21
Common Control Class Example
Remember to use Detach function if you create
the object on the stack
22
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

23
DDX Example
24
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

25
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

26
DDV Example
27
DDV Functions
  • DDV_MinMaxByte, DDV_MinMaxInt,
  • DDV_MinMaxLong, DDV_MinMaxUInt,
  • DDV_MinMaxDWord, DDV_MinMaxFloat,
  • DDV_MinMaxDouble, DDV_MaxChars

28
Modal vs Modeless
  • Modal
  • Display dialog by calling CDialogDoModal
  • Exit by calling CDialogOnOK or OnCancel
  • Usually instantiated on the stack so destruction
    is automatic

29
Modal vs Modeless
  • Modeless
  • Display dialog by calling CDialogCreate
  • Exit dialog by calling DestroyWindow
  • Dont call OnOK or OnCancel
  • Usually instantiated on the heap (new) so the
    dialog is not destroyed prematurely
  • Make sure dialog is deleted by overriding
    CDialogPostNcDestroy function using delete
    this statement

30
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 andcomment out
    call to CdialogOnOK()

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

32
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 includes members linked to the
    pages controls via DDX or DDV.
  • Derive a property sheet class from
    CPropertySheet.
  • Use CPropertySheetAddPage() to add pages to the
    property sheet.
  • Call the property sheets DoModal() to display
    the property sheet.

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

34
How to Create a Modal Property Sheet (cont.)
  • class CFirstPagepublic CPropertyPage
  • public .
  • // delare member here
  • protected
  • virtual void DoDataExchange(CDataExchange)
    .
  • class CMyPropertySheetpublic CProperySheet
  • public .
  • CFirstPage m_firstPage // first page ..
  • CMyPropertySheet() // constructor
  • AddPage(m_firstPage) .

35
Common Dialogs
  • CFileDialog
  • CPrintDialog
  • CPageSetupDialog
  • CFindReplaceDialog
  • CColorDialog
  • CFontDialog

36
CFileDialog
37
CFileDialog code
TCHAR szFilters _T( "Text files
(.txt).txtAll files (.). ) CFileDialo
g dlg(TRUE, _T("txt"), _T(".txt"),
OFN_FILEMUSTEXIST OFN_HIDEREADONLY,
szFilters) if( dlg.DoModal() IDOK )
filename dlg.GetPathName()
Write a Comment
User Comments (0)
About PowerShow.com