Home »
MCQs
Microsoft Foundation Class (MFC) MCQs (Multiple-Choice Questions)
Practice Microsoft Foundation Class (MFC) MCQs (Multiple-Choice Questions) with answers and explanations. These MFC questions cover MFC architecture, CWinApp, CWnd, document/view architecture, message maps, dialogs, controls, resources, device contexts, SDI, MDI, document templates, and other important MFC concepts.
Microsoft Foundation Class (MFC) MCQs
Microsoft Foundation Classes (MFC) is a C++ class library for developing Windows applications. MFC provides classes that encapsulate many Win32 concepts and application features, including windows, dialogs, documents, views, menus, controls, and device contexts.
List of Microsoft Foundation Class (MFC) MCQs
The following MFC multiple-choice questions are useful for beginners, experienced C++ developers, technical interviews, examinations, and Windows application development preparation.
1. What does MFC stand for?
- Microsoft Foundation Classes
- Microsoft Framework Components
- Microsoft Functional Classes
- Microsoft Foundation Components
Answer: A) Microsoft Foundation Classes
Explanation:
MFC stands for Microsoft Foundation Classes. It is a C++ class library designed to simplify development of Windows applications.
2. Which programming language is primarily associated with MFC?
- Java
- C++
- Python
- Visual Basic
Answer: B) C++
Explanation:
MFC is a C++ class library. It provides C++ wrappers and framework classes for many Windows programming concepts and Win32 APIs.
3. Which MFC class represents the main application object?
CWnd
CView
CWinApp
CDocument
Answer: C) CWinApp
Explanation:
CWinApp is the main application class in MFC. An MFC application normally has one application object derived from CWinApp.
4. Which MFC class provides the base functionality for Windows objects?
CWnd
CFrameWnd
CDialog
CView
Answer: A) CWnd
Explanation:
CWnd provides the basic functionality of Windows window objects in MFC and encapsulates the Win32 window handle represented by HWND.
5. Which MFC class represents an application document in the document/view architecture?
CView
CDocument
CWnd
CFrameWnd
Answer: B) CDocument
Explanation:
CDocument provides the basic functionality for programmer-defined document classes and is responsible for representing application data.
6. Which MFC class represents a view of a document?
CView
CDocument
CWinApp
CDocTemplate
Answer: A) CView
Explanation:
CView provides the basic functionality for view classes. A view displays document data and handles user interaction with that data.
7. Which MFC class is commonly used as the base class for an SDI frame window?
CFrameWnd
CDialog
CView
CDocument
Answer: A) CFrameWnd
Explanation:
CFrameWnd supports frame-window objects. It is commonly used as the base for the main frame window in an SDI MFC application.
8. Which MFC class is commonly used for the main frame window in an MDI application?
CMDIFrameWnd
CView
CDocument
CDialog
Answer: A) CMDIFrameWnd
Explanation:
CMDIFrameWnd provides functionality for the main frame window of an MDI application.
9. Which MFC class represents a dialog box?
CDialog
CFrameWnd
CMenu
CView
Answer: A) CDialog
Explanation:
CDialog encapsulates dialog-box functionality in MFC. Custom dialog classes are commonly derived from CDialog or one of its derived classes.
10. Which MFC class encapsulates a Win32 device context?
CDC
CWnd
CBitmap
CBrush
Answer: A) CDC
Explanation:
CDC encapsulates a Windows device context and provides member functions for drawing and other device-context operations.
11. Which MFC class represents a Windows menu?
CMenu
CMenuBar
CCommandMenu
CWinMenu
Answer: A) CMenu
Explanation:
CMenu provides an MFC wrapper for Windows menu resources and menu handles.
12. Which MFC class represents a font?
CFont
CTextFont
CTypeface
CFontObject
Answer: A) CFont
Explanation:
CFont encapsulates a Windows font object and provides functions for creating and managing fonts.
13. Which MFC class represents a brush?
CBrush
CFill
CBackground
CBrushObject
Answer: A) CBrush
Explanation:
CBrush encapsulates a Windows brush object, which can be selected into a device context for filling areas.
14. Which MFC class represents a pen used for drawing?
CPen
CLine
CDrawPen
CPenStyle
Answer: A) CPen
Explanation:
CPen encapsulates a Windows pen object. It can be used to control the appearance of lines drawn through a device context.
15. Which MFC class encapsulates a bitmap?
CBitmap
CImageMap
CGraphic
CBitmapView
Answer: A) CBitmap
Explanation:
CBitmap encapsulates a Windows bitmap object and provides functions for loading, creating, and managing bitmap resources.
16. Which MFC class represents a point?
CPoint
CPosition
CXY
CPointObject
Answer: A) CPoint
Explanation:
CPoint is an MFC geometry class representing a point using horizontal and vertical coordinates.
17. Which MFC class represents a rectangle?
CRect
CBox
CRectangle
CWindowRect
Answer: A) CRect
Explanation:
CRect represents a rectangle and provides operations for manipulating its coordinates, dimensions, and relationships with other rectangles.
18. Which MFC class represents a size?
CSize
CDimension
CWidthHeight
CMeasure
Answer: A) CSize
Explanation:
CSize represents the dimensions of an object using width and height values.
19. Which MFC class is commonly used to represent a string?
CString
CStringObject
CText
CStdString
Answer: A) CString
Explanation:
CString is an MFC string class that provides convenient operations for storing and manipulating strings.
20. Which class is the root class of the MFC class hierarchy?
CWnd
CObject
CWinApp
CBase
Answer: B) CObject
Explanation:
CObject is the root of the principal MFC class hierarchy and provides common functionality such as runtime-class support and serialization support for appropriate derived classes. Not every MFC-related type derives from CObject.
21. Which MFC class is derived from CWinThread and represents the main application object?
CWnd
CWinApp
CFrameWnd
CDocument
Answer: B) CWinApp
Explanation:
CWinApp is derived from CWinThread. The application object represents the primary application thread and controls application initialization and termination.
22. Which member function is commonly overridden in a CWinApp-derived class to initialize an MFC application?
InitInstance
StartApplication
InitializeApp
OnStart
Answer: A) InitInstance
Explanation:
InitInstance is commonly overridden in a class derived from CWinApp to perform application-specific initialization.
23. What does the MFC document/view architecture primarily separate?
- CPU and memory
- Data and its presentation
- Menus and toolbars
- Threads and processes
Answer: B) Data and its presentation
Explanation:
The document/view architecture separates the application's data from how that data is displayed and manipulated. The document manages the data, while the view presents it to the user.
24. Which MFC class is responsible for storing or managing application data in the document/view model?
CView
CDocument
CFrameWnd
CWnd
Answer: B) CDocument
Explanation:
The document class represents the application's data. It can also handle persistence-related operations such as loading and saving document data.
25. Which MFC class displays document data and handles user interaction with it?
CView
CDocument
CWinApp
CDocTemplate
Answer: A) CView
Explanation:
A view acts as the user's window onto the document data. It displays the data and processes appropriate user interactions.
26. Which MFC class coordinates the creation and management of documents, views, and frame windows?
CDocTemplate
CView
CWinApp
CWnd
Answer: A) CDocTemplate
Explanation:
CDocTemplate coordinates the relationships between document, view, and frame-window classes for a particular document type.
27. Which document template class is typically used for an SDI application?
CMultiDocTemplate
CSingleDocTemplate
CSdiTemplate
CSingleViewTemplate
Answer: B) CSingleDocTemplate
Explanation:
CSingleDocTemplate is the document-template class used for applications with a single document at a time, such as a typical SDI application.
28. Which document template class is typically used for an MDI application?
CSingleDocTemplate
CMultiDocTemplate
CMdiTemplate
CMultiViewTemplate
Answer: B) CMultiDocTemplate
Explanation:
CMultiDocTemplate supports multiple documents of a particular type in an MDI application.
29. What does SDI stand for in MFC application architecture?
- Single Data Interface
- Single Document Interface
- System Document Interface
- Standard Document Integration
Answer: B) Single Document Interface
Explanation:
SDI stands for Single Document Interface. An SDI application typically works with one document at a time within its main frame window.
30. What does MDI stand for?
- Multiple Document Interface
- Managed Document Interface
- Multiple Data Integration
- Microsoft Document Interface
Answer: A) Multiple Document Interface
Explanation:
MDI stands for Multiple Document Interface. An MDI application can manage multiple document windows within a main frame window.
31. Which MFC class provides support for a scrolling view?
CScrollView
CScrollableWnd
CScrollWnd
CViewScroll
Answer: A) CScrollView
Explanation:
CScrollView is derived from CView and provides support for scrolling within a view.
32. Which MFC class is useful for a view based on a dialog-template resource?
CFormView
CDialogView
CFormDialog
CViewForm
Answer: A) CFormView
Explanation:
CFormView provides a form-based view whose controls can be laid out using a dialog-template resource.
33. Which mechanism does MFC use to associate Windows messages and commands with class member functions?
- Message maps
- Virtual tables only
- Resource maps
- Command arrays
Answer: A) Message maps
Explanation:
MFC uses message maps to connect Windows messages and command identifiers with member functions that handle them.
34. Which macro begins the message map declaration for an MFC class?
BEGIN_MESSAGE_MAP
START_MESSAGE_MAP
DECLARE_MESSAGE_MAP
BEGIN_MFC_MAP
Answer: A) BEGIN_MESSAGE_MAP
Explanation:
BEGIN_MESSAGE_MAP starts the implementation of a message map. It is normally paired with END_MESSAGE_MAP.
35. Which macro is commonly placed in the class declaration to declare that a class has a message map?
DECLARE_MESSAGE_MAP
DEFINE_MESSAGE_MAP
MESSAGE_MAP_DECLARE
DECLARE_MFC_MAP
Answer: A) DECLARE_MESSAGE_MAP
Explanation:
DECLARE_MESSAGE_MAP is placed in an MFC class declaration when the class uses a message map.
36. Which macro is used to map a command message to a member function?
ON_COMMAND
ON_MESSAGE_COMMAND
MAP_COMMAND
COMMAND_HANDLER
Answer: A) ON_COMMAND
Explanation:
ON_COMMAND maps a command identifier to a member function in an MFC message map.
37. Which message-map macro is commonly used to handle a button click notification?
ON_BN_CLICKED
ON_BUTTON_CLICK
ON_CLICK_BUTTON
ON_CONTROL_CLICK
Answer: A) ON_BN_CLICKED
Explanation:
ON_BN_CLICKED maps the button's BN_CLICKED notification to a handler function.
38. Which MFC function is commonly overridden to draw the contents of a view?
OnDraw
DrawView
RenderView
PaintDocument
Answer: A) OnDraw
Explanation:
OnDraw is a member function of CView and is commonly overridden to render document data in the view.
39. Which MFC class is commonly used to represent a toolbar?
CToolBar
CBar
CToolWindow
CButtonBar
Answer: A) CToolBar
Explanation:
CToolBar provides functionality for creating and managing toolbar controls in an MFC application.
40. Which MFC class is commonly used to represent a status bar?
CStatusBar
CStatusWindow
CInfoBar
CStatusControl
Answer: A) CStatusBar
Explanation:
CStatusBar provides functionality for creating and managing status bars in MFC frame windows.
41. Which MFC class can be used to create and manipulate a list box control?
CListBox
CListControl
CListWindow
CItemsBox
Answer: A) CListBox
Explanation:
CListBox encapsulates the functionality of a Windows list-box control.
42. Which MFC class encapsulates an edit control?
CEdit
CTextBox
CInput
CEditBox
Answer: A) CEdit
Explanation:
CEdit provides the MFC wrapper for a Windows edit control and supports operations such as setting and retrieving text.
43. Which MFC class encapsulates a button control?
CButton
CButtonControl
CCommandButton
CBtn
Answer: A) CButton
Explanation:
CButton encapsulates a Windows button control and supports operations such as setting button states and handling notifications.
44. Which MFC class is used to access a dialog control through a control ID?
CWnd
CDialog
CView
CDocument
Answer: B) CDialog
Explanation:
An MFC dialog class derived from CDialog can access its child controls using functions such as GetDlgItem or control-member mechanisms such as DDX.
45. What does DDX primarily provide in MFC dialog programming?
- Data exchange between controls and member variables
- Database encryption
- Document indexing
- DirectX rendering
Answer: A) Data exchange between controls and member variables
Explanation:
DDX, or Dialog Data Exchange, transfers data between dialog controls and corresponding member variables of a dialog class.
46. What is the purpose of MFC resources such as dialog, menu, icon, and bitmap resources?
- They define application interface and other compiled resources
- They replace all C++ classes
- They execute application threads
- They store CPU instructions
Answer: A) They define application interface and other compiled resources
Explanation:
MFC applications commonly use Windows resources for elements such as dialogs, menus, icons, cursors, strings, and bitmaps. These resources can be edited using Visual Studio resource tools.
47. Which MFC macro is associated with runtime class information and dynamic object creation for appropriate classes?
DECLARE_DYNCREATE
DECLARE_RUNTIME
ENABLE_RUNTIME
CREATE_RUNTIME_CLASS
Answer: A) DECLARE_DYNCREATE
Explanation:
DECLARE_DYNCREATE is used in a class declaration when MFC runtime class information and dynamic object creation support are required. It is commonly paired with IMPLEMENT_DYNCREATE.
48. Which MFC class represents a thread of execution?
CWinThread
CThreadObject
CExecutionThread
CAppThread
Answer: A) CWinThread
Explanation:
CWinThread represents a thread of execution in MFC. CWinApp itself is derived from CWinThread.
49. Which MFC class can be used to display a simple message box?
CMessageBox
AfxMessageBox
CDialogMessage
CAlertBox
Answer: B) AfxMessageBox
Explanation:
AfxMessageBox is an MFC global function used to display a message box. It is a function rather than an MFC class.
50. Consider the following MFC view implementation. What is the purpose of the code?
void CMyView::OnDraw(CDC* pDC)
{
pDC->TextOut(50, 50, _T("Hello MFC"));
}
- It creates a new document
- It displays "Hello MFC" in the view at the specified coordinates
- It creates a dialog box
- It terminates the application
Answer: B) It displays "Hello MFC" in the view at the specified coordinates
Explanation:
OnDraw is used to render content in an MFC view. The CDC pointer provides access to the device context, and TextOut draws the specified text at the given coordinates. Therefore, this code displays Hello MFC at position (50, 50) in the view.
Advertisement
Advertisement