MFC Interview Questions And Answers

Download MFC Interview Questions and Answers PDF

Enhance your MFC interview preparation with our set of 26 carefully chosen questions. Our questions cover a wide range of topics in MFC to ensure you're well-prepared. Whether you're new to the field or have years of experience, these questions are designed to help you succeed. Don't miss out on our free PDF download, containing all 26 questions to help you succeed in your MFC interview. It's an invaluable tool for reinforcing your knowledge and building confidence.

26 MFC Questions and Answers:

MFC Job Interview Questions Table of Contents:

MFC Job Interview Questions and Answers
MFC Job Interview Questions and Answers

1 :: Will there be any difference in the image buffer size if it is loaded in from CString to LPTSTR using GetBuffer()? lptstr = string.GetBuffer(0);

No there wont be any difference. Infact the first method is
preffered
Read More

2 :: How to update windows title bar dynamically?

using SetWindowText()function we can change text of
specified window dynamically
Read More

3 :: What is CTargetObject?

In general, TargetObject is the object where you will get
the sorted result.

If you want to specific answer please update the context
and details of question like Grid or Array
Read More

4 :: How to find the mouse entering an image and while entering need to display next image?

BY USING THE TOOL TIP PROPERTY WE CAN KNOW THE WHERE THE
MOUSE POINT IS LOCATED NOW.
Read More

5 :: How we call a dialog in another dialog?

Using DoModal() function.
create a class of another dialog box.
and write a code in fist dialog box function.

Classname(second) variable_name;
variable_name.DoModl();

and define the new header file in fisrt dialog bob code.
like;
#include "classname.h"
Read More

6 :: List out the parameters of WinMain Function?

int CALLBACK WinMain(
__in HINSTANCE hInstance,
__in HINSTANCE hPrevInstance,
__in LPSTR lpCmdLine,
__in int nCmdShow
);
Read More

7 :: How to create a button dynamically?

1. Create a Object from CButton control. CButton m_ctlButton
2. m_ctlButton.Create("OK",ES_CHILD|ES_VISIBLE,CRect(0,0,100,100),CWnd*
pParentWnd,MB_OK);

with this we can create the button by dynamically.
Read More

8 :: What is a message map?

Message map is dynamic function locater
It can look each function if it defined

e.g

void OnWndMessage(UINT message, WPARAM wParam, LPARAM
lParam, LRESULT *pResult)

{
// function looking MESSAGE_MAPS ((DECLARED))
// if found, CWnd::OnSize(UINT nStyle, int cx, int cy);
__thisclass.OnSize(wParam, HIWORD(lParam), LOWORD(lParam);
}
//M
Read More

9 :: List out the basic features of MFC?

new container
polymorphic wrapping
expression passing
Smart Pointer

1.Application Framework: The MFC library framework includes its own application structure-one that has been proved in many software environments.App wizard generates skeleton code for your entire application, and class wizard generates prototypes and function bodies for message handlers.
2.Message Mapping
3.Runtime class information
4.Serialization
Read More

10 :: How to give color for dialog button or static buuto?

Brush *brush;
Initialize the brush pointer in the constructor of your Dialog
Code:
brush = new CBrush(RGB(49,49,49));
Add the WM_CTLCOLR Message handler for the dialog and add the following code
Code:
switch (nCtlColor) {

case CTLCOLOR_BTN:
pDC->SetTextColor(RGB(0, 255, 0));
pDC->SetBkColor(RGB(0, 0, 0));
return (HBRUSH)(brush->GetSafeHandle());
default:
return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
}
Read More

11 :: Which Macro is a Super set of other two macro DECLARE_SERIAL, DECLARE_DYNAMIC and DECLARE_DYNCREATE?

DECLARE_SERIAL is super set for other 2 macros since The
DECLARE_SERIAL macro includes all the functionality of
DECLARE_DYNAMIC and DECLARE_DYNCREATE.
Read More

12 :: Visual Programming c++ coding for create a paint application?

class myframe:public CFrameWnd
{
public:
myframe()
{
Create(NULL,"My Paint application");
}
void OnPaint()
{
CPaintDC d(this);
CBrush mybrush(RGB(0,255,0));
d.SelectObject(&mybrush);
d.Rectangle(50,150,150,50);
}
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(myframe,CFrameWnd)
ON_WM_PAINT()
END_MESSAGE_MAP()
class myapp:public CWinApp
{
public:
int InitInstance()
{
myframe *p=new myframe;
p->ShowWindow(1);
m_pMainWnd=p;
return 1;
}
};
myapp a;
Read More

13 :: What is the use of CCmdTarget?

CCmdTarget class used to process window message, any class directly or indirectly inherited from CCmdTarget will eligible for message handling..
Read More

14 :: General purpose classes in MFC?

CString, CSize, CPOint..
Read More

15 :: What is primitive and non-primitive application?

primitive & non-primitive type are difference thing,primitive is the well defined data,we can't modified this type of data,but in non-primtive type as a user defined of data which store reference or object data,bcz they are created rather then per-defind
Read More

16 :: What is the base class for MFC?

CObject is the base class for all the MFC classes.
Read More

17 :: How you find memory leaks?

There many ways to find memory leaks, One of the ways is by
using MFC class. And another way is using Purify tools...

CMemorState is a MFC class by which we can find the memory
leaks. Below is a sample code to find the same.

#ifdef _DEBUG
CMemoryState oldState, newState, diffState;
oldState.Checkpoint();
#endif
int* a = new int[10];
#ifdef _DEBUG
newState.Checkpoint();
if(diffState.Difference(oldState, newState))
{
TRACE0("Memory Leaked");
}
#endif
Read More

18 :: If application hangs while SendMessage is waiting for the result, how you handle it?

Instead of SendMessage API i will use the SendMessageTimeout
API to solve the system hang or You can use PostMessage API instead.
Read More

19 :: How can update edit control data of an executing application from other application?

First, need to find the handle of the Control by using some API like EnumWindows and enumerrating all windows and checking for the text of the window by GetWindowTExt.
Once, handle of the target control has been identified, SendMessage can be used to send appropriate message to the control. like WM_SETTEXT can be sent to change text of window, etc...
Read More

20 :: What is stack size in win32 program?

1mb
Read More

21 :: what is the use of CWinApp class?

CWinApp is an application object provides member functions
for initializing your application (and each instance of it)
and for running the application.

Each application that uses the Microsoft Foundation classes
can only contain one object derived from CWinApp. This
object is constructed when other C++ global objects are
constructed and is already available when Windows calls the
WinMain function, which is supplied by the Microsoft
Foundation Class Library. Declare your derived CWinApp
object at the global level.

When you derive an application class from CWinApp, override
the InitInstance member function to create your
application's main window object.

In addition to the CWinApp member functions, the Microsoft
Foundation Class Library provides the following global
functions to access your CWinApp object and other global
information:

► AfxGetApp Obtains a pointer to the CWinApp object.

► AfxGetInstanceHandle Obtains a handle to the current
application instance.

► AfxGetResourceHandle Obtains a handle to the
application's resources.

► AfxGetAppName Obtains a pointer to a string containing
the application's name. Alternately, if you have a pointer
to the CWinApp object, use m_pszExeName to get the
application's name.
Read More

22 :: What is model and modeless dialog box? Give some examples?

Modal dialog is one which will not allow u to access any thing until this dialog is active.

Call:
Dialog::DoModal()

And reverse of this ur modeless dialog.
Dialog::ShowDialog();

For Example:
Modal Dialog:
When we access Menu items such as Save as, Open, attach file, in any application, we can not able to access any part of the application execpt the active dialog.

When we open add remove program for uninstalling any application, u will get a Uninstallation dialog which will be modeles. bcz still u were able to access add remove programs. (this is probably in Vista. And in XP its modal dialog which they have used)
Read More

23 :: What is the base class for MFC Framework?

CObject class
Read More

24 :: What is the flow of SDI application?

CwinApp -> CDocument -> CFrameWnd -> CView
Read More

25 :: What is synchronization objects types and where we are using in the code?

CRITICAL_SECTION :- CRITICAL_SECTION (CS) objects are initialized and deleted but do not have handles and are not shared by other processes. A variable should be declared to be of type CRITICAL_SECTION. Threads enter and leave a CS, and only one thread at a time can be in a specific CS. EnterCriticalSection blocks a thread if another thread is in the section. The waiting thread unblocks when another thread executes LeaveCriticalSection. If a thread already owns the CS, it can enter again without blocking; that is, CRITICAL_SECTIONs are recursive. CRITICAL_SECTIONs have the advantage of not being kernel objects and are maintained in user space. This usually, but not always, provides performance improvements.

Mutex: - mutexes can be named and have handles, they can also be used for interprocess synchronization between threads in separate processes. Mutex objects are similar to CSs, but, in addition to being process-sharable, mutexes allow time-out values and become signaled when abandoned by a terminating process.A thread gains mutex ownership (or locks the mutex) by waiting on the mutex handle (WaitForSingleObject or WaitForMultipleObjects), and it releases ownership with ReleaseMutex.

Semaphore :- Semaphores maintain a count, and the semaphore object is signaled when the count is greater than 0. The semaphore object is unsignaled when the count is 0.

Event :- Events are used to signal other threads that some event, such as a message being available, has occurred.
Read More