The last of the custom screens, View Text, functions similarly to Edit Text--with a couple of differences. It displays any previously entered text, but the user is not allowed to edit it. The Print button is now visible and functional (see Figure 6
). The class declaration and implementation of CViewTextDlg contain the messaging code for the Print button (see Listings 7
). Again, the dialog creator sets the text in the dialog by calling SetText(), which is implemented in CViewTextDlg. If the user hits Print, it displays the message box shown in Figure 7
Bring It All Together
|Figure 6. Adding Options and Restrictions: From here, you can view the text, but the edit control does not allow text editing. You can print now, so the Print button is visible.
||Figure 7. The "Print" Dialog: The message box located in the print button handler in CViewTextDlg is activated when the user hits the Print button.|
The main screen, shown in Figure 1
, ties it all together. AppWizard created most of the code for it, so I am not going to show that portion. I'll show just the code I added (see Listing 9
). CPolymorphicDialogBoxExampleDlg is the name of the class I used for the main screen. The header file contains the following variable declaration to create a holding place for what the user typed/edited in the screens:
class CPolymorphicDialogBoxExampleDlg :
The three functions you see in Listing 9 for the "New," "Edit," and "View" buttons are the event handlers I set up using Class Wizard. Notice how they use CreateDlg() to create the custom screens.
This program is just one example of what you can do with MFC customization. You can customize MFC in all sorts of ways to get the look and functionality that you want-and you don't have to sacrifice object-orientation to do it.