Windows NT Systems Programming: Spring 2000
[ Home | Syllabus | Course Notes | Assignments | Search]
Dialog Boxes (Chapter 6)
- Dialog boxes are used
- To give messages to the user
- Receive (usually) small amounts of information from the user
- Can be
- modal: wait till done, no other processing can proceed
- modeless: can work elsewhere in the application (find/replace
dialog)
this is more complicated than "modal" since need to manage several threads
of control and possible synchronize
- CDialog is an object derived from CWnd (see
hierarchy chart inside front cover.)
- Most dialog boxes are built using the dialog editor (one of the resource editors).
- Dialogs contain one or more elements called controls.
There is an excellent selection of controls already available which work together (radio
buttons, edit controls, sliders, lists, combo boxes, progress bars, etc)
More information on controls can be found here.
- Most controls are objects in MFC derived from CWnd.
- Challenge: how to communicate between the dialog box and the rest
of the application?
- How are the initial values of the control objects set?
- For example, user clicks on a control (say the "OK" button)
the button is a window which gets a WM_LButtonDown message
How is control passed back to the main application?
- How are values set in a dialog transferred back to the main application?
- The answers form an interesting study of object oriented design and division of
responsibilites
Two critical questions any software designer should ask are:
- Which object should remember this information
- Which object is responsible for making this happen.
Three Simple Dialog
To illustrate some of the difficulties in building a good dialog box
and the advantage of reusing CDialog object from the MFC library and the use of the
Resource/Dialog Editor and Class Wizard, I present three versions of a simple dialog to
ask the user for a new title for the main window.
Version one does not
use CDialog, but builds the dialog in the main window itself. This is not a good solution
but it does clearly illustrate the communications between CEdit and CButton controls.
Version two uses CDialog
and the Dialog editor and illustrates how to incorporate a resource compiler generated
dialog into your program. Illustrates passing of data from Edit to MainWindow.
Version three uses the app
and class wizard and most closely follows the example in the book. Hopefully some the
magic going on behind the scenes will make sense.
The book has a interesting dialog that incorporates most of the basic controls.
See source here.
And an even more interesting one that requires user programming to work.
See source here.
Copyright chris wild 1999/2000.
For problems or questions regarding this web contact [Dr.
Wild].
Last updated: January 25, 2000.