diff --git a/client/win/win_screensaver.cpp b/client/win/win_screensaver.cpp index b72fce0237..9e09f2957e 100755 --- a/client/win/win_screensaver.cpp +++ b/client/win/win_screensaver.cpp @@ -993,7 +993,8 @@ DWORD WINAPI CScreensaver::DataManagementProc() { BOOL bForegroundWindowIsScreensaver; HRESULT hrError; HWND hwndBOINCGraphicsWindow = NULL; - HWND hwndForegroundWindow = NULL; + HWND hwndForeWindow = NULL; + HWND hwndForeParent = NULL; DWORD iMonitor = 0; int iReturnValue = 0; time_t tThreadCreateTime = 0; @@ -1055,14 +1056,14 @@ DWORD WINAPI CScreensaver::DataManagementProc() { hwndBOINCGraphicsWindow = FindWindow(BOINC_WINDOW_CLASS_NAME, NULL); if (hwndBOINCGraphicsWindow) { // Graphics Application. - hwndForegroundWindow = GetForegroundWindow(); + hwndForeWindow = GetForegroundWindow(); // If the graphics application is not the top most window try and force it // to the top. - if (hwndForegroundWindow != hwndBOINCGraphicsWindow) { + if (hwndForeWindow != hwndBOINCGraphicsWindow) { BOINCTRACE(_T("CScreensaver::DataManagementProc - Graphics Window Detected but NOT the foreground window, bringing window to foreground.\n")); SetForegroundWindow(hwndBOINCGraphicsWindow); - hwndForegroundWindow = GetForegroundWindow(); - if (hwndForegroundWindow != hwndBOINCGraphicsWindow) { + hwndForeWindow = GetForegroundWindow(); + if (hwndForeWindow != hwndBOINCGraphicsWindow) { BOINCTRACE(_T("CScreensaver::DataManagementProc - Graphics Window Detected but NOT the foreground window, bringing window to foreground. (Final Try)\n")); // This may be needed on Windows 2000 or better machines @@ -1104,7 +1105,7 @@ DWORD WINAPI CScreensaver::DataManagementProc() { ShowWindow(hwndBOINCGraphicsWindow, SW_MINIMIZE); ShowWindow(hwndBOINCGraphicsWindow, SW_FORCEMINIMIZE); SetError(TRUE, SCRAPPERR_BOINCSHUTDOWNEVENT); - ShutdownSaver(); + SendMessage(m_Monitors[iMonitor].hWnd, WM_INTERRUPTSAVER, NULL, NULL); } } } @@ -1112,10 +1113,13 @@ DWORD WINAPI CScreensaver::DataManagementProc() { // Graphics application does not exist. So check that one of the windows // assigned to each monitor is the foreground window. bForegroundWindowIsScreensaver = FALSE; - hwndForegroundWindow = GetForegroundWindow(); + hwndForeWindow = GetForegroundWindow(); + hwndForeParent = GetParent(hwndForeWindow); for(iMonitor = 0; iMonitor < m_dwNumMonitors; iMonitor++) { pMonitorInfo = &m_Monitors[iMonitor]; - if (pMonitorInfo->hWnd == hwndForegroundWindow) { + if ((pMonitorInfo->hWnd == hwndForeWindow) || + (pMonitorInfo->hWnd == hwndForeParent)) + { bForegroundWindowIsScreensaver = TRUE; } } @@ -1125,7 +1129,7 @@ DWORD WINAPI CScreensaver::DataManagementProc() { // screensaver mode. BOINCTRACE(_T("CScreensaver::DataManagementProc - Unknown foreground window detected, shutdown the screensaver.\n")); SetError(TRUE, SCRAPPERR_BOINCSHUTDOWNEVENT); - ShutdownSaver(); + SendMessage(m_Monitors[iMonitor].hWnd, WM_INTERRUPTSAVER, NULL, NULL); } } break; @@ -1150,7 +1154,7 @@ DWORD WINAPI CScreensaver::DataManagementProc() { GetError(bErrorMode, hrError, NULL, 0); if (SS_STATUS_QUIT == m_iStatus && m_bCoreNotified) { BOINCTRACE(_T("CScreensaver::DataManagementProc - Shutdown BOINC Screensaver\n")); - ShutdownSaver(); + SendMessage(m_Monitors[iMonitor].hWnd, WM_INTERRUPTSAVER, NULL, NULL); } else { if (!bErrorMode && !m_bCoreNotified) { BOINCTRACE(_T("CScreensaver::DataManagementProc - Startup BOINC Screensaver\n")); @@ -1522,6 +1526,11 @@ LRESULT CScreensaver::SaverProc( if (wParam == PBT_APMQUERYSUSPEND && gspfnMyVerifyPwdProc == NULL) InterruptSaver(); break; + case WM_INTERRUPTSAVER: + if (hWnd == m_Monitors[0].hWnd) { + InterruptSaver(); + } + break; } BOINCTRACE(_T("CScreensaver::SaverProc [%d] hWnd '%d' uMsg '%X' wParam '%d' lParam '%d'\n"), dwMonitor, hWnd, uMsg, wParam, lParam); diff --git a/client/win/win_screensaver.h b/client/win/win_screensaver.h index 506ceb2563..644477764d 100644 --- a/client/win/win_screensaver.h +++ b/client/win/win_screensaver.h @@ -35,6 +35,7 @@ #define NO_MONITOR 0xffffffff #define BSF_ALLOWSFW 0x00000080 +#define WM_INTERRUPTSAVER WM_USER+1 #define BOINC_WINDOW_CLASS_NAME _T("BOINC_app") diff --git a/lib/boinc_win.h b/lib/boinc_win.h index 28b936dcc2..1b307aed1d 100644 --- a/lib/boinc_win.h +++ b/lib/boinc_win.h @@ -38,7 +38,7 @@ // platforms we are going to disable the deprecation warnings if we are compiling // on Visual Studio 2005 #if _MSC_VER >= 1400 -#pragma warning(disable: 4996) // function deprecation +#define _CRT_SECURE_NO_DEPRECATE #endif // Modify the following defines if you have to target a platform prior to the ones specified below.