2007-10-29 22:49:31 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2003 J Brown
|
|
|
|
* Copyright 2006 Eric Kohl
|
|
|
|
* Copyright 2007 Marc Piulachs (marc.piulachs@codexchange.net)
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
2009-10-27 10:34:16 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2007-10-29 22:49:31 +00:00
|
|
|
*/
|
|
|
|
|
2023-09-03 19:18:23 +00:00
|
|
|
#include <stdlib.h>
|
2013-01-24 23:00:42 +00:00
|
|
|
#include <windef.h>
|
|
|
|
#include <winbase.h>
|
|
|
|
#include <wingdi.h>
|
|
|
|
#include <winuser.h>
|
2008-02-21 17:07:01 +00:00
|
|
|
#include <scrnsave.h>
|
2013-01-24 23:00:42 +00:00
|
|
|
|
2007-10-29 22:49:31 +00:00
|
|
|
#include "resource.h"
|
|
|
|
|
2023-09-03 19:18:23 +00:00
|
|
|
#define RANDOM(min, max) ((rand() % (int)(((max)+1) - (min))) + (min))
|
2007-10-29 22:49:31 +00:00
|
|
|
|
2013-02-24 20:27:15 +00:00
|
|
|
#define APP_TIMER 1
|
2023-09-03 19:18:23 +00:00
|
|
|
#define APP_TIMER_INTERVAL 10000
|
2007-10-29 22:49:31 +00:00
|
|
|
|
2023-09-03 19:18:23 +00:00
|
|
|
static
|
2013-02-24 20:27:15 +00:00
|
|
|
HBITMAP
|
|
|
|
GetScreenSaverBitmap(VOID)
|
2007-10-29 22:49:31 +00:00
|
|
|
{
|
2023-09-03 19:18:23 +00:00
|
|
|
OSVERSIONINFOEX osvi = {0};
|
|
|
|
osvi.dwOSVersionInfoSize = sizeof(osvi);
|
|
|
|
GetVersionEx((POSVERSIONINFO)&osvi);
|
|
|
|
|
|
|
|
return LoadImageW(GetModuleHandle(NULL),
|
|
|
|
osvi.wProductType == VER_NT_WORKSTATION ?
|
|
|
|
MAKEINTRESOURCEW(IDB_WORKSTATION) : MAKEINTRESOURCEW(IDB_SERVER),
|
|
|
|
IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
|
2007-10-29 22:49:31 +00:00
|
|
|
}
|
|
|
|
|
2013-02-24 20:27:15 +00:00
|
|
|
LRESULT
|
|
|
|
CALLBACK
|
2023-09-03 19:18:23 +00:00
|
|
|
ScreenSaverProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
2007-10-29 22:49:31 +00:00
|
|
|
{
|
2013-02-24 20:27:15 +00:00
|
|
|
static HBITMAP bitmap;
|
|
|
|
|
2023-09-03 19:18:23 +00:00
|
|
|
switch (uMsg)
|
2013-02-24 20:27:15 +00:00
|
|
|
{
|
|
|
|
case WM_CREATE:
|
|
|
|
{
|
2023-09-03 19:18:23 +00:00
|
|
|
bitmap = GetScreenSaverBitmap();
|
2013-02-24 20:27:15 +00:00
|
|
|
if (bitmap == NULL)
|
|
|
|
{
|
2023-09-03 19:18:23 +00:00
|
|
|
/* Extremely unlikely, message not localized. */
|
|
|
|
MessageBoxW(hWnd,
|
|
|
|
L"Fatal Error: Could not load bitmap",
|
|
|
|
L"Error",
|
|
|
|
MB_OK | MB_ICONEXCLAMATION);
|
2013-02-24 20:27:15 +00:00
|
|
|
}
|
|
|
|
|
2023-09-03 19:18:23 +00:00
|
|
|
SetTimer(hWnd, APP_TIMER, APP_TIMER_INTERVAL, NULL);
|
|
|
|
break;
|
2013-02-24 20:27:15 +00:00
|
|
|
}
|
|
|
|
case WM_PAINT:
|
|
|
|
{
|
2023-09-03 19:18:23 +00:00
|
|
|
BITMAP bm;
|
|
|
|
PAINTSTRUCT ps;
|
|
|
|
HDC hdc;
|
|
|
|
HDC hdcMem;
|
|
|
|
HBITMAP hbmOld;
|
|
|
|
RECT rect;
|
|
|
|
|
|
|
|
hdc = BeginPaint(hWnd, &ps);
|
|
|
|
hdcMem = CreateCompatibleDC(hdc);
|
|
|
|
hbmOld = SelectObject(hdcMem, bitmap);
|
|
|
|
GetObjectW(bitmap, sizeof(bm), &bm);
|
|
|
|
|
|
|
|
GetClientRect(hWnd, &rect);
|
|
|
|
if (rect.right < bm.bmWidth || rect.bottom < bm.bmHeight)
|
|
|
|
{
|
|
|
|
StretchBlt(hdc, RANDOM(0, rect.right - (bm.bmWidth / 5)),
|
|
|
|
RANDOM(0, rect.bottom - (bm.bmHeight / 5)),
|
|
|
|
bm.bmWidth / 5, bm.bmHeight / 5, hdcMem, 0, 0,
|
|
|
|
bm.bmWidth, bm.bmHeight, SRCCOPY);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BitBlt(hdc, RANDOM(0, rect.right - bm.bmWidth),
|
|
|
|
RANDOM(0, rect.bottom - bm.bmHeight),
|
|
|
|
bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
|
|
|
|
}
|
|
|
|
|
|
|
|
SelectObject(hdcMem, hbmOld);
|
|
|
|
DeleteDC(hdcMem);
|
|
|
|
EndPaint(hWnd, &ps);
|
|
|
|
break;
|
2013-02-24 20:27:15 +00:00
|
|
|
}
|
2008-02-21 17:07:01 +00:00
|
|
|
case WM_TIMER:
|
|
|
|
{
|
2023-09-03 19:18:23 +00:00
|
|
|
InvalidateRect(hWnd, NULL, TRUE);
|
|
|
|
break;
|
2008-02-21 17:07:01 +00:00
|
|
|
}
|
2013-02-24 20:27:15 +00:00
|
|
|
case WM_DESTROY:
|
|
|
|
{
|
|
|
|
KillTimer(hWnd, APP_TIMER);
|
|
|
|
DeleteObject(bitmap);
|
|
|
|
PostQuitMessage(0);
|
|
|
|
break;
|
|
|
|
}
|
2008-02-21 17:07:01 +00:00
|
|
|
default:
|
2023-09-03 19:18:23 +00:00
|
|
|
{
|
|
|
|
/* Pass window messages to the default screensaver window procedure */
|
|
|
|
return DefScreenSaverProc(hWnd, uMsg, wParam, lParam);
|
|
|
|
}
|
2008-02-21 17:07:01 +00:00
|
|
|
}
|
2007-10-29 22:49:31 +00:00
|
|
|
|
2013-02-24 20:27:15 +00:00
|
|
|
return 0;
|
2007-10-29 22:49:31 +00:00
|
|
|
}
|
|
|
|
|
2013-02-24 20:27:15 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
ScreenSaverConfigureDialog(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
2007-10-29 22:49:31 +00:00
|
|
|
{
|
2008-02-21 17:07:01 +00:00
|
|
|
return FALSE;
|
2007-10-29 22:49:31 +00:00
|
|
|
}
|
|
|
|
|
2023-09-03 19:18:23 +00:00
|
|
|
/* This function is only called once before opening the configuration dialog.
|
|
|
|
* Use it to show a message that no configuration is necessary and return FALSE to indicate that no configuration dialog shall be opened.
|
|
|
|
*/
|
2013-02-24 20:27:15 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
RegisterDialogClasses(HANDLE hInst)
|
2007-10-29 22:49:31 +00:00
|
|
|
{
|
2023-09-03 19:18:23 +00:00
|
|
|
WCHAR szMessage[256];
|
|
|
|
WCHAR szTitle[25];
|
2007-10-29 22:49:31 +00:00
|
|
|
|
2023-09-03 19:18:23 +00:00
|
|
|
LoadStringW(hInst, IDS_TEXT, szMessage, _countof(szMessage));
|
|
|
|
LoadStringW(hInst, IDS_DESCRIPTION, szTitle, _countof(szTitle));
|
2007-10-29 22:49:31 +00:00
|
|
|
|
2023-09-03 19:18:23 +00:00
|
|
|
MessageBoxW(NULL, szMessage, szTitle, MB_OK | MB_ICONEXCLAMATION);
|
2007-10-29 22:49:31 +00:00
|
|
|
|
2008-02-21 17:07:01 +00:00
|
|
|
return FALSE;
|
2007-10-29 22:49:31 +00:00
|
|
|
}
|