| Back to Questions Page |
| |
| Question |
Hi All,
I have created one MFC Dialog Based application.now if i am
running the application its working fine,instead of closing
he application i minimized the application,if i run the
application again,i am getting the Dialog.
I want to prevent the calling of application multiple times.
please give me the code and let me know in which method i
need to make changes.
Praveer |
Rank |
Answer Posted By |
|
Question Submitted By :: Praveer |
| This Interview Question Asked @ HP |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | if(NULL != ::CreateMutex(NULL, TRUE,
_T("CSingleInstanceApp")))
{
long dwError = ::GetLastError();
if(dwError == ERROR_ALREADY_EXISTS)
EndDialog(IDOK);
}
Paste the above code snippet inside the "InitInstance"
function.  |
| Rajaram B |
| |
| |
| Answer | Hi,
i wrote the code as you told still its not
working,here is my code,please have a look
/////////////////////////////////////////////////////////////
BOOL CDlgApp::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce
the size
// of your final executable, you should remove from the
following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a
shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC
statically
#endif
if(NULL != ::CreateMutex(NULL, TRUE,_T("CSingleInstanceApp")))
{
long dwError = ::GetLastError();
if(dwError == ERROR_ALREADY_EXISTS)
EndDialog(NULL,IDOK);
}
CDlgDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that
we exit the
// application, rather than start the application's
message pump.
return FALSE;
}
////////////////////////////////  |
| Praveer |
| |
| |
| Question |
What is CALLBACK? How it work?
what is the advantage of CALLBACK,
please explain with an example
|
Rank |
Answer Posted By |
|
Question Submitted By :: Praveer |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | • callback function is a function that is called
through a function pointer.
• pass the pointer (address) of a function as an
argument to another, when that pointer is used to call the
function it points to it is said that a call back is made.
// 2.1 define a function pointer and initialize to NULL
int (*pt2Function)(float, char, char) =
NULL; // C
int (TMyClass::*pt2Member)(float, char, char) =
NULL; // C++
int (TMyClass::*pt2ConstMember)(float, char, char) const =
NULL; // C++
• A callback function is a function that is passed
to another function (in the form of a pointer to the
callback function) so that the second function can
call it. This is simply of way of making the second
function more flexible without the second function needing
to know a lot of stuff
Uses:
• A callback can be used for notifications
• callback functions can be used for updates, sort of
like hooking into another function. For example, consider a
function that downloads files using http. Your application
may want to display progress to the user. You could pass a
callback function (display progress) into the download
function so that it calls your display function everytime
it reads from the socket. At least that is my
understanding...  |
| Zero Zero.... |
| |
| |
|
|
| |
| Question |
How WM_PAINT message gets called in MFC,please explain it .
a)Who calls the WM_PAINT message?
b)When it gets called?
c)how it comes to message queue?
Please Explain it |
Rank |
Answer Posted By |
|
Question Submitted By :: Praveer |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | a)The framework calls this member function
b)This function get called, when Windows or an application
makes a request to repaint a portion of an application's
window.
c)  |
| Sai |
| |
| |
| Answer | WM_Paint Message will be invoked by the system and not by
any application.
This message is sent when updatewindow or RedrawWindow
Function is called.
Dispactch Message Function dispatches the message , it gets
the message from the GetMessage() or PeekMessage()
Functions.  |
| Vijay |
| |
| |
| Question |
1)why we cant create more than one instance of the class
Derived from CWinApp
|
Rank |
Answer Posted By |
|
Question Submitted By :: Praveer |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | You theApp object is replace with new name;
Eg
CdlgtestApp theApp;
CdlgtestApp theApp3; // now this is your applcation obj
CdlgtestApp theApp3;
CdlgtestApp theApp; // No effect  |
| Narayan |
| |
| |
| Question |
Differ GetMessage, PostMessage & PeakMessage? |
Rank |
Answer Posted By |
|
Question Submitted By :: Td |
| This Interview Question Asked @ Symphony |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | PostMessage is used in Threading usually. to post a message
to Messaging Queue.
Get message is a blocking call it waits for the message
untill it recieve the message it was requiring
Peak message doesnt wait for the message particually it is
looking it just look if the particular message is not in the
queue it returns.  |
| Rao Naeem |
| |
| |
| Question |
How can i change the color of a dropdowncombobox elements |
Rank |
Answer Posted By |
|
Question Submitted By :: K.ramaswamy |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | to change color of all controls
window message "WM_CTLCOLOR" needs to process
in MFC this can be done by modifying OnCtlColor()
eg.
HBRUSH CTestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd,
UINT nCtlColor)
{
HBRUSH hbr;
switch (nCtlColor)
{
// process my edit controls by ID.
case CTLCOLOR_EDIT:
case CTLCOLOR_MSGBOX:
switch (pWnd->GetDlgCtrlID())
{
// first CEdit control ID
case IDC_MYCONTROLNAME1:
// put your own CONTROL ID here
pDC->SetBkMode(TRANSPARENT); // make text
// background transparent
pDC->SetTextColor(RGB(255,0,0));
// change the text color to red.
hbr = (HBRUSH) GetStockObject(NULL_BRUSH);
// apply a null brush, so control's rectangle
// isn't filled.
break;
// otherwise, do default handling of OnCtlColor
default:
hbr=CDialog::OnCtlColor(pDC,pWnd,nCtlColor);
}
return hbr; // return brush
}
refer
http://www.codeguru.com/cpp/controls/editctrl/backgroundcolor/article.php/c3929/
for more information
 |
| Sanjay20 |
| |
| |
| Question |
Why Array Index starts from Zero |
Rank |
Answer Posted By |
|
Question Submitted By :: K.ramaswamy |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | This boils down to the concept of Binary digits. Take an
array size of 64 for example. We start from 0 and end at
63. We require 6 bits.But, if we were to start from 1 and
end at 64, we would require 7 bits to store the same
number, thus increasing the storage size.  |
| Chandan Singh From Niit |
| |
| |
| Answer | the index of array, which is of the form a[i], is converted
by the compiler in the form [a+i]. So, the index of first
element is zero because [a+0] will give 'a' & the first
array element can be accessed. Due to this, we can also
access the array elements as'i[a]' instead of 'a[i]' , &
this will not produce an error.  |
| Pooja Sonawane |
| |
| |
| Answer | i think 2nd answer is correct
'we can also
access the array elements as'i[a]' instead of 'a[i]' , &
this will not produce an error' is wrong  |
| Murukesan |
| |
| |
| Answer | Both Answer ARE correct but First one is EXACT and after
that compiler is design according to that  |
| Chetan |
| |
| |
| Question |
How we can findout Memoryleaks, In what way it can be
avoided |
Rank |
Answer Posted By |
|
Question Submitted By :: K.ramaswamy |
| This Interview Question Asked @ Infosys |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | To find out the memory leaks there are several ways
1. Use Permon utility provided by Microsoft
2. Collect the memory leak dump using Debug Diag and
investigate.  |
| Chandrasekharreddy S |
| |
| |
| Answer | Use CMemoryState class put checkpoints and differences, and
investigate  |
| Guest |
| |
| |
| Question |
What is the initial function to be called in MFC and what
it will do |
Rank |
Answer Posted By |
|
Question Submitted By :: K.ramaswamy |
| This Interview Question Asked @ Infosys |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | The WinMain function is called by the system as the initial
entry point for a Windows-based application. It initializes
the application, display its main window, and enter a
message retrieval-and-dispatch loop that is the top-level
control structure for the remainder of the application's
execution.  |
| Abhishek Soni |
| |
| |
| Answer | The question was for MFC and its InitInstance.  |
| Iridium |
| |
| |
| Answer | CWinAPP is the first function to be called.  |
| Aeganesan |
| |
| |
| Answer | InitApplication and InitInstance functions gets called
first by WinMain  |
| Zerozero |
| |
| |
| Answer | Intial function called in MFC is AfxWinMain which is
WinMain equivalent. AfxWinMain then calls AfxWinInit which
initialises tha application and copies AfxWinMain
fub=nction parameters to the mamber variables of the
application object.then it calls InitApplication(only for
16 bit)/InitInstance(32 bit) .If all the above goes well
then Run function is called which starts the message loop.  |
| Pallavi |
| |
| |
| Question |
How can i implement the dynamic menus in MFC plz give the
code |
Rank |
Answer Posted By |
|
Question Submitted By :: K.ramaswamy |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | Create a CMenu object on the stack frame as a local, then
call CMenu’s member functions to manipulate the new menu as
needed. Use the following function to create the same
1. LoadMenu,SetMenu or TrackPopupMenu function  |
| Surendra Mishra |
| |
| |
| Answer | The code would look like this:
BEGIN_MESSAGE_MAP(CSomeCtrl, COleControl)
//{{AFX_MSG_MAP(CSomeCtrl)
//}}AFX_MSG_MAP
ON_COMMAND(IDM_MENU_ITEM, OnPopupMenuItem)
END_MESSAGE_MAP()
LRESULT CSomeCtrl::OnPopupMenuItem(WORD wNotifyCode, WORD
wID, HWND hWndCtl, BOOL& bHandled)
{
// Implementation of the menu command handler...
return S_OK;
}
{
// Dynamic creation...
CMenu mnuZoomOutPopUp;
mnuZoomOutPopUp.CreatePopupMenu();
CString strMenuItem;
strMenuItem.LoadString(IDM_MENU_ITEM);
mnuZoomOutPopUp.AppendMenu( MF_STRING | MF_ENABLED,
IDM_MENU_ITEM, strMenuItem );
mnuZoomOutPopUp.AppendMenu( MF_SEPARATOR, 0, "" );
// nLeftPos, nTopPos -- screen coordinates of pop-up menu
placement ...
mnuZoomOutPopUp.TrackPopupMenu( TPM_LEFTALIGN, nLeftPos,
nTopPos, this );
mnuZoomOutPopUp.DestroyMenu();
}  |
| Igor Polivanyi |
| |
| |
| Question |
I can i set size of integer variable should be fixed for
different operating systems(Ex i want integer size is
2bytes in OS) |
Rank |
Answer Posted By |
|
Question Submitted By :: K.ramaswamy |
| This Interview Question Asked @ Invensys |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | one can define integer class
like
class Int {
byte data[2];
public:
//overload all basic operation of integer here
//like + - etc
};  |
| Vijay Visana |
| |
| |
| Answer | we can define with #ifdef's
Ex:
#ifdef OS==WINDOWS
int a:32;
#endif
#ifdef OS==UNIX
int a:64;
#endif  |
| Wizards |
| |
| |
| Question |
What is difference between the TCP/IP and UDP socket |
Rank |
Answer Posted By |
|
Question Submitted By :: K.ramaswamy |
| This Interview Question Asked @ Invensys |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | TCP/IP is connection oriented and UDP is Connection less
protocol.  |
| Naved Lodi |
| |
| |
| Answer | TCP/IP Vs UDP :
1. Connection oriented & other is Connection less
2. Will have Acknowledgment & other one don't
3. Performance slow & other one fast
4. More secure & other is not much  |
| Rajendar Gunnal |
| |
| |
|
| |
|
Back to Questions Page |