Wednesday 3 August 2011

MFC Interview Questions & Answers - 2

Q:- What is thread & process?
Ans:- Threads are similar to processes, but differ in the way that they share resources. Threads are distinguished from processes in that processes are typically independent, carry considerable state information and have separate address spaces. Threads typically share the memory belonging to their parent process.


Q:- what is the use of AFX_MANAGE_STATE ?
Ans:- By default, MFC uses the resource handle of the main application to load the resource template. If you have an exported function in a DLL, such as one that launches a dialog box in the DLL, this template is actually stored in the DLL module. You need to switch the module state for the correct handle to be used. You can do this by adding the following code to the beginning of the function:


AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
This swaps the current module state with the state returned from AfxGetStaticModuleState until the end of the current scope. If all your resources lies in the single DLL you can even change the default handle to the DLL handle with the help of AfxSetResourceHandle function.


Q:- Why wizards generate enum IDD for dialogs?
Ans:- It's good programming practice to do it this way, as from the client code you can always refer to the CMyDlg::IDD without worrying what the actual constant is.



Q:- What is CArchive class does?
Ans:- The CArchive class allows you to save a complex network of objects in a permanent binary form (usually disk storage) that persists after those objects are deleted. Later you can load the objects from persistent storage, reconstituting them in memory. This process of making data persistent is called “serialization.”


Q:- How to handle command line arguements from simple MFC application ?
Ans:- m_lpCmdLine Corresponds to the lpCmdLine parameter passed by Windows to WinMain. Points to a null-terminated string that specifies the command line for the application. Use m_lpCmdLine to access any command-line arguments the user entered when the application was started. m_lpCmdLine is a public variable of type LPTSTR.
BOOL CMyApp::InitInstance()
{
// ...
if (m_lpCmdLine[0] == _T('\0'))
{
// Create a new (empty) document.
OnFileNew();
}
else
{
// Open a file passed as the first command line parameter.
OpenDocumentFile(m_lpCmdLine);
}
// ...
}


Q:- What is the base class for MFC Framework ?
Ans:-CObject


Q:- If I derive a new class from CObject what are the basic features my derived will get?
Ans:-Searialization, Debugging support, Runtime time class information, compatibility with collection classes.


Q:- What is the use of CCmdTarget ?
Ans:- It is the base class for the MFC library message map architecture.Which maps commands/messages to the member functions to handle them. Classes derived from this are CWnd,CWinApp,CFrameWnd,CView, CDocument


Q:- What is document-view architecture ? Give me one real time example for SDI ?
Ans:- Document/view architecture, which defines a program structure that relies on document objects to hold an application's data and on view objects to render views of that data. MFC provides the infrastructure for documents and views in the classes CDocument and CView. example of SDI is a wordpad application


Q:- Can you explain the relashionship between document,frame and view ?
Ans:- 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.


Q:- How to access document object from view ?
Ans:- Using GetDocument() function within a CView class.


Q:- What is the entry point for window based applications ?
Ans:- WinMain() is the entry point for window based applications.


Q:- Explain the flow for a simple win32 based application ?
Ans:- Starting point for win32 based applications is WinMain()
WinMain begins by calling the API function RegisterClass to register a window class. The window class(WNDCLASS) defines important characteristics of a window such as its window procedure address, its default background color, and its icon. Once the WNDCLASS is registered, WinMain calls the all-important CreateWindow function to create the application's window. WinMain follows CreateWindow with calls to ShowWindow and UpdateWindow, which make the window visible and ensure that its WM_PAINT handler is called immediately. Next comes the message loop. In order to retrieve and dispatch messages, WinMain executes a simple while loop that calls the GetMessage, TranslateMessage, and DispatchMessage API functions repeatedly. GetMessage checks the message queue. If a message is available, it is removed from the queue and copied to msg; TranslateMessage converts a keyboard message denoting a character key to an easier-to-use WM_CHAR message, and DispatchMessage dispatches the message to the window procedure. The message loop executes until GetMessage returns 0, which happens only when a WM_QUIT message is retrieved from the message queue. When this occurs, WinMain ends and the program terminates.

0 comments:

Post a Comment

Popular Posts

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | cheap international calls