[STARFIELD] Change to use scrnsave library. Tidy up all now useless stuff. Tabs -> spaces. Single language link in support added. Noticable change: Multi Monitor support!!! TBD, some user configuration stuff maybe

svn path=/trunk/; revision=67455
This commit is contained in:
Daniel Reimer 2015-04-27 01:04:01 +00:00
parent 0a06865906
commit a80379f358
4 changed files with 192 additions and 321 deletions

View file

@ -2,5 +2,6 @@
add_executable(starfield screensaver.c starfield.rc)
set_module_type(starfield win32gui UNICODE)
set_target_properties(starfield PROPERTIES SUFFIX ".scr")
target_link_libraries(starfield scrnsave)
add_importlibs(starfield user32 gdi32 msvcrt kernel32)
add_cd_file(TARGET starfield DESTINATION reactos/system32 FOR all)

View file

@ -1,3 +1,4 @@
#pragma once
#define IDS_DESCRIPTION 1
#define IDS_TITLE 2

View file

@ -2,6 +2,7 @@
* Copyright 2003 J Brown
* Copyright 2006 Eric Kohl
* Copyright 2007 Marc Piulachs (marc.piulachs@codexchange.net)
* Copyright 2015 Daniel Reimer
*
* 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
@ -20,6 +21,7 @@
#include <windows.h>
#include <tchar.h>
#include <scrnsave.h>
#include "resource.h"
#define RANDOM( min, max ) ((rand() % (int)(((max)+1) - (min))) + (min))
@ -40,9 +42,6 @@ typedef struct star
int m_nOldX, m_nOldY;
} STAR;
HINSTANCE hInstance;
BOOL fullscreen = FALSE;
STAR *stars;
int m_nTotStars;
@ -116,7 +115,6 @@ BOOL SetUpStars (int nNumStars)
stars[i].m_nOldY = -1;
} while ((stars[i].m_nXPos == 0) || (stars[i].m_nYPos == 0));
}
return TRUE;
}
@ -142,16 +140,13 @@ void SetDimensions (int nWidth, int nHeight)
m_nCenterY = nHeight / 2;
}
LRESULT WINAPI WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
LRESULT WINAPI ScreenSaverProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static POINT ptLast;
static POINT ptCursor;
static BOOL fFirstTime = TRUE;
static HDC pDC;
switch (msg)
{
case WM_CREATE :
case WM_CREATE:
{
SetTimer (
hwnd,
@ -160,16 +155,17 @@ LRESULT WINAPI WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
NULL);
}
break;
case WM_PAINT :
case WM_PAINT:
{
PAINTSTRUCT PtStr;
HDC pDC = BeginPaint (hwnd, &PtStr);
DrawStarField (pDC);
EndPaint (hwnd, &PtStr);
SetUpStars(250);
return (0);
}
break;
case WM_TIMER :
case WM_TIMER:
{
if (wParam == APP_TIMER)
{
@ -180,7 +176,7 @@ LRESULT WINAPI WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
}
}
break;
case WM_SIZE :
case WM_SIZE:
{
// Change the center point of the starfield
SetDimensions (
@ -188,7 +184,7 @@ LRESULT WINAPI WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
HIWORD(lParam));
}
break;
case WM_DESTROY :
case WM_DESTROY:
{
KillTimer (hwnd, APP_TIMER);
free(stars);
@ -197,143 +193,28 @@ LRESULT WINAPI WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
return 0;
}
break;
// break out of screen-saver if any keyboard activity
case WM_NOTIFY:
case WM_SYSKEYDOWN:
{
PostMessage(hwnd, WM_CLOSE, 0, 0);
break;
default:
return DefScreenSaverProc(hwnd, msg, wParam, lParam);
}
// break out of screen-saver if any mouse activity
case WM_LBUTTONDOWN:
case WM_LBUTTONUP:
case WM_RBUTTONDOWN:
case WM_RBUTTONUP:
case WM_MBUTTONDOWN:
case WM_MBUTTONUP:
case WM_MOUSEMOVE:
{
// If we've got a parent then we must be a preview
if(GetParent(hwnd) != 0)
return 0;
if(fFirstTime)
{
GetCursorPos(&ptLast);
fFirstTime = FALSE;
}
GetCursorPos(&ptCursor);
// if the mouse has moved more than 3 pixels then exit
if( (abs(ptCursor.x - ptLast.x) >= 3) ||
(abs(ptCursor.y - ptLast.y) >= 3))
{
PostMessage(hwnd, WM_CLOSE, 0, 0);
}
ptLast = ptCursor;
return 0;
}
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
void InitSaver(HWND hwndParent)
BOOL WINAPI ScreenSaverConfigureDialog(HWND hWnd, UINT message, WPARAM wparam, LPARAM lparam)
{
WNDCLASS wc;
ZeroMemory(&wc, sizeof(wc));
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = APPNAME;
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
RegisterClass(&wc);
if (hwndParent != 0)
{
RECT rect;
GetClientRect(hwndParent, &rect);
CreateWindow(APPNAME, APPNAME,
WS_VISIBLE | WS_CHILD,
0, 0,
rect.right,
rect.bottom,
hwndParent, 0,
hInstance, NULL);
fullscreen = FALSE;
}
else
{
HWND hwnd;
hwnd = CreateWindowEx(WS_EX_TOPMOST,
APPNAME,
APPNAME,
WS_VISIBLE | WS_POPUP,
0, 0,
GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN),
HWND_DESKTOP, 0,
hInstance, NULL);
SetWindowPos(hwnd,
0, 0, 0, 0, 0,
SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_SHOWWINDOW);
ShowCursor(FALSE);
fullscreen = TRUE;
}
SetUpStars(250);
return FALSE;
}
//
// Look for any options Windows has passed to us:
//
// -a <hwnd> (set password)
// -s (screensave)
// -p <hwnd> (preview)
// -c <hwnd> (configure)
//
VOID ParseCommandLine(LPWSTR szCmdLine, UCHAR *chOption, HWND *hwndParent)
{
UCHAR ch = *szCmdLine++;
if(ch == '-' || ch == '/')
ch = *szCmdLine++;
if(ch >= 'A' && ch <= 'Z')
ch += 'a' - 'A'; //convert to lower case
*chOption = ch;
ch = *szCmdLine++;
if(ch == ':')
ch = *szCmdLine++;
while(ch == ' ' || ch == '\t')
ch = *szCmdLine++;
if(isdigit(ch))
{
unsigned int i = _wtoi(szCmdLine - 1);
*hwndParent = (HWND)i;
}
else
*hwndParent = NULL;
}
void Configure(void)
BOOL WINAPI RegisterDialogClasses(HANDLE hmodule)
{
TCHAR szTitle[256];
TCHAR szText[256];
LoadString(hInstance,
LoadString(hmodule,
IDS_TITLE,
szTitle,
256);
LoadString(hInstance,
LoadString(hmodule,
IDS_TEXT,
szText,
256);
@ -342,44 +223,5 @@ void Configure(void)
szText,
szTitle,
MB_OK | MB_ICONWARNING);
}
int CALLBACK wWinMain (HINSTANCE hInst,
HINSTANCE hPrev,
LPWSTR lpCmdLine,
int iCmdShow)
{
HWND hwndParent;
UINT nPreviousState;
UCHAR chOption;
MSG Message;
hInstance = hInst;
ParseCommandLine(lpCmdLine, &chOption, &hwndParent);
SystemParametersInfo(SPI_SETSCREENSAVERRUNNING, TRUE, &nPreviousState, 0);
switch (chOption)
{
case 's':
InitSaver(0);
break;
case 'p':
InitSaver(hwndParent);
break;
case 'c':
default:
Configure();
return 0;
}
while (GetMessage(&Message, 0, 0, 0))
DispatchMessage(&Message);
SystemParametersInfo(SPI_SETSCREENSAVERRUNNING, FALSE, &nPreviousState, 0);
return Message.wParam;
return FALSE;
}

View file

@ -1,4 +1,5 @@
#include <windows.h>
#include <scrnsave.h>
#include "resource.h"
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
@ -10,18 +11,44 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
#include <reactos/version.rc>
#include <reactos/manifest_exe.rc>
/* UTF-8 */
#pragma code_page(65001)
#include "lang/bg-BG.rc"
#include "lang/de-DE.rc"
#include "lang/en-US.rc"
#include "lang/es-ES.rc"
#include "lang/fr-FR.rc"
#include "lang/lt-LT.rc"
#include "lang/nl-NL.rc"
#include "lang/no-NO.rc"
#include "lang/pl-PL.rc"
#include "lang/ro-RO.rc"
#include "lang/sk-SK.rc"
#include "lang/uk-UA.rc"
#ifdef LANGUAGE_BG_BG
#include "lang/bg-BG.rc"
#endif
#ifdef LANGUAGE_DE_DE
#include "lang/de-DE.rc"
#endif
#ifdef LANGUAGE_EN_US
#include "lang/en-US.rc"
#endif
#ifdef LANGUAGE_ES_ES
#include "lang/es-ES.rc"
#endif
#ifdef LANGUAGE_ES_ES
#include "lang/fr-FR.rc"
#endif
#ifdef LANGUAGE_LT_LT
#include "lang/lt-LT.rc"
#endif
#ifdef LANGUAGE_NL_NL
#include "lang/nl-NL.rc"
#endif
#ifdef LANGUAGE_NO_NO
#include "lang/no-NO.rc"
#endif
#ifdef LANGUAGE_PL_PL
#include "lang/pl-PL.rc"
#endif
#ifdef LANGUAGE_RO_RO
#include "lang/ro-RO.rc"
#endif
#ifdef LANGUAGE_SK_SK
#include "lang/sk-SK.rc"
#endif
#ifdef LANGUAGE_UK_UA
#include "lang/uk-UA.rc"
#endif