diff --git a/checkin_notes b/checkin_notes index b1993209aa..e9ee541255 100644 --- a/checkin_notes +++ b/checkin_notes @@ -7317,3 +7317,11 @@ Charlie 14 Oct 2010 client/ cs_scheduler.cpp + +Rom 14 Oct 2010 + - MGR: Check for a duplicate instance much earlier in the initialization + cycle, before any window or document creation. Prevents rapid window + creation and then destruction. + + clientgui/ + BOINCGUIApp.cpp, .h diff --git a/clientgui/BOINCGUIApp.cpp b/clientgui/BOINCGUIApp.cpp index b85cbd58ec..d4958d8ac6 100644 --- a/clientgui/BOINCGUIApp.cpp +++ b/clientgui/BOINCGUIApp.cpp @@ -381,6 +381,13 @@ bool CBOINCGUIApp::OnInit() { } #endif + // Detect if BOINC Manager is already running, if so, bring it into the + // foreground and then exit. + if (!m_bMultipleInstancesOK) { + if (DetectDuplicateInstance()) { + return false; + } + } // Initialize the main document m_pDocument = new CMainDocument(); @@ -652,6 +659,23 @@ void CBOINCGUIApp::DetectAccessibilityEnabled() { } +/// +/// Detect if another instance of this application is running. +// Returns true if there is, otherwise false +/// +bool CBOINCGUIApp::DetectDuplicateInstance() { +#ifdef __WXMSW__ + HWND hWnd = ::FindWindow(NULL, m_pSkinManager->GetAdvanced()->GetApplicationName().c_str()); + if (hWnd) { + ::ShowWindow(hWnd, SW_SHOW); + ::SetForegroundWindow(hWnd); + return true; + } +#endif + return false; +} + + /// /// Determines what name BOINC Manager is called. /// diff --git a/clientgui/BOINCGUIApp.h b/clientgui/BOINCGUIApp.h index f7c86dc100..e1a25b2899 100644 --- a/clientgui/BOINCGUIApp.h +++ b/clientgui/BOINCGUIApp.h @@ -60,6 +60,7 @@ protected: void DetectDisplayInfo(); void DetectAccessibilityEnabled(); + bool DetectDuplicateInstance(); void DetectExecutableName(); void DetectRootDirectory(); void DetectDataDirectory();