MFC Interview Questions & Answers
Table of Contents
General Questions
-
What are MFC & VC++ Version Numbers?
MFC version Visual C++ version 1.0 Microsoft C/C++ 7.0 2.0 Visual C++ 1.0 2.5 Visual C++ 1.5 3.0 Visual C++ 2.0 3.1 Visual C++ 2.1 3.2 Visual C++ 2.2 4.0 Visual C++ 4.0 4.1 Visual C++ 4.1 4.2 Visual C++ 4.2 4.21 (mfc42.dll) Visual C++ 5.0 6.0 (mfc42.dll) Visual C++ 6.0 7.0 (mfc70.dll) Visual C++ .NET 2002 7.1 (mfc71.dll) Visual C++ .NET 2003 8.0 (mfc80.dll) Visual C++ 2005 -
What is a message map, and what is the purpose of message map instead of virtual function?
Message Map is a logical table that maps the windows messages to the member functions of the class. Message map is to avoid following drawbacks:
-
Most windows only process a small number of messages, yet each window require to giant virtual function table with the entries of each message.
-
more efficient and use less space then virtual functions
-
Virtual functions don't handle user defined messages and other custom cases.
-
-
Explain about PostMessage/SendMessage?
PostMessage
Places (posts) a message in the message queue associated with the thread that created the specified window and returns without waiting for the thread to process the message. To post a message in the message queue associated with a thread, use the PostThreadMessage function. Syntax
BOOL WINAPI PostMessage(
__in_opt HWND hWnd,
__in UINT Msg,
__in WPARAM wParam,
__in LPARAM lParam
);SendMessage
Sends the specified message to a window or windows. The SendMessage function calls the window procedure for the specified window and does not return until the window procedure has processed the message. To send a message and return immediately, use the SendMessageCallback or SendNotifyMessage function. To post a message to a thread's message queue and return immediately, use the PostMessage or PostThreadMessage function. Syntax
LRESULT WINAPI SendMessage(
__in HWND hWnd,
__in UINT Msg,
__in WPARAM wParam,
__in LPARAM lParam
); -
Message Map vs Virtual Functions?
Message Map is a logical table that maps the windows messages to the member functions of the class. Message map is to avoid following drawbacks:
-
Most windows only process a small number of messages, yet each window require to giant virtual function table with the entries of each message.
-
more efficient and use less space then virtual functions.
-
Virtual functions don't handle user defined messages and other custom cases.
-
-
What are the classes created involved when a Dialog based application is created?
Document View Architecture
-
What is Document View Architecture?
-
What is SDI?
-
What is MDI?
-
How to convert SDI Application to MDI Application?
-
Can you explaining the relationship between document, frame and view ?
The frame window is the application's top-level window. It's normally a WS_OVERLAPPEDWINDOW-style window with a resizing border, a title bar, a system menu, and minimize, maximize, and close buttons. The view is a child window sized to fit the frame window so that it becomes the frame window's client area. The application's data is stored in the document object, a visible representation of which appears in the view. For an SDI application, the frame window class is derived from CFrameWnd, the document class is derived from CDocument, and the view class is derived from CView or a related class such as CScrollView.
-
What is CSingleDocTemplate and CMultiDocTemplate?
-
How to access document object from view ?
Using GetDocument() function within a CView class. ###
-
What are the advantages of using Doc/View or SDI over DialogBox ?
-
If I modified data in 1 view how does the other view knows ?
-
Explain about Command Routing in SDI/MDI?
-
How to Add a View to Document?
-
How can you update all the views present?
-
In UpdateAllViews what for the 2nd and 3rd parameters used?
CDocument::UpdateAllViews Call this function after the document has been modified. void UpdateAllViews(CViewpSender, LPARAM lHint = 0L, CObject pHint = NULL);
Parameters
pSender - Points to the view that modified the document, or NULL if all views are to be updated. lHint - Contains information about the modification. pHint - Points to an object storing information about the modification.
You should call this function after you call the SetModifiedFlag member function. This function informs each view attached to the document, except for the view specified by pSender, that the document has been modified. You typically call this function from your view class after the user has changed the document through a view. This function calls the CView::OnUpdate member function for each of the document's views except the sending view, passing pHint and lHint.
-
How to update all the views whenever document got updated ?
Call UpdateAllViews()- which updates all views associated with the document by calling OnUpdate() function of all the views.
-
What is Serialization and Deserialization?
Searialization is the process of streaming the object data to or from a persistent storage medium. It's useful in Doc-View Architecture. CObject :: Serialize() function is used to do serialization.
-
Explain the process of Serialization?
-
What is OnInitialUpdate and where is it called and what happens?
CView::OnInitialUpdate Called by the framework after the view is first attached to the document, but before the view is initially displayed. ###
virtual void OnInitialUpdate( ); The default implementation of this function calls the OnUpdate member function with no hint information (that is, using the default values of 0 for the lHint parameter and NULL for the pHint parameter).
CView::OnUpdate Called by the framework after the view's document has been modified; this function is called by CDocument::UpdateAllViews and allows the view to update its display to reflect those modifications. ### virtual void OnUpdate(CViewpSender, LPARAM lHint, CObject pHint );