Wednesday, 3 August 2011

MFC Interview Questions & Answers - 1


Q:- What is model and modeless dialog box ? Give some examples?
Ans:- When we create Modal Dialog Box we can't move to other windows until this dialog is closed. For eg: MessageBox, where we can't move to the other window until we press ok or cancel. 
When we create Modeless Dilaog Box we can swap to the other windows. For eg: like a conventional window.


Q:- How to create open & save dialogs ?
Ans:- In CommonDialogs class we have to use CFileDialog class where the first parameter TRUE for open dialog and FALSE for Save dialog.
For file open:
CFileDialog SampleDlg(TRUE,NULL,NULL,OFN_OVERWRITEPROMPT,"Text Files (*.txt)|*.txt|Comma Separated Values(*.csv)|*.csv||");


int iRet = SampleDlg.DoModal();


Q:- What is CSingleDocTemplate?
Ans:- It’s a document template class used to create single document interface SDI applications. Only one document can be opened at a time. It identifies the document class used to manage the application's data, the frame window class that encloses views of that data, and the view class used to draw visual representations of the data. The document template also stores a resource ID that the framework uses to load menus, accelerators, and other resources that shape the application's user interface.



Q:- What is the difference between hinstance and hprevinstance in WinMain function?
Ans:- hInstance is used for things like loading resources and any other task which is performed on a per-module basis. A module is either the EXE or a DLL loaded into your program. hPrevInstance used to be the handle to the previously run instance of your program (if any) in Win16. It is always NULL for Win32 programs.


Q:- Explain about MDI and CMultiDocTemplate ?
Ans:- MDI applications are designed using the doc-view architectures in which there could be many views associated with a single document object and an application can open multiple docuements at the same time for eg:WORD.
In MDI terms, your main window is called the Frame, this is probably the only window you would have in a SDI (Single Document Interface) program. In MDI there is an additional window, called the MDI Client Window which is a child of your Frame window. CMultiDocTemplate is the document template class used to create MDI applications..The document template also stores a resource ID that the framework uses to load menus, accelerators, and other resources that shape the application's user interface.


Q:- Which are the different controls in MFC ?
Ans:- CAnimateCtrl, CButton, CEdit, CListBox, CComboBox, CRichEditCtrl, CStatic, TreeCtrl, ToolTipCtrl, IPAddressCtrl, TabCtrl,CDa teTimeCtrl, HeaderCtrl, ListCtrl, MonthCalCtrl, OleCtrl, ProgressCtrl, ScrollBar, SliderCtrl, StatusBarCtrl, TollBarCtrl etc.,


Q:- What is the use of OnInitDialog ?
Ans:- This message is sent to the dialog box during the Create, CreateIndirect, or DoModal calls, which occur immediately before the dialog box is displayed. This can be used to intialize the dialog controls or show/hide the controls etc.,


Q:- What is the functioning of UpdateData() funciton ?
Ans:- This is to initialize data in a dialog box, or to retrieve and validate dialog data.
The framework automatically calls UpdateData with bSaveAndValidate set to FALSE when a modal dialog box is created in the default implementation of CDialog::OnInitDialog. The call occurs before the dialog box is visible. The default implementation of CDialog::OnOK calls this member function with bSaveAndValidate set to TRUE to retrieve the data, and if successful, will close the dialog box. If the Cancel button is clicked in the dialog box, the dialog box is closed without the data being retrieved.


Q:- How to update all the views whenever document got updated ?
Ans:- call UpdateAllViews()- which updates all views associated with the document by calling OnUpdate() function of all the views.


Q:- How to handle RTTI in MFC ?
Ans:- Run-Time Type Information is a mechanism that allows the type of an object to be determined during the program execution. 3 main elements to RTTI in MFC are
1. Dynamic_cast operator Used for conversion of polymorphic types.
2. typeid - used for identifying the exact type of an object 
3. type_info classused to hold the type information returned by typeid.


Q:- What is serialization ?which function is responsible for serializing data ?
Ans:- 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.


Q:- what is the use of Mutex and critical section ?
Ans:- Mutex as the name suggest allows a mutullay exclusive access to a shared resource among the threads. Critical section is a piece of code that can be executed safely to be accessed by two or more threads. Criticalsection provides synchronization means for one process only, while mutexes allow data synchronization across processes. Means two or more threads can share the common resources among more than one application or process boundaries in mutex.

0 comments:

Post a Comment

Popular Posts

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