opening many docs in the same application
Hi i have an application that is a singleton. Only one instance of the application exists. Im achieving this by putting following code in the initinstance()
[/code]
char m_pszOneInstance[MAX_PATH];
strcpy(m_pszOneInstance,"Mutex for Avoiding multiple copies of the same appliaction");
//
m_hMutexHandle = CreateMutex(NULL,TRUE,m_pszOneInstance);
//
if (GetLastError() == ERROR_ALREADY_EXISTS)
{
// find previous apps main window
CMainFrame *pPrevWnd =(CMainFrame*) CWnd::GetDesktopWindow()->GetWindow(GW_CHILD);
while (pPrevWnd)
{
// does this window have the "previous instance tag" set ?
if (::GetProp(pPrevWnd->GetSafeHwnd(),m_pszOneInstance))
{
// found the window, now restore if minimized
if (pPrevWnd->IsIconic())
pPrevWnd->ShowWindow(SW_RESTORE);
// set focus
pPrevWnd->SetForegroundWindow();
// if window is a pop-up window, set focus to pop-up
pPrevWnd->GetLastActivePopup()->SetForegroundWindow();
// finally, exit from this instance of the app
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
if(cmdInfo.m_strFileName!="")
{
if(!obUtility.SetFileToOpenInRegistry(cmdInfo.m_strFileName))
{
AfxMessageBox("Problems in accessing registry");
return TRUE;
}
SendMessage(pPrevWnd->GetSafeHwnd(),WM_FILEOPEN,0,0);
}
return TRUE;
}
// get next window in the list
pPrevWnd = (CMainFrame*)pPrevWnd->GetWindow(GW_HWNDNEXT);
}
return TRUE;
}
[/code]