ReactOS 0.4.16-dev-197-g92996da
screensaver.c
Go to the documentation of this file.
1/*
2 * Copyright 2003 J Brown
3 * Copyright 2006 Eric Kohl
4 * Copyright 2007 Marc Piulachs (marc.piulachs@codexchange.net)
5 * Copyright 2015 Daniel Reimer
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20 */
21
22#include <windows.h>
23#include <tchar.h>
24#include <scrnsave.h>
25#include "resource.h"
26
27#define RANDOM( min, max ) ((rand() % (int)(((max)+1) - (min))) + (min))
28
29#define MAX_LOADSTRING 100
30#define MAX_STARS 1000
31
32#define APPNAME _T("Starfield")
33#define APP_TIMER 1
34#define APP_TIMER_INTERVAL 20
35
36#define MAX_STARS 1000
37
38// Details of each individual star
39typedef struct star
40{
44
46
49
51{
52 int nX, nY;
53 int i;
54 for (i = 0; i < m_nTotStars; i++)
55 {
56 // Clear last position of this star
57 SetPixel (
58 pDC,
59 stars[i].m_nOldX,
60 stars[i].m_nOldY,
61 RGB (0, 0, 0));
62
63 nX = (int)((((long)stars[i].m_nXPos << 7) / (long)stars[i].m_nZPos) + m_nCenterX);
64 nY = (int)((((long)stars[i].m_nYPos << 7) / (long)stars[i].m_nZPos) + m_nCenterY);
65
66 // Draw star
67 SetPixel (
68 pDC,
69 nX,
70 nY,
71 RGB (255, 255, 255));
72
73 // Remember current position for clearing later
74 stars[i].m_nOldX = nX;
75 stars[i].m_nOldY = nY;
76 }
77}
78
79BOOL SetUpStars (int nNumStars)
80{
81 int i;
82 if (nNumStars > MAX_STARS)
83 {
84 MessageBox (0,
85 _T("Too many stars! Aborting!"),
86 _T("Error"),
88 return FALSE;
89 }
90
91 if (stars)
92 free (stars);
93
94 m_nTotStars = nNumStars;
95
96 stars = (STAR*)malloc(nNumStars * sizeof(STAR));
97
98 if (!stars)
99 {
100 MessageBox (0,
101 _T("Unable to allocate memory! Aborting!"),
102 _T("Error"),
104 return FALSE;
105 }
106
107 for (i = 0; i < m_nTotStars; i++)
108 {
109 do
110 {
111 stars[i].m_nXPos = RANDOM (-320, 320);
112 stars[i].m_nYPos = RANDOM (-200, 200);
113 stars[i].m_nZPos = i+1;
114 stars[i].m_nOldX = -1;
115 stars[i].m_nOldY = -1;
116 } while ((stars[i].m_nXPos == 0) || (stars[i].m_nYPos == 0));
117 }
118 return TRUE;
119}
120
121void MoveStarField (int nXofs, int nYofs, int nZofs)
122{
123 int i;
124 for (i = 0; i < m_nTotStars; i++)
125 {
126 stars[i].m_nXPos += nXofs;
127 stars[i].m_nYPos += nYofs;
128 stars[i].m_nZPos += nZofs;
129
130 if (stars[i].m_nZPos > m_nTotStars)
132 if (stars[i].m_nZPos < 1)
134 }
135}
136
137void SetDimensions (int nWidth, int nHeight)
138{
139 m_nCenterX = nWidth / 2;
140 m_nCenterY = nHeight / 2;
141}
142
144{
145 static HDC pDC;
146
147 switch (msg)
148 {
149 case WM_CREATE:
150 {
151 SetTimer (
152 hwnd,
153 APP_TIMER,
155 NULL);
156 }
157 break;
158 case WM_PAINT:
159 {
160 PAINTSTRUCT PtStr;
161 HDC pDC = BeginPaint (hwnd, &PtStr);
162 DrawStarField (pDC);
163 EndPaint (hwnd, &PtStr);
164 SetUpStars(250);
165 return (0);
166 }
167 break;
168 case WM_TIMER:
169 {
170 if (wParam == APP_TIMER)
171 {
172 MoveStarField (0, 0, -3);
173 pDC = GetDC(hwnd);
174 DrawStarField (pDC);
175 ReleaseDC(hwnd, pDC);
176 }
177 }
178 break;
179 case WM_SIZE:
180 {
181 // Change the center point of the starfield
183 LOWORD(lParam),
184 HIWORD(lParam));
185 }
186 break;
187 case WM_DESTROY:
188 {
190 free(stars);
192 PostQuitMessage (0);
193 return 0;
194 }
195 break;
196 default:
198 }
199 return 0;
200}
201
203{
204 return FALSE;
205}
206
208{
209 TCHAR szTitle[256];
210 TCHAR szText[256];
211
213 IDS_TITLE,
214 szTitle,
215 256);
216
218 IDS_TEXT,
219 szText,
220 256);
221
222 MessageBox(0,
223 szText,
224 szTitle,
226 return FALSE;
227}
@ lparam
Definition: SystemMenu.c:31
@ wparam
Definition: SystemMenu.c:30
FORCEINLINE VOID SetPixel(_In_ ULONG Left, _In_ ULONG Top, _In_ UCHAR Color)
Definition: arm.h:55
#define msg(x)
Definition: auth_time.c:54
#define IDS_TITLE
Definition: resource.h:30
HWND hWnd
Definition: settings.c:17
#define IDS_TEXT
Definition: resource.h:3
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
#define RGB(r, g, b)
Definition: precomp.h:71
unsigned int BOOL
Definition: ntddk_ex.h:94
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
TCHAR szTitle[MAX_LOADSTRING]
Definition: magnifier.c:35
int m_nCenterY
Definition: screensaver.c:48
LRESULT WINAPI ScreenSaverProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: screensaver.c:143
void DrawStarField(HDC pDC)
Definition: screensaver.c:50
#define MAX_STARS
Definition: screensaver.c:36
void MoveStarField(int nXofs, int nYofs, int nZofs)
Definition: screensaver.c:121
#define RANDOM(min, max)
Definition: screensaver.c:27
#define APP_TIMER_INTERVAL
Definition: screensaver.c:34
BOOL SetUpStars(int nNumStars)
Definition: screensaver.c:79
void SetDimensions(int nWidth, int nHeight)
Definition: screensaver.c:137
struct star STAR
#define APP_TIMER
Definition: screensaver.c:33
STAR * stars
Definition: screensaver.c:45
int m_nTotStars
Definition: screensaver.c:47
BOOL WINAPI RegisterDialogClasses(HANDLE hmodule)
Definition: screensaver.c:207
BOOL WINAPI ScreenSaverConfigureDialog(HWND hWnd, UINT message, WPARAM wparam, LPARAM lparam)
Definition: screensaver.c:202
int m_nCenterX
Definition: screensaver.c:48
static HDC
Definition: imagelist.c:88
static HMODULE hmodule
Definition: rasapi.c:29
unsigned int UINT
Definition: ndis.h:50
#define LOWORD(l)
Definition: pedump.c:82
#define long
Definition: qsort.c:33
LRESULT WINAPI DefScreenSaverProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: scrnsave.c:92
Definition: tftpd.h:60
int m_nXPos
Definition: screensaver.c:41
int m_nYPos
Definition: screensaver.c:41
int m_nZPos
Definition: screensaver.c:41
int m_nOldX
Definition: screensaver.c:42
int m_nOldY
Definition: screensaver.c:42
#define HIWORD(l)
Definition: typedefs.h:247
#define _T(x)
Definition: vfdio.h:22
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define WINAPI
Definition: msvc.h:6
#define WM_PAINT
Definition: winuser.h:1623
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define WM_CREATE
Definition: winuser.h:1611
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define WM_SIZE
Definition: winuser.h:1614
int WINAPI ShowCursor(_In_ BOOL)
Definition: cursoricon.c:2729
UINT_PTR WINAPI SetTimer(_In_opt_ HWND, _In_ UINT_PTR, _In_ UINT, _In_opt_ TIMERPROC)
#define WM_TIMER
Definition: winuser.h:1745
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
HDC WINAPI GetDC(_In_opt_ HWND)
#define MB_OK
Definition: winuser.h:793
#define MB_ICONWARNING
Definition: winuser.h:789
#define LoadString
Definition: winuser.h:5831
#define MessageBox
Definition: winuser.h:5834
#define WM_DESTROY
Definition: winuser.h:1612
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
BOOL WINAPI KillTimer(_In_opt_ HWND, _In_ UINT_PTR)
char TCHAR
Definition: xmlstorage.h:189