HANDLE hMutex = ::CreateMutex( NULL, TRUE, strObjectName );
if( GetLastError() == ERROR_ALREADY_EXISTS )
{
//Find our previous application's main window.
CWnd * pPrevWnd = CWnd::GetDesktopWindow()->GetWindow( GW_CHILD );
while( pPrevWnd )
{
// Does this window have the previous instance tag'set?
if( ::GetProp( pPrevWnd->GetSafeHwnd(), m_pszExeName ) )
{
// Found window, now set focus to the window.
// First rrestore window id it is currently iconic.
if( pPrevWnd->IsIconic() )
{
pPrevWnd->ShowWindow( SW_RESTORE );
}
// Set focus to main eindow.
pPrevWnd->SetForegroundWindow();
// Id window has a pop-up window, set focus to pop-up.
pPrevWnd->GetLastActivePopup()->SetForegroundWindow();
if(m_lpCmdLine[0] != _T('/0'))
{
// Deal with command line parameter
}
return FALSE;
}
// Didnot find window, get next window in list.
pPrevWnd = pPrevWnd->GetWindow( GW_HWNDNEXT );
}
return FALSE;
}