-
July 18th, 2002, 02:26 PM
#1
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]
-
July 18th, 2002, 02:37 PM
#2
Whats the question....
BTW: take the / off the first code tag. code starts a code section and /code ends it.
-
July 19th, 2002, 06:22 AM
#3
Everytime you detect a new instance starting, you need to also check your command line. This should have the filename of the file the user is wanting to open. When you switch to the other instance and close yourself down you need to copy the command line into a buffer that is shared between both instances and post a message to the other instance so that it can open the file for you.
Please use meaningful question titles - "Help me" does not let me know whether I can help with your question, and I am unlikely to bother reading it.
Please remember to rate useful answers. It lets us know when a question has been answered.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|