diff --git a/dll/cpl/desk/screensaver.c b/dll/cpl/desk/screensaver.c index 5c310f8d6929c..8226fe7396151 100644 --- a/dll/cpl/desk/screensaver.c +++ b/dll/cpl/desk/screensaver.c @@ -173,10 +173,14 @@ ShowScreenSaverPreview(IN LPDRAWITEMSTRUCT draw, IN PDATA pData) } +/* + * /p: Run preview, hwnd is handle of calling window + */ static VOID SetScreenSaverPreviewBox(HWND hwndDlg, PDATA pData) { HWND hPreview = pData->ScreenSaverPreviewParent; + HRESULT hr; STARTUPINFO si; TCHAR szCmdline[2048]; @@ -190,32 +194,34 @@ SetScreenSaverPreviewBox(HWND hwndDlg, PDATA pData) } ShowWindow(pData->ScreenSaverPreviewParent, SW_HIDE); - if (pData->Selection > 0) + if (pData->Selection < 1) + return; + + hr = StringCbPrintf(szCmdline, sizeof(szCmdline), + TEXT("%s /p %Iu"), + pData->ScreenSaverItems[pData->Selection].szFilename, + (ULONG_PTR)hPreview); + if (FAILED(hr)) + return; + + ZeroMemory(&si, sizeof(si)); + si.cb = sizeof(si); + ZeroMemory(&pData->PrevWindowPi, sizeof(pData->PrevWindowPi)); + + ShowWindow(pData->ScreenSaverPreviewParent, SW_SHOW); + + if (!CreateProcess(NULL, + szCmdline, + NULL, + NULL, + FALSE, + 0, + NULL, + NULL, + &si, + &pData->PrevWindowPi)) { - _stprintf(szCmdline, - _T("%s /p %Iu"), - pData->ScreenSaverItems[pData->Selection].szFilename, - (ULONG_PTR)hPreview); - - ZeroMemory(&si, sizeof(si)); - si.cb = sizeof(si); - ZeroMemory(&pData->PrevWindowPi, sizeof(pData->PrevWindowPi)); - - ShowWindow(pData->ScreenSaverPreviewParent, SW_SHOW); - - if (!CreateProcess(NULL, - szCmdline, - NULL, - NULL, - FALSE, - 0, - NULL, - NULL, - &si, - &pData->PrevWindowPi)) - { - pData->PrevWindowPi.hThread = pData->PrevWindowPi.hProcess = NULL; - } + pData->PrevWindowPi.hThread = pData->PrevWindowPi.hProcess = NULL; } } @@ -260,38 +266,40 @@ WaitForSettingsDialog(HWND hwndDlg, } +/* + * /c: Run configuration, hwnd is handle of calling window + */ static VOID -ScreensaverConfig(HWND hwndDlg, PDATA pData) +ScreenSaverConfig(HWND hwndDlg, PDATA pData) { - /* - * /c: Run configuration, hwnd is handle of calling window - */ - - TCHAR szCmdline[2048]; + HRESULT hr; STARTUPINFO si; PROCESS_INFORMATION pi; + TCHAR szCmdline[2048]; if (pData->Selection < 1) return; - _stprintf(szCmdline, - _T("%s /c:%Iu"), - pData->ScreenSaverItems[pData->Selection].szFilename, - (ULONG_PTR)hwndDlg); + hr = StringCbPrintf(szCmdline, sizeof(szCmdline), + TEXT("%s /c:%Iu"), + pData->ScreenSaverItems[pData->Selection].szFilename, + (ULONG_PTR)hwndDlg); + if (FAILED(hr)) + return; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); ZeroMemory(&pi, sizeof(pi)); if (CreateProcess(NULL, - szCmdline, - NULL, - NULL, - FALSE, - 0, - NULL, - NULL, - &si, - &pi)) + szCmdline, + NULL, + NULL, + FALSE, + 0, + NULL, + NULL, + &si, + &pi)) { /* Kill off the previous preview process */ if (pData->PrevWindowPi.hProcess) @@ -310,17 +318,16 @@ ScreensaverConfig(HWND hwndDlg, PDATA pData) } } - +/* + * /s Run normal + */ static VOID -ScreensaverPreview(HWND hwndDlg, PDATA pData) +ScreenSaverPreview(HWND hwndDlg, PDATA pData) { - /* - /s Run normal - */ - - TCHAR szCmdline[2048]; + HRESULT hr; STARTUPINFO si; PROCESS_INFORMATION pi; + TCHAR szCmdline[2048]; if (pData->Selection < 1) return; @@ -334,23 +341,25 @@ ScreensaverPreview(HWND hwndDlg, PDATA pData) pData->PrevWindowPi.hThread = pData->PrevWindowPi.hProcess = NULL; } - _stprintf(szCmdline, - _T("%s /s"), - pData->ScreenSaverItems[pData->Selection].szFilename); + hr = StringCbPrintf(szCmdline, sizeof(szCmdline), + TEXT("%s /s"), + pData->ScreenSaverItems[pData->Selection].szFilename); + if (FAILED(hr)) + return; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); ZeroMemory(&pi, sizeof(pi)); if (CreateProcess(NULL, - szCmdline, - NULL, - NULL, - FALSE, - 0, - NULL, - NULL, - &si, - &pi)) + szCmdline, + NULL, + NULL, + FALSE, + 0, + NULL, + NULL, + &si, + &pi)) { WaitForSingleObject(pi.hProcess, INFINITE); CloseHandle(pi.hProcess); @@ -638,9 +647,8 @@ SetScreenSaver(HWND hwndDlg, PDATA pData) &bRet, FALSE); if (Time == 0) - Time = 60; - else - Time *= 60; + Time = 1; + Time *= 60; // Convert to seconds SystemParametersInfoW(SPI_SETSCREENSAVETIMEOUT, Time, 0, SPIF_SENDCHANGE | SPIF_UPDATEINIFILE); @@ -888,7 +896,7 @@ ScreenSaverPageProc(HWND hwndDlg, { if (command == BN_CLICKED) { - ScreensaverPreview(hwndDlg, pData); + ScreenSaverPreview(hwndDlg, pData); SetScreenSaverPreviewBox(hwndDlg, pData); } break; @@ -897,7 +905,7 @@ ScreenSaverPageProc(HWND hwndDlg, case IDC_SCREENS_SETTINGS: // Screensaver Settings { if (command == BN_CLICKED) - ScreensaverConfig(hwndDlg, pData); + ScreenSaverConfig(hwndDlg, pData); break; }