MFC interview questions

Discussion in 'MFC' started by coderzone, Apr 14, 2006.

  1. rajeswaridvssnr

    rajeswaridvssnr New Member

    Joined:
    Oct 24, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    Hyderabad
    Explain the flow for a simple win32 based application ?

    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.
     
  2. rajeswaridvssnr

    rajeswaridvssnr New Member

    Joined:
    Oct 24, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    Hyderabad
    What is model and modeless dialog box ? Give some examples?

    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.
     
  3. rajeswaridvssnr

    rajeswaridvssnr New Member

    Joined:
    Oct 24, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    Hyderabad
    How to create open & save dialogs ?

    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();
     
  4. rajeswaridvssnr

    rajeswaridvssnr New Member

    Joined:
    Oct 24, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    Hyderabad
    What is CSingleDocTemplate?

    What is CSingleDocTemplate?

    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.
     
  5. rajeswaridvssnr

    rajeswaridvssnr New Member

    Joined:
    Oct 24, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    Hyderabad
    What is the difference between hinstance and hprevinstance in WinMain function?

    What is the difference between hinstance and hprevinstance in WinMain function?

    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.
     
  6. rajeswaridvssnr

    rajeswaridvssnr New Member

    Joined:
    Oct 24, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    Hyderabad
    Explain about MDI and CMultiDocTemplate ?

    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.
     
    Last edited: Oct 30, 2006
  7. rajeswaridvssnr

    rajeswaridvssnr New Member

    Joined:
    Oct 24, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    Hyderabad
    Tell me the different controls in MFC ?

    CAnimateCtrl,CButton,CEdit,CListBox,CComboBox,CRichEditCtrl,CStatic, CTreeCtrl,CToolTipCtrl,CIPAddressCtrl,CTabCtrl,CDateTimeCtrl,CHeaderCtrl,CListCtrl,CMonthCalCtrl,COleCtrl,CProgressCtrl,CScrollBar,CSliderCtrl,CStatusBarCtrl,CTollBarCtrl etc.,
     
    Last edited: Oct 30, 2006
  8. rajeswaridvssnr

    rajeswaridvssnr New Member

    Joined:
    Oct 24, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    Hyderabad
    What is the use of OnInitDialog ?

    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.,
     
    Last edited: Oct 30, 2006
  9. rajeswaridvssnr

    rajeswaridvssnr New Member

    Joined:
    Oct 24, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    Hyderabad
    What is the functioning of UpdateData() funciton ?

    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.
     
  10. rajeswaridvssnr

    rajeswaridvssnr New Member

    Joined:
    Oct 24, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    Hyderabad
    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.
     
  11. rajeswaridvssnr

    rajeswaridvssnr New Member

    Joined:
    Oct 24, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    Hyderabad
    How to handle RTTI in MFC ?

    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 class
    used to hold the type information returned by typeid.
     
  12. rajeswaridvssnr

    rajeswaridvssnr New Member

    Joined:
    Oct 24, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    Hyderabad
    What is serialization ?which function is responsible for serializing data ?

    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.
     
  13. rajeswaridvssnr

    rajeswaridvssnr New Member

    Joined:
    Oct 24, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    Hyderabad
    Explain about different kinds of threads in MFC?

    2 types of thread in MFc are UserInterface thread and worker thread. UserInterface threads maintain the message loops and used to handles user input,creates windows and process messges sent to those windows.Worker thread don't use message loops and mainly used to perform background operations such as printing etc.,Created using AfxBeginThread bypassing ThreadFunction to create worker thread and Runtime class object to create a user interface thread.
     
  14. rajeswaridvssnr

    rajeswaridvssnr New Member

    Joined:
    Oct 24, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    Hyderabad
    what is the use of Mutex and critical section ?

    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.
     
  15. rajeswaridvssnr

    rajeswaridvssnr New Member

    Joined:
    Oct 24, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    Hyderabad
    What is socket?

    A "socket" is an endpoint of communication: an object through which your application communicates with other Windows Sockets applications across a network.The two MFC Windows Sockets programming models are supported by the following classes: CAsyncSocket and CSocket
     
  16. rajeswaridvssnr

    rajeswaridvssnr New Member

    Joined:
    Oct 24, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    Hyderabad
    What is the difference between Synchronous sockets and asynchronous sockets?

    Consider a server application that is listening on a specific port to get data from clients. In synchronous receiving, while the server is waiting to receive data from a client, if the stream is empty the main thread will block until the request for data is satisfied. Hence, the server cannot do anything else until it receives data from the client. If another client attempts to connect to the server at that time, the server cannot process that request because it is blocked on the first client. This behavior is not acceptable for a real-world application where we need to support multiple clients at the same time.

    In asynchronous communication, while the server is listening or receiving data from a client, it can still process connection requests from other clients as well as receive data from those clients. When a server is receiving asynchronously, a separate thread (at the OS level) listens on the socket and will invoke a callback function when a socket event occurs. This callback function in turn will respond and process that socket event.
     
  17. rajeswaridvssnr

    rajeswaridvssnr New Member

    Joined:
    Oct 24, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    Hyderabad
    Have you ever used win32 APIs ?

    MFC is a wrapper around win32 API, It provides classes which uses the win32 API, Some of the API's we usually work with are : GetDlgItemInt,GetDlgItemText,GetWindowTextA,MessageBoxA,CreateFile,CreateMutex,CreateEvent,WaitForSingleObject,CreateWindow,ShowWindow etc.,
     
  18. rajeswaridvssnr

    rajeswaridvssnr New Member

    Joined:
    Oct 24, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    Hyderabad
    What is the difference between ANSI Code and UNICODE ?

    ANSI code represents 8bytes data where UNICODE represents 16bytes data for supporting universal languages. One major draw back to ASCII was you could only have 256 different characters. However, languages such as Japanese and Arabic have thousands of characters. Thus ASCII would not work in these situations. The result was Unicode which allowed for up to 65,536 different characters
     
  19. rajeswaridvssnr

    rajeswaridvssnr New Member

    Joined:
    Oct 24, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    Hyderabad
    What is the difference between regular dlls and extended dlls?

    Regular dlls wraps only the c/c++ functions. Where extention dlls include c++ interfaces where we can create the objects of it and use in our classes. Extended dlls support object oriented concepts.Regural dlls uses mfc internally and exported functions can be used by any mfc or non-mfc applications.Extention dlls implements reusable classes derived from mfc library,built using dll version of mfc.Only mfc executables(applications/dll-shared version of mfc) can use extention dlls.extention dlls used for passing mfc derived objects b/w applications and dlls. Regulardlls linked both statically and dynamically but extended dlls links dynamically.
     
  20. rajeswaridvssnr

    rajeswaridvssnr New Member

    Joined:
    Oct 24, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    Hyderabad
    What is a message map, and what is the advantage of a message map over virtual functi

    MessageMap is a logical table that maps the windows messages to the member functions of the class. We use message maps over virtual function because of lots of overhead. If every windows message had a virtual function associated with it , there would be several hundred bytes per window class of vtable. Message maps means we only pay for the messages we use.
     
    Last edited: Nov 1, 2006

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice