[ Pobierz całość w formacie PDF ]
.Because it is much smaller, the HelloDialogproject will compile and launch faster than an SDI or MDI project.For that reasonmany of the examples in this book that deal with controls will use dialog box-basedprojects.SummaryThis hour began with an introduction to object-oriented design.In this hour,you also learned about dialog boxes and how they are used in programs written forWindows.This hour also covered the support provided by Developer Studio, includingClassWizard, the MFC class library, and the dialog box editor.Q&AQ When I display a modal dialog box, no other part of the user interface canbe used; does my application also stop functioning while the dialog box is displayed?A A modal dialog box prevents the user from accessing other parts of yourapplication; it does not prevent Windows from sending events to your message-handlingprocedures.Your application will continue to work normally while displaying a modaldialog box.Q Why are C++ classes always split into two files? Wouldn't it be easier to haveonly a single file that defines the class as is done with Java?A A key part of most languages that support object-oriented programming isthe idea that the description of a class should be kept separate from its implementation.This fits in with the notion of information hiding, where unnecessary details arehidden whenever possible.In a well-designed C++ class, the implementation is considereda detail that the consumer doesn't need to be concerned with.In Java, the class is always defined inside the class declaration, and they are neverseparated.This simplifies the work required for the compiler and runtime system.However, it also forces you to deal with implementation details when reading theclass declaration.If you prefer to define a class inside the class declaration, C++ supports that codingstyle; just include the function body after its declaration:class CFoo{int m_nBar;public:CFoo(){m_nBar = 0;}void SetBar(int newVal){m_nBar = newVal;}int GetBar() const{return m_nBar;}};WorkshopThe Workshop is designed to help you anticipate possible questions, review whatyou've learned, and begin thinking ahead to putting your knowledge into practice.The answers to the quiz are in Appendix B, "Quiz Answers."Quiz1.What is the difference between a modal and modeless dialog box?2.What message is sent to a dialog box for initialization purposes?3.What is the file extension used for C++ class declaration files?4.What is the file extension used for C++ class implementation files?5.What message box style is provided by default when using AfxMessageBox?6.What message box style should be used when reporting an error to a user?7.What MFC class is used to manage dialog boxes?8.What member function is called to pop up a modal dialog box?9.If the user presses the Yes button in a message box, what return value is providedto AfxMessageBox?10.If the user presses the No button in a message box, what return value is providedto AfxMessageBox?Exercises1.Change the HelloSDI example so that the message box displayed for WM_INITIDIALOGuses the information icon.2.Add a second static text label to the HelloDialog project's main dialog box thatdisplays your name.© Copyright, Macmillan Computer Publishing.Allrights reserved
[ Pobierz całość w formacie PDF ]