Teach Yourself Visual C++® 5 in 24 Hours

Previous chapterContents


- Appendix B -
Quiz Answers

This appendix lists the answers to the quiz questions in the Workshop sections at the end of each hour.

Hour 1 Quiz

1. A library is a collection of reusable source code or compiled code that can be used in a program. The MFC class library and the standard C++ library are examples of commonly used libraries.

2. A project is built by using one of these steps:
3. A wizard is a tool similar to a dialog box that guides you through a series of steps.

4. AppWizard, ClassWizard, and ControlWizard

5. Press the F1 function key.

6. ClassView, FileView, ResourceView, and InfoView

7. OnDraw

8. The F7 function key

9. Ctrl+Z

10. Undo reverses an action; Redo reverses an Undo.

Hour 2 Quiz

1. The cout iostream object is used to display output to a console-mode window. The cin iostream object is used to collect input from the keyboard.

2. When including project-specific files that are located in the project directory, use quotes around the header filename, as in the following:
#include "myfile.h"
When including library files that are located in a standard location, use angle brackets around the filename, like this:
#include <myfile.h>
3. Character values are stored in variables that have the char type.

4. A C++ namespace provides a container for a set of names. This prevents identical names in two parts of your application from conflicting with each other.

5. To declare multiple variables on one line, separate the variable names with a comma, like this:

int nFoo, nBar, nBaz;
6. Type-safety refers to the capability of a C++ compiler to enforce rules that ensure that variables and functions are used as they are intended. This helps the compiler detect a large number of common errors.

7. The floating-point variable types are float, double, and long double.

8. The C++ assignment operator is the equals sign, =, as in nFoo = 5;.

9. Integer values are normally stored in variables that have the int type. To save space, smaller values may be stored in the char and short int types.

10. If you know that a value will not be negative, you can double the maximum value stored in the variable by declaring it as unsigned.

Hour 3 Quiz

1. Dialog boxes, menus, toolbars, and controls are all examples of windows.

2. A function is a group of computer instructions that are grouped together to perform a well-defined task.

3. The function's name, return value, parameter list, and function body.

4. Classes are exactly like structures, except that members of a class cannot be accessed from outside the class by default.

5. The constructor

6. The destructor

7. The non-client area contains the borders, menu, and caption area; the client area is the area that is left over.

8. 42

9. The * symbol is used for multiplication.

10. The / symbol is used for division.

Hour 4 Quiz

1. A modal dialog box prevents the user from interacting with the program until the dialog box is dismissed. A modeless dialog box does not prevent the user from interacting with the program.

2. WM_INITDIALOG

3. .h

4. .cpp

5. The warning icon, MB_ICONEXCLAMATION

6. The stop sign icon, MB_ICONSTOP

7. CDialog

8. DoModal

9. IDYES

10. IDNO

Hour 5 Quiz

1. A Cancel button is used to close the dialog box and discard any changes that have been made. A Close button is used to close the dialog box and keep any changes that have been made.

2. An OK button is used to close the dialog box and keep any changes that have been made. An Apply button keeps changes that have been made but does not close the dialog box; this button is often used when the Apply button is used to update the application that displays the dialog box.

3. CButton

4. Check boxes, radio buttons, pushbuttons, group boxes, and owner-drawn buttons.

5. Clear the Tab Stop property for the control.

6. Enable

7. ShowWindow

8. The default label is selected when no case labels match the switch expression.

9. The = operator is used for assignment. The == operator is used to test for equality.

10. SetWindowText

Hour 6 Quiz

1. CEdit

2. An MLE is a multiline edit control and accepts multiple lines of text as input. An SLE is a single-line edit control and accepts single lines of text as input.

3. A DDV routine is used to validate data input stored in a control. A DDX routine is used to transfer data to or from a control.

4. UpdateData

5. GetWindowText

6. SetWindowText

7. Password

8. Ctrl+V

9. Ctrl+C

10. Ctrl+X

Hour 7 Quiz

1. CListBox

2. LBN_DBLCLCK

3. AddString and InsertString

4. GetCount

5. GetCurSel

6. Single-selection, multiple-selection, and extended-selection

7. for, while, and do-while

8. CComboBox

9. InsertString

10. Simple, drop-down, and drop list

Hour 8 Quiz

1. The default window procedure is a special function supplied by Windows that handles messages that aren't handled by the application.

2. Messages are physical chunks of data and are easily prioritized. They are not processor or language dependent.

3. When the mouse cursor passes over a window, the window receives the WM_MOUSEMOVE and WM_NCMOUSEMOVE messages.

4. A message map is used to associate a message with a function used to process that message.

5. CObject is the base class for most MFC classes.

6. The Dump function is used to display debug information about the current state of an object.

7. The ASSERT macro is used to test an expression that is not needed when the program is compiled for release mode. The VERIFY macro is used to test an expression that is used when the program is compiled for release mode. When compiled for release mode, the ASSERT macro and the expression contained inside it will be removed; the VERIFY macro is also removed, but its contained expression is compiled.

8. WM_LBUTTONDOWN

9. The message map entries reserved for use by ClassWizard begin with //{{AFX_MSG_MAP and end with //}}AFX_MSG_MAP.

Hour 9 Quiz

1. The sizeof operator returns the number of bytes required to hold an object.

2. A pointer that points to one variable can be changed to point to another variable; references must be bound to a single variable for their lifetime. A reference to a class uses . to access a member, a pointer to a class uses the -> operator.

3. Passing a point to an object rather than the object itself is almost always more efficient. Passing a pointer parameter is a 32-bit variable; passing an object such as a class instance requires that a copy be made of the instance--and not only must the copy be made, it must be destroyed after the copy is no longer needed.

4. The new keyword is used to dynamically allocate memory.

5. The delete keyword is used to release memory allocated with new.

6. Classes derived from CView are responsible for the user interface.

7. The four classes are
8. The document class is responsible for an application's data.

9. The GetDocument function returns a pointer to the document associated with a view.

10. A document class uses UpdateAllViews to notify views associated with the document that their user interfaces might need to be updated.

Hour 10 Quiz

1. The CMenu class

2. The WM_CONTEXTMENU message

3. An ellipsis (...) after the menu item

4. A letter that is used to represent the menu item, such as x in Exit

5. A keyboard shortcut to a message-handling function

Hour 11 Quiz

1. An information context cannot be used for output.

2. SelectStockObject

3. Approximately 1440

4. A pen

5. A brush

6. Use the GetTextMetrics function.

7. RGB is used to create a COLORREF value.

8. CDC

9. If SelectObject returns NULL, the call failed.

10. MM_TEXT

Hour 12 Quiz

1. Width, color, and style

2. Cosmetic and geometric

3. CPen

4. BLACK_PEN, WHITE_PEN, and NULL_PEN

5. PS_SOLID, PS_DASH, PS_DOT, PS_DASHDOT, PS_DASHDOTDOT, PS_NULL, PS_INSIDEFRAME, and PS_ALTERNATE

6. PS_SOLID, PS_DASH, PS_DOT, PS_DASHDOT, PS_DASHDOTDOT, PS_NULL, and PS_INSIDEFRAME

7. Solid, hatch, pattern, and stock

8. BLACK_BRUSH, DKGRAY_BRUSH, GRAY_BRUSH, HOLLOW_BRUSH, LTGRAY_BRUSH, NULL_BRUSH, and WHITE_BRUSH

9. CBrush

10. Ellipse

Hour 13 Quiz

1. Serif fonts include Courier, Garamond, and Times Roman; sans-serif fonts include Arial, Tahoma, and MS Sans Serif.

2. ANSI_FIXED_FONT, ANSI_VAR_FONT, DEVICE_DEFAULT_FONT, DEFAULT_GUI_FONT, OEM_FIXED_FONT, and SYSTEM_FONT

3. The font escapement is the angle in tenths of a degree that a line of text forms with the bottom of the page.

4. A glyph is an individual character.

5. CFont

6. Decorative, Modern, Roman, Script, Swiss, and Dontcare

7. DEFAULT_PITCH, FIXED_PITCH, and VARIABLE_PITCH

8. SetFont

Hour 14 Quiz

1. SetIcon

2. The hotspot

3. ClipCursor

4. SetCapture

5. SetCursor

6. WM_SETCURSOR

7. 16x16

8. BeginWaitCursor

Hour 15 Quiz

1. CBitmap

2. CPalette

3. Memory DC

4. BitBlt

5. 256

6. 20

7. WM_QUERYNEWPALETTE and WM_PALETTECHANGED

8. WM_QUERYNEWPALETTE is sent to an application when it moves into the foreground. WM_PALETTECHANGED is sent to an application after the system palette has been updated.

Hour 16 Quiz

1. The Orientation property can be set to either horizontal (left-right) or vertical (up-down).

2. Auto-buddy

3. The CSpinButtonCtrl::SetRange member function is used to set the minimum and maximum limits for an up-down control.

4. The control tab order determines which control is paired with the up-down control. The up-down control must follow the buddy control in the tab order.

5. Tick marks

6. The CSliderCtrl::SetRange member function is used to set the minimum and maximum limits for an up-down control.

7. The CProgressCtrl::SetRange member function is used to set the minimum and maximum limits for an up-down control.

Hour 17 Quiz

1. Masked and unmasked. Masked image lists include a mask used to draw the image transparently.

2. If items are often added to the image list, the grow-by parameter reduces the number of costly internal resize operations performed by the image list.

3. A transparent image is an image that allows part of the background surface to be visible.

4. The color mask is used to determine the color in the bitmap that is treated as the transparent color. The image list uses this information to create a mask for the image.

5. ILD_TRANSPARENT

6. The ILD_BLENDxx styles are used to combine the image with the system highlight color.

7. You are always responsible for destroying the bitmap or icon used as a source for the image stored in the image list. The image list will keep a copy of the image internally.

8. An overlapped image is made up of two combined image list items.

Hour 18 Quiz

1. There are four list view styles: Icon, Small Icon, Report, and List.

2. Icon view uses a 32x32 icon. Small icon view uses a 16x16 icon.

3. LVN_BEGINLABELEDIT and LVN_ENDLABELEDIT

4. You will receive LVN_ENDLABELEDIT with the LV_ITEM pszText member set to NULL or the iItem member set to -1.

5. SetWindowLong

6. First, you must initialize the LV_COLUMN structure, then call CListCtrl's InsertColumn member function.

7. Call CListCtrl's SetItem text member function.

8. -1

Hour 19 Quiz

1. TVN_BEGINLABELEDIT and TVN_ENDLABELEDIT

2. TVN_BEGINDRAG is sent when the drag operation begins, WM_MOUSEMOVE is sent when the mouse is being moved, and WM_LBUTTONUP is sent when the user releases the primary mouse button.

3. The first image is displayed when the tree view item is in its normal state. The second image is displayed when the item is selected.

4. CTreeCtrl::DeleteAllItems()

5. The properties for any view can be changed in the PreCreateWindow function.

6. The TVS_HASLINES is equivalent to the Has lines property; TVS_LINESATROOT is the same as the Lines at root property, TVS_BUTTONS is the same as the Has buttons property, and the TVS_EDITLABELS style is equivalent to the Edit labels property.

7. Unlike the list view control, where items are referred to by an index, items in a tree view control are referred to through an HTREEITEM handle.

8. Images stored in a tree view control can be any size.

9. Use the TVI_FIRST symbol when calling CTreeCtrl::InsertItem:

m_tree.InsertItem( szLabel, 1, 1, hParent, TVI_FIRST );

Hour 20 Quiz

1. In the Components and Controls Gallery

2. Visual Fox Pro, Visual Basic, Access 95, and Delphi are just a few of the development tools that support ActiveX controls.

3. Examples of events fired from ActiveX controls include mouse clicks, pressed buttons, and expiring timers.

4. Examples of properties exposed by ActiveX controls are the font and background color used by a control.

5. A grid control, such as the Microsoft FlexGrid

6. False

7. In AppWizard step two, the ActiveX Controls check box must be selected.

8. A function that is exposed by the control and called by the control's container

9. False

Hour 21 Quiz

1. Call the GetDeviceCaps function and ask for RASTERCAPS information. Check the RC_BITBLT bit in the result. (See Listing 21.2.)

2. The five MFC view functions that are most commonly overridden for printing are
3. These functions are called once for each print job:
These functions are called once for each printed page:
4. CPrintInfo

5. OnBeginPrinting

6. About 1,440

7. Set the CPrintInfo::m_bContinue member variable to TRUE

8. The positive direction is up--the bottom of the page is usually a large negative number.

9. The positive direction is to the right.

10. OnEndPrinting

Hour 22 Quiz

1. Persistence is the capability of an object to remember its state between executions.

2. Serialization is the act of storing the state of an object for the purpose of loading it at another time.

3. Serialization is the act of storing the state of a persistent object to an archive; deserialization is the act of reading data from an archive and re-creating a persistent object.

4. CArchive

5. Serialize

6. SerializeElements

Hour 23 Quiz

1. A form view is always modeless, whereas a dialog box can be either modal or modeless. A form view fits into the Document/View architecture and receives view messages from the MFC framework; a dialog box does not.

2. A dialog box resource used in a form view must have the following attributes:

3. You must call ResizeParentToFit twice during OnInitialUpdate:
ResizeParentToFit( FALSE );

ResizeParentToFit();
4. OnInitialUpdate is called when the form view is initially displayed and is a good place to perform one-time initializations for your form view. OnUpdate is called when the document wants to notify the view that the document has been updated; it's also called after OnInitialUpdate.

5. To prevent an MDI child window from being resized, you must change the style of the frame that contains the form window. By default, this is the CChildFrame class. Masking off the WS_THICKFRAME style bits during PreCreateWindow will create a frame window that cannot be resized. If you make this modification, you might also want to mask off the WS_MAXIMIZEBOX style bit; this will disable the Maximize button on the form view.

6. UpdateAllViews

7. A document template resource string, an icon used for the view, and the menu used for the view

8. CEditView

9. CScrollView

10. CMultiDocTemplate

Hour 24 Quiz

1. An ActiveX interface is a group of related functions that are grouped together.

2. IUnknown

3. The ActiveX Control Test Container, Visual Basic, Internet Explorer, Access, Word, Excel, PowerPoint, and many others.

4. Ambient, Extended, Stock, and Custom

5. Stock and Custom

6. DDP and DDX

7. COleCtrl, COleControlModule, and COlePropertyPage

8. Ambient properties

9. Subclassing is a method of borrowing functionality from another window or control.

10. DoSuperclassPaint


Previous chapterContents


Macmillan Computer Publishing USA

© Copyright, Macmillan Computer Publishing. All rights reserved.