Here is what I am trying to do: I have a Dialog Application and I only want to have one instance running at a time.

Here is the code that I have, but it still allows for mulitple instances.

LPCTSTR lpszUniqueClass = _T("MsdSaveData");

BOOL CGSaveApp::InitInstance()
{
// InitCommonControls() is required on Windows XP if an application
// manifest specifies use of ComCtl32.dll version 6 or later to enable
// visual styles. Otherwise, any window creation will fail.

// check for previous instance of Software
if(FirstInstance()== FALSE)
{
return(FALSE);
}

InitCommonControls();

CWinApp::InitInstance();

AfxEnableControlContainer();

// Register our unique class name that we wish to use
WNDCLASS wndcls;
memset(&wndcls, 0, sizeof(WNDCLASS)); // start with NULL defaults
wndcls.style = CS_DBLCLKS |CS_HREDRAW |CS_VREDRAW;
wndcls.lpfnWndProc = :efWindowProc;
wndcls.hInstance = AfxGetInstanceHandle();
wndcls.hIcon = NULL;
wndcls.hCursor = LoadCursor(IDC_ARROW);
wndcls.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
wndcls.lpszMenuName = NULL;
wndcls.cbWndExtra = DLGWINDOWEXTRA;
wndcls.lpszClassName = lpszUniqueClass;
// register MsdSaveData class name
if(!AfxRegisterClass(&wndcls))
{
return FALSE;
}


CGSaveDlg dlg;
m_pMainWnd = &dlg;
INT_PTR 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;
}




BOOL CGSaveApp::FirstInstance(void)
{
CWnd *pWndPrev, *pWndParent, *pWndChild;
// check for another copy of wnd class running
pWndPrev = CWnd::FindWindow(lpszUniqueClass,NULL);
if(pWndPrev)
{
pWndPrev->SetWindowText("TRUE");
pWndParent = pWndPrev->GetParent();
// find child popup
pWndChild = pWndParent->GetLastActivePopup();
// pWndParent->BringWindowToTop();
// activate previous copy
if(pWndParent->IsIconic())
{
pWndParent->ShowWindow(SW_SHOWNORMAL);
}
pWndChild->SetForegroundWindow();
return(FALSE);
}
// first instance
return(TRUE);
}

Thanks I have not been able to figure this out!!