ReactOS  0.4.13-dev-651-g5dbc677
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 }
STAR * stars
Definition: screensaver.c:45
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
int m_nTotStars
Definition: screensaver.c:47
FORCEINLINE VOID SetPixel(IN ULONG Left, IN ULONG Top, IN UCHAR Color)
Definition: vga.c:93
int m_nCenterX
Definition: screensaver.c:48
#define RGB(r, g, b)
Definition: wingdi.h:2918
int m_nOldY
Definition: screensaver.c:42
#define long
Definition: qsort.c:33
int m_nOldX
Definition: screensaver.c:42
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

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_nZPos
Definition: screensaver.c:41
STAR * stars
Definition: screensaver.c:45
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_nYPos
Definition: screensaver.c:41
int m_nTotStars
Definition: screensaver.c:47

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 MB_ICONWARNING
Definition: winuser.h:780
static const WCHAR szText[]
Definition: dialog.c:139
static HMODULE hmodule
Definition: rasapi.c:29
char TCHAR
Definition: xmlstorage.h:189
#define IDS_TITLE
Definition: resource.h:30
TCHAR szTitle[MAX_LOADSTRING]
Definition: magnifier.c:35
#define MessageBox
Definition: winuser.h:5720
#define MB_OK
Definition: winuser.h:784
#define IDS_TEXT
Definition: resource.h:3
#define LoadString
Definition: winuser.h:5717

◆ 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
182  SetDimensions (
183  LOWORD(lParam),
184  HIWORD(lParam));
185  }
186  break;
187  case WM_DESTROY:
188  {
190  free(stars);
191  ShowCursor(TRUE);
192  PostQuitMessage (0);
193  return 0;
194  }
195  break;
196  default:
198  }
199  return 0;
200 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
void SetDimensions(int nWidth, int nHeight)
Definition: screensaver.c:137
#define TRUE
Definition: types.h:120
HDC WINAPI GetDC(_In_opt_ HWND)
#define free
Definition: debug_ros.c:5
static HDC
Definition: imagelist.c:92
void DrawStarField(HDC pDC)
Definition: screensaver.c:50
void ShowCursor(void)
Definition: hardware.c:556
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
WPARAM wParam
Definition: combotst.c:138
STAR * stars
Definition: screensaver.c:45
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
smooth NULL
Definition: ftsmooth.c:416
UINT_PTR WINAPI SetTimer(_In_opt_ HWND, _In_ UINT_PTR, _In_ UINT, _In_opt_ TIMERPROC)
#define WM_DESTROY
Definition: winuser.h:1591
void MoveStarField(int nXofs, int nYofs, int nZofs)
Definition: screensaver.c:121
#define WM_SIZE
Definition: winuser.h:1593
#define WM_TIMER
Definition: winuser.h:1724
#define APP_TIMER
Definition: screensaver.c:33
#define WM_PAINT
Definition: winuser.h:1602
BOOL WINAPI KillTimer(_In_opt_ HWND, _In_ UINT_PTR)
#define APP_TIMER_INTERVAL
Definition: screensaver.c:34
#define msg(x)
Definition: auth_time.c:54
#define WM_CREATE
Definition: winuser.h:1590
#define HIWORD(l)
Definition: typedefs.h:246
LRESULT WINAPI DefScreenSaverProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: scrnsave.c:95
BOOL SetUpStars(int nNumStars)
Definition: screensaver.c:79
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)

◆ 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 }
int m_nCenterY
Definition: screensaver.c:48
int m_nCenterX
Definition: screensaver.c:48

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 TRUE
Definition: types.h:120
int m_nXPos
Definition: screensaver.c:41
#define free
Definition: debug_ros.c:5
int m_nZPos
Definition: screensaver.c:41
#define MB_ICONWARNING
Definition: winuser.h:780
STAR * stars
Definition: screensaver.c:45
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_nYPos
Definition: screensaver.c:41
int m_nTotStars
Definition: screensaver.c:47
#define _T(x)
Definition: vfdio.h:22
#define RANDOM(min, max)
Definition: screensaver.c:27
#define MessageBox
Definition: winuser.h:5720
#define MAX_STARS
Definition: screensaver.c:36
int m_nOldY
Definition: screensaver.c:42
int m_nOldX
Definition: screensaver.c:42
#define MB_OK
Definition: winuser.h:784
#define malloc
Definition: debug_ros.c:4

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