Chapter 6 shows you how to invoke another standard Windows feature: the dialog box. You learn how to add standard and custom dialog boxes to your project. The objectives important to this chapter are:
Although it seems longer, the first part of this chapter is quite repetitive, so you can save time with the copy and paste features in the coding section. An observation may be appropriate: when doing the copy and paste procedure, you must know what to copy and what to paste.
A few students may need to review basic concepts about functions. You must understand that a function is called by some event in a Windows program. Note that the names of functions in this project (and all others) should contain a logical reminder of the event calling the function. The name alone does not determine the link, it is determined when you are in the Code Wizard screen and set up the link to the event/message map. If you were coding by hand, and not using the wizard, you would have to pay much more attention to the names used by Windows to refer to these events.
A dialog box is a device to get input back from a user. You pop a dialog box on the screen when you want the user to make a choice about what to do next. You have already used the basic function for this in previous programs: the MessageBox() function. You may recall that the default behavior of a message box is to present only an OK button to the user. This is fine, as long as you only wanted to send a message to the user and get an acknowledgement. Chapter 6 shows you how to ask for a choice from the user as well.
The first project in the chapter starts on page 166. You create a five button Dialog Box application. Don't confuse the project dialog box with the four subsequent dialog boxes that you teach the application to create.
It may be helpful to work in pairs, sharing books, so that you can look at the picture of the application design on page 166, while working on the object creation and property settings on pages 168 and 169.
On page 169, you create a variable and associate it with the Edit Box in your project. This control does not need to be an edit box, since the user will not type in it, but it is visually appealing to use one. You will use the variable associated with the Edit Box to change the contents of the box, making use of the UpdateData() function as in previous projects.
You attach code to the exit button on page 170 (which you should be able to do in your sleep by now). The next button to be coded is on page170 as well, and it establishes the pattern for the rest. When you have this code right, remember to copy, paste and modify it for the next three buttons to save typing.
You begin by creating a function to be called when the button you are coding
is clicked. The code is shown on page 171. Several things happen in it:
This sequence is repeated for each button you attach code to. The differences are in the buttons and icon you are told to use for each one, showing you the variety available, and the tests associated with those buttons.
The next section of the chapter tells you about creating a custom dialog box, as seen on page 181. This is a common approach for asking the user specific questions, yet offering a more varied response than just clicking a button.
Begin this project as usual, following the directions on pages 182 and 183.
There are only a few new ideas in this project:
It should be clear to you what is happening from the text descriptions, but you will be required to discuss the procedure in class, so become familiar with it.