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.
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.
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.
Tell me the different controls in MFC ?
CAnimateCtrl,CButton,CEdit,CListBox,CComboBox,CRic hEditCtrl,CStatic, CTreeCtrl,CToolTipCtrl,CIPAddressCtrl,CTabCtrl,CDa teTimeCtrl,CHeaderCtrl,CListCtrl,CMonthCalCtrl,COl eCtrl,CProgressCtrl,CScrollBar,CSliderCtrl,CStatus BarCtrl,CTollBarCtrl etc.,
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.,
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.
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.
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
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.
What is a message map, and what is the advantage of a message map over virtual function?
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.
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.
Given two processes, how can they share memory?
Processes and thread are very similar but they differ in the way they share their resources. Processes are independent and have its own address space. If two independent processes want to communicate they do this by using the following techniques 1.Message Passing 2.Sockets 3. named pipes
How to restrict only one instance of a class object to be created?
Create a Named Mutex.
HANDLE hMutex=CreateMutex(TRUE,_T(“NamedMutex”))
How do I dynamically change the mainframe menu?
CMenu newMenu;
newMenu.LoadMenu (IDR_MENU1);
AfxGetMainWnd()->SetMenu( &newMenu );
AfxGetMainWnd()->DrawMenuBar();
newMenu.Detach ();
What is serialization? Which function is responsible for serializing data ?
Serialization is the process of converting an object into sequence of bits so that it can be stored and retrieved from storage medium e.g. file. Serialize () is responsible for serialization of data
Welcome to the world of e Gyan.This is an attempt to put together and share the vast and vivid knowledge.The focus will be on sharing of our knowledge on- Latest tools and techniques.etc.So, go ahead and share the Gyan.
Showing posts with label MFC FAQ. Show all posts
Showing posts with label MFC FAQ. Show all posts
Thursday, February 17, 2011
MFC FAQ
What is the difference between GetMessage and PeekMessage ?
GetMessage function waits for a message to be placed in the queue before returning where as PeekMessage function does not wait for a message to be placed in the queue before returning.
What’s the difference between PostMessage and SendMessage?
The PostMessage function places (posts) a message in the message queue associated with the thread that created the specified window and then returns without waiting for the thread to process the message.
The SendMessage function sends the specified message to a window or windows. The function calls the window procedure for the specified window and does not return until the window procedure has processed the message.
Name the Synchronization objects ?
Following are the synchronization objects
1) Critical Section
2) Event
3) Mutex
4) Semaphore
Classes provided for above synchronization objects are:
1) CCriticalSection
2) CEvent
3) CMutex
4) CSemaphore
What is the difference between ASSERT and VERIFY?
The main difference between ASSERT and VERIFY is when you compile the release build of the program.
ASSERT will not be present in the release build version of the executables/dlls, and its expression that would have been evaluated will be deleted.
VERIFY will be present in the release build version of the executables/dlls but its expression that would have been evaluated will be left intact.
What is thread & process?
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.
what is the use of AFX_MANAGE_STATE ?
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.
Why wizards generate enum IDD for dialogs?
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.
What is the base class for MFC Framework ?
CObject
What is the use of CCmdTarget ?
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 .
What is document-view architecture ? Give me one real time example for SDI ?
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
Can you explain the relashionship 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.
How to access document object from view ?
Using GetDocument() function within a CView class.
What is the entry point for window based applications ?
WinMain() is the entry point for window based applications.
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.
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();
GetMessage function waits for a message to be placed in the queue before returning where as PeekMessage function does not wait for a message to be placed in the queue before returning.
What’s the difference between PostMessage and SendMessage?
The PostMessage function places (posts) a message in the message queue associated with the thread that created the specified window and then returns without waiting for the thread to process the message.
The SendMessage function sends the specified message to a window or windows. The function calls the window procedure for the specified window and does not return until the window procedure has processed the message.
Name the Synchronization objects ?
Following are the synchronization objects
1) Critical Section
2) Event
3) Mutex
4) Semaphore
Classes provided for above synchronization objects are:
1) CCriticalSection
2) CEvent
3) CMutex
4) CSemaphore
What is the difference between ASSERT and VERIFY?
The main difference between ASSERT and VERIFY is when you compile the release build of the program.
ASSERT will not be present in the release build version of the executables/dlls, and its expression that would have been evaluated will be deleted.
VERIFY will be present in the release build version of the executables/dlls but its expression that would have been evaluated will be left intact.
What is thread & process?
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.
what is the use of AFX_MANAGE_STATE ?
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.
Why wizards generate enum IDD for dialogs?
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.
What is the base class for MFC Framework ?
CObject
What is the use of CCmdTarget ?
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 .
What is document-view architecture ? Give me one real time example for SDI ?
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
Can you explain the relashionship 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.
How to access document object from view ?
Using GetDocument() function within a CView class.
What is the entry point for window based applications ?
WinMain() is the entry point for window based applications.
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.
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();
Subscribe to:
Posts (Atom)