ReactOS 0.4.16-dev-340-g0540c21
screensaver.c File Reference
#include <windows.h>
#include <tchar.h>
#include <scrnsave.h>
#include "resource.h"
Include dependency graph for screensaver.c:

Go to the source code of this file.

Classes

struct  star
 

Macros

#define RANDOM(min, max)   ((rand() % (int)(((max)+1) - (min))) + (min))
 
#define MAX_LOADSTRING   100
 
#define MAX_STARS   1000
 
#define APPNAME   _T("Starfield")
 
#define APP_TIMER   1
 
#define APP_TIMER_INTERVAL   20
 
#define MAX_STARS   1000
 

Typedefs

typedef struct star STAR
 

Functions

void DrawStarField (HDC pDC)
 
BOOL SetUpStars (int nNumStars)
 
void MoveStarField (int nXofs, int nYofs, int nZofs)
 
void SetDimensions (int nWidth, int nHeight)
 
LRESULT WINAPI ScreenSaverProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 
BOOL WINAPI ScreenSaverConfigureDialog (HWND hWnd, UINT message, WPARAM wparam, LPARAM lparam)
 
BOOL WINAPI RegisterDialogClasses (HANDLE hmodule)
 

Variables

STARstars
 
int m_nTotStars
 
int m_nCenterX
 
int m_nCenterY
 

Macro Definition Documentation

◆ APP_TIMER

#define APP_TIMER   1

Definition at line 33 of file screensaver.c.

◆ APP_TIMER_INTERVAL

#define APP_TIMER_INTERVAL   20

Definition at line 34 of file screensaver.c.

◆ APPNAME

#define APPNAME   _T("Starfield")

Definition at line 32 of file screensaver.c.

◆ MAX_LOADSTRING

#define MAX_LOADSTRING   100

Definition at line 29 of file screensaver.c.

◆ MAX_STARS [1/2]

#define MAX_STARS   1000

Definition at line 36 of file screensaver.c.

◆ MAX_STARS [2/2]

#define MAX_STARS   1000

Definition at line 36 of file screensaver.c.

◆ RANDOM

#define RANDOM (   min,
  max 
)    ((rand() % (int)(((max)+1) - (min))) + (min))

Definition at line 27 of file screensaver.c.

Typedef Documentation

◆ STAR

typedef struct star STAR

Function Documentation

◆ DrawStarField()

void DrawStarField ( HDC  pDC)

Definition at line 50 of file screensaver.c.

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}
FORCEINLINE VOID SetPixel(_In_ ULONG Left, _In_ ULONG Top, _In_ UCHAR Color)
Definition: arm.h:55
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
#define RGB(r, g, b)
Definition: precomp.h:71
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
int m_nCenterY
Definition: screensaver.c:48
STAR * stars
Definition: screensaver.c:45
int m_nTotStars
Definition: screensaver.c:47
int m_nCenterX
Definition: screensaver.c:48
#define long
Definition: qsort.c:33
int m_nOldX
Definition: screensaver.c:42
int m_nOldY
Definition: screensaver.c:42

Referenced by ScreenSaverProc().

◆ MoveStarField()

void MoveStarField ( int  nXofs,
int  nYofs,
int  nZofs 
)

Definition at line 121 of file screensaver.c.

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}
int m_nXPos
Definition: screensaver.c:41
int m_nYPos
Definition: screensaver.c:41
int m_nZPos
Definition: screensaver.c:41

Referenced by ScreenSaverProc().

◆ RegisterDialogClasses()

BOOL WINAPI RegisterDialogClasses ( HANDLE  hmodule)

Definition at line 207 of file screensaver.c.

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}
#define IDS_TITLE
Definition: resource.h:30
#define IDS_TEXT
Definition: resource.h:3
#define FALSE
Definition: types.h:117
TCHAR szTitle[MAX_LOADSTRING]
Definition: magnifier.c:35
static HMODULE hmodule
Definition: rasapi.c:29
#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
char TCHAR
Definition: xmlstorage.h:189

◆ ScreenSaverConfigureDialog()

BOOL WINAPI ScreenSaverConfigureDialog ( HWND  hWnd,
UINT  message,
WPARAM  wparam,
LPARAM  lparam 
)

Definition at line 202 of file screensaver.c.

203{
204 return FALSE;
205}

◆ ScreenSaverProc()

LRESULT WINAPI ScreenSaverProc ( HWND  hwnd,
UINT  msg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 143 of file screensaver.c.

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}
#define msg(x)
Definition: auth_time.c:54
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define free
Definition: debug_ros.c:5
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
void DrawStarField(HDC pDC)
Definition: screensaver.c:50
void MoveStarField(int nXofs, int nYofs, int nZofs)
Definition: screensaver.c:121
#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
#define APP_TIMER
Definition: screensaver.c:33
static HDC
Definition: imagelist.c:88
#define LOWORD(l)
Definition: pedump.c:82
LRESULT WINAPI DefScreenSaverProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: scrnsave.c:92
#define HIWORD(l)
Definition: typedefs.h:247
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
#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 WM_DESTROY
Definition: winuser.h:1612
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
BOOL WINAPI KillTimer(_In_opt_ HWND, _In_ UINT_PTR)

◆ SetDimensions()

void SetDimensions ( int  nWidth,
int  nHeight 
)

Definition at line 137 of file screensaver.c.

138{
139 m_nCenterX = nWidth / 2;
140 m_nCenterY = nHeight / 2;
141}

Referenced by ScreenSaverProc().

◆ SetUpStars()

BOOL SetUpStars ( int  nNumStars)

Definition at line 79 of file screensaver.c.

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}
#define malloc
Definition: debug_ros.c:4
#define MAX_STARS
Definition: screensaver.c:36
#define RANDOM(min, max)
Definition: screensaver.c:27
#define _T(x)
Definition: vfdio.h:22

Referenced by ScreenSaverProc().

Variable Documentation

◆ m_nCenterX

int m_nCenterX

Definition at line 48 of file screensaver.c.

Referenced by DrawStarField(), and SetDimensions().

◆ m_nCenterY

int m_nCenterY

Definition at line 48 of file screensaver.c.

Referenced by DrawStarField(), and SetDimensions().

◆ m_nTotStars

int m_nTotStars

Definition at line 47 of file screensaver.c.

Referenced by DrawStarField(), MoveStarField(), and SetUpStars().

◆ stars

STAR* stars

Definition at line 45 of file screensaver.c.

Referenced by DrawStarField(), MoveStarField(), ScreenSaverProc(), and SetUpStars().