Skip to content

Commit

Permalink
[DESK] Cleanup some functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
HBelusca committed Oct 16, 2023
1 parent e2d3aa7 commit 6c19406
Showing 1 changed file with 76 additions and 68 deletions.
144 changes: 76 additions & 68 deletions dll/cpl/desk/screensaver.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,14 @@ ShowScreenSaverPreview(IN LPDRAWITEMSTRUCT draw, IN PDATA pData)
}


/*
* /p:<hwnd> 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];

Expand All @@ -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;
}
}

Expand Down Expand Up @@ -260,38 +266,40 @@ WaitForSettingsDialog(HWND hwndDlg,
}


/*
* /c:<hwnd> Run configuration, hwnd is handle of calling window
*/
static VOID
ScreensaverConfig(HWND hwndDlg, PDATA pData)
ScreenSaverConfig(HWND hwndDlg, PDATA pData)
{
/*
* /c:<hwnd> 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)
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -888,7 +896,7 @@ ScreenSaverPageProc(HWND hwndDlg,
{
if (command == BN_CLICKED)
{
ScreensaverPreview(hwndDlg, pData);
ScreenSaverPreview(hwndDlg, pData);
SetScreenSaverPreviewBox(hwndDlg, pData);
}
break;
Expand All @@ -897,7 +905,7 @@ ScreenSaverPageProc(HWND hwndDlg,
case IDC_SCREENS_SETTINGS: // Screensaver Settings
{
if (command == BN_CLICKED)
ScreensaverConfig(hwndDlg, pData);
ScreenSaverConfig(hwndDlg, pData);
break;
}

Expand Down

0 comments on commit 6c19406

Please sign in to comment.