- Compile screensavers as UNICODE applications + minor fixes (Part 2/2)
authorMarc Piulachs <marc.piulachs@live.com>
Mon, 29 Oct 2007 22:52:33 +0000 (22:52 +0000)
committerMarc Piulachs <marc.piulachs@live.com>
Mon, 29 Oct 2007 22:52:33 +0000 (22:52 +0000)
svn path=/trunk/; revision=29966

rosapps/applications/screensavers/cylfrac/cylfrac.c
rosapps/applications/screensavers/cylfrac/cylfrac.rbuild
rosapps/applications/screensavers/matrix/matrix.rbuild
rosapps/applications/screensavers/matrix/screensave.c
rosapps/applications/screensavers/scrnsave/scrnsave.c
rosapps/applications/screensavers/scrnsave/scrnsave.rbuild
rosapps/applications/screensavers/starfield/screensaver.c
rosapps/applications/screensavers/starfield/starfield.rbuild

index db5f51b..cb06fa1 100644 (file)
@@ -236,26 +236,25 @@ void InitSaver(HWND hwndParent)
        }
 }
 
-void ParseCommandLine(PSTR szCmdLine, int *chOption, HWND *hwndParent)
+//
+//     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)
 {
-       int ch;
-
-       if (!strlen(szCmdLine))
-               return;
-
-       ch = *szCmdLine++;
+       UCHAR ch = *szCmdLine++;
 
        if(ch == '-' || ch == '/')
                ch = *szCmdLine++;
 
        if(ch >= 'A' && ch <= 'Z')
-               ch += 'a' - 'A';
+               ch += 'a' - 'A';                //convert to lower case
 
        *chOption = ch;
-
-       if (ch == 's' || ch == 'c')
-               return;
-
        ch = *szCmdLine++;
 
        if(ch == ':')
@@ -266,11 +265,11 @@ void ParseCommandLine(PSTR szCmdLine, int *chOption, HWND *hwndParent)
 
        if(isdigit(ch))
        {
-               unsigned int i = atoi(szCmdLine - 1);
+               unsigned int i = _wtoi(szCmdLine - 1);
                *hwndParent = (HWND)i;
        }
        else
-               *hwndParent = 0;
+               *hwndParent = NULL;
 }
 
 void Configure(void)
@@ -294,13 +293,13 @@ void Configure(void)
                   MB_OK | MB_ICONWARNING);
 }
 
-int WINAPI WinMain (HINSTANCE hInst,
+int CALLBACK wWinMain (HINSTANCE hInst,
                     HINSTANCE hPrev,
-                    LPSTR lpCmdLine,
+                    LPWSTR lpCmdLine,
                     int iCmdShow)
 {
        HWND    hwndParent = 0;
-       int     chOption = 0;
+       UCHAR   chOption;
        MSG     Message;
 
        hInstance = hInst;
index e9ac5d4..1c73bba 100644 (file)
@@ -1,9 +1,6 @@
 <?xml version="1.0"?>
 <!DOCTYPE module SYSTEM "../../../../tools/rbuild/project.dtd">
-<module name="cylfrac" type="win32scr" installbase="system32" installname="cylfrac.scr">
-       <define name="UNICODE" />
-       <define name="_UNICODE" />
-
+<module name="cylfrac" type="win32scr" installbase="system32" installname="cylfrac.scr" unicode="true">
        <library>kernel32</library>
        <library>user32</library>
        <library>gdi32</library>
index 166e46b..ab206d0 100644 (file)
@@ -1,13 +1,9 @@
 <?xml version="1.0"?>
 <!DOCTYPE module SYSTEM "../../../../tools/rbuild/project.dtd">
-<module name="matrix" type="win32scr" installbase="system32" installname="matrix2.scr" allowwarnings="true">
+<module name="matrix" type="win32scr" installbase="system32" installname="matrix2.scr" allowwarnings="true" unicode="true">
        <include base="matrix">.</include>
-
        <define name="_WIN32_IE">0x0501</define>
        <define name="_WIN32_WINNT">0x0501</define>
-       <define name="UNICODE" />
-       <define name="_UNICODE" />
-
        <library>kernel32</library>
        <library>user32</library>
        <library>gdi32</library>
index 3c771fe..adfc9d9 100644 (file)
@@ -100,7 +100,7 @@ BOOL ScreenSaver(HWND hwndParent)
 //  -p <hwnd>          (preview)
 //  -c <hwnd>          (configure)
 //
-VOID ParseCommandLine(LPSTR szCmdLine, UCHAR *chOption, HWND *hwndParent)
+VOID ParseCommandLine(LPWSTR szCmdLine, UCHAR *chOption, HWND *hwndParent)
 {
        UCHAR ch = *szCmdLine++;
 
@@ -121,7 +121,7 @@ VOID ParseCommandLine(LPSTR szCmdLine, UCHAR *chOption, HWND *hwndParent)
 
        if(isdigit(ch))
        {
-               unsigned int i = atoi(szCmdLine - 1);
+               unsigned int i = _wtoi(szCmdLine - 1);
                *hwndParent = (HWND)i;
        }
        else
@@ -131,7 +131,7 @@ VOID ParseCommandLine(LPSTR szCmdLine, UCHAR *chOption, HWND *hwndParent)
 //
 //     Entrypoint for screen-saver: it's just a normal win32 app!
 //
-int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, int iCmdShow)
+int CALLBACK wWinMain (HINSTANCE hInst, HINSTANCE hPrev, LPWSTR lpCmdLine, int iCmdShow)
 {
        HWND   hwndParent;
        UCHAR  chOption;
index 06579d8..93eb763 100644 (file)
-/*\r
- *  Copyright 2003 J Brown\r
- *  Copyright 2006 Eric Kohl\r
- *\r
- *  This program is free software; you can redistribute it and/or modify\r
- *  it under the terms of the GNU General Public License as published by\r
- *  the Free Software Foundation; either version 2 of the License, or\r
- *  (at your option) any later version.\r
- *\r
- *  This program is distributed in the hope that it will be useful,\r
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- *  GNU General Public License for more details.\r
- *\r
- *  You should have received a copy of the GNU General Public License\r
- *  along with this program; if not, write to the Free Software\r
- *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA\r
- */\r
-\r
-#include <windows.h>\r
-#include <tchar.h>\r
-#include "resource.h"\r
-\r
-#define APPNAME _T("Scrnsave")\r
-\r
-\r
-HINSTANCE hInstance;\r
-\r
-BOOL fullscreen = FALSE;\r
-\r
-\r
-LRESULT WINAPI WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)\r
-{\r
-       static POINT ptLast;\r
-       static POINT ptCursor;\r
-       static BOOL  fFirstTime = TRUE;\r
-\r
-       switch (msg)\r
-       {\r
-               case WM_DESTROY:\r
-                 ShowCursor(TRUE);\r
-                       PostQuitMessage(0);\r
-                       break;\r
-\r
-               // break out of screen-saver if any keyboard activity\r
-               case WM_NOTIFY:\r
-               case WM_SYSKEYDOWN:\r
-                       PostMessage(hwnd, WM_CLOSE, 0, 0);\r
-                       break;\r
-\r
-               // break out of screen-saver if any mouse activity\r
-               case WM_LBUTTONDOWN:\r
-               case WM_LBUTTONUP:\r
-               case WM_RBUTTONDOWN:\r
-               case WM_RBUTTONUP:\r
-               case WM_MBUTTONDOWN:\r
-               case WM_MBUTTONUP:\r
-               case WM_MOUSEMOVE:\r
-                       // If we've got a parent then we must be a preview\r
-                       if(GetParent(hwnd) != 0)\r
-                               return 0;\r
-\r
-                       if(fFirstTime)\r
-                       {\r
-                               GetCursorPos(&ptLast);\r
-                               fFirstTime = FALSE;\r
-                       }\r
-\r
-               GetCursorPos(&ptCursor);\r
-\r
-               // if the mouse has moved more than 3 pixels then exit\r
-               if(abs(ptCursor.x - ptLast.x) >= 3 || abs(ptCursor.y - ptLast.y) >= 3)\r
-                       PostMessage(hwnd, WM_CLOSE, 0, 0);\r
-\r
-               ptLast = ptCursor;\r
-\r
-               return 0;\r
-       }\r
-\r
-       return DefWindowProc(hwnd, msg, wParam, lParam);\r
-}\r
-\r
-void InitSaver(HWND hwndParent)\r
-{\r
-       WNDCLASS wc;\r
-       ZeroMemory(&wc, sizeof(wc));\r
-       wc.style            = CS_HREDRAW | CS_VREDRAW;\r
-       wc.lpfnWndProc      = WndProc;\r
-       wc.lpszClassName    = APPNAME;\r
-       wc.hbrBackground    = (HBRUSH)GetStockObject(BLACK_BRUSH);\r
-       RegisterClass(&wc);\r
-\r
-       if (hwndParent != 0)\r
-       {\r
-               RECT rect;\r
-               GetClientRect(hwndParent, &rect);\r
-               CreateWindow(APPNAME, APPNAME,\r
-                            WS_VISIBLE | WS_CHILD,\r
-                            0, 0,\r
-                            rect.right,\r
-                            rect.bottom,\r
-                            hwndParent, 0,\r
-                            hInstance, NULL);\r
-               fullscreen = FALSE;\r
-       }\r
-       else\r
-       {\r
-               HWND hwnd;\r
-    hwnd = CreateWindowEx(WS_EX_TOPMOST,\r
-                          APPNAME,\r
-                          APPNAME,\r
-                          WS_VISIBLE | WS_POPUP,\r
-                          0, 0,\r
-                          GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN),\r
-                          HWND_DESKTOP, 0,\r
-                          hInstance, NULL);\r
-\r
-    SetWindowPos(hwnd,\r
-                 0, 0, 0, 0, 0,\r
-                 SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_SHOWWINDOW);\r
-\r
-               ShowCursor(FALSE);\r
-               fullscreen = TRUE;\r
-       }\r
-}\r
-\r
-void ParseCommandLine(PSTR szCmdLine, int *chOption, HWND *hwndParent)\r
-{\r
-       int ch = *szCmdLine++;\r
-\r
-       if(ch == '-' || ch == '/')\r
-               ch = *szCmdLine++;\r
-\r
-       if(ch >= 'A' && ch <= 'Z')\r
-               ch += 'a' - 'A';\r
-\r
-       *chOption = ch;\r
-       ch = *szCmdLine++;\r
-\r
-       if(ch == ':')\r
-               ch = *szCmdLine++;\r
-\r
-       while(ch == ' ' || ch == '\t')\r
-               ch = *szCmdLine++;\r
-\r
-       if(isdigit(ch))\r
-       {\r
-               unsigned int i = atoi(szCmdLine - 1);\r
-               *hwndParent = (HWND)i;\r
-       }\r
-       else\r
-               *hwndParent = 0;\r
-}\r
-\r
-void Configure(void)\r
-{\r
-       TCHAR szTitle[256];\r
-       TCHAR szText[256];\r
-\r
-       LoadString(hInstance,\r
-                  IDS_TITLE,\r
-                  szTitle,\r
-                  256);\r
-\r
-       LoadString(hInstance,\r
-                  IDS_TEXT,\r
-                  szText,\r
-                  256);\r
-\r
-       MessageBox(0,\r
-                  szText,\r
-                  szTitle,\r
-                  MB_OK | MB_ICONWARNING);\r
-}\r
-\r
-\r
-int WINAPI WinMain (HINSTANCE hInst,\r
-                    HINSTANCE hPrev,\r
-                    LPSTR lpCmdLine,\r
-                    int iCmdShow)\r
-{\r
-       HWND    hwndParent;\r
-       UINT    nPreviousState;\r
-       int     chOption;\r
-       MSG     Message;\r
-\r
-       hInstance = hInst;\r
-\r
-       ParseCommandLine(lpCmdLine, &chOption, &hwndParent);\r
-\r
-       SystemParametersInfo(SPI_SETSCREENSAVERRUNNING, TRUE, &nPreviousState, 0);\r
-\r
-       switch (chOption)\r
-       {\r
-               case 's':\r
-                       InitSaver(0);\r
-                       break;\r
-\r
-               case 'p':\r
-                       InitSaver(hwndParent);\r
-                       break;\r
-\r
-               case 'c':\r
-               default:\r
-                       Configure();\r
-                       return 0;\r
-       }\r
-\r
-       while (GetMessage(&Message, 0, 0, 0))\r
-               DispatchMessage(&Message);\r
-\r
-       SystemParametersInfo(SPI_SETSCREENSAVERRUNNING, FALSE, &nPreviousState, 0);\r
-\r
-       return Message.wParam;\r
-}\r
+/*
+ *  Copyright 2003 J Brown
+ *  Copyright 2006 Eric Kohl
+ *
+ *  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.
+ *
+ *  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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#include <windows.h>
+#include <tchar.h>
+#include "resource.h"
+
+#define APPNAME _T("Scrnsave")
+
+
+HINSTANCE hInstance;
+
+BOOL fullscreen = FALSE;
+
+
+LRESULT WINAPI WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+       static POINT ptLast;
+       static POINT ptCursor;
+       static BOOL  fFirstTime = TRUE;
+
+       switch (msg)
+       {
+               case WM_DESTROY:
+                 ShowCursor(TRUE);
+                       PostQuitMessage(0);
+                       break;
+
+               // break out of screen-saver if any keyboard activity
+               case WM_NOTIFY:
+               case WM_SYSKEYDOWN:
+                       PostMessage(hwnd, WM_CLOSE, 0, 0);
+                       break;
+
+               // 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)
+{
+       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;
+       }
+}
+
+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)
+{
+       TCHAR szTitle[256];
+       TCHAR szText[256];
+
+       LoadString(hInstance,
+                  IDS_TITLE,
+                  szTitle,
+                  256);
+
+       LoadString(hInstance,
+                  IDS_TEXT,
+                  szText,
+                  256);
+
+       MessageBox(0,
+                  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;
+}
index 67832a1..5e71884 100644 (file)
@@ -1,16 +1,13 @@
-<?xml version="1.0"?>\r
-<!DOCTYPE module SYSTEM "../../../../tools/rbuild/project.dtd">\r
-<module name="scrnsave" type="win32scr" installbase="system32" installname="scrnsave.scr">\r
-       <define name="UNICODE" />\r
-       <define name="_UNICODE" />\r
-\r
-       <library>kernel32</library>\r
-       <library>user32</library>\r
-       <library>gdi32</library>\r
-       <library>opengl32</library>\r
-       <library>glu32</library>\r
-       <library>winmm</library>\r
-\r
-       <file>scrnsave.c</file>\r
-       <file>scrnsave.rc</file>\r
-</module>\r
+<?xml version="1.0"?>
+<!DOCTYPE module SYSTEM "../../../../tools/rbuild/project.dtd">
+<module name="scrnsave" type="win32scr" installbase="system32" installname="scrnsave.scr" unicode="true">
+       <library>kernel32</library>
+       <library>user32</library>
+       <library>gdi32</library>
+       <library>opengl32</library>
+       <library>glu32</library>
+       <library>winmm</library>
+
+       <file>scrnsave.c</file>
+       <file>scrnsave.rc</file>
+</module>
index d0e91e9..ca53bf2 100644 (file)
-/*\r
- *  Copyright 2003 J Brown\r
- *  Copyright 2006 Eric Kohl\r
- *  Copyright 2007 Marc Piulachs (marc.piulachs@codexchange.net)\r
- *\r
- *  This program is free software; you can redistribute it and/or modify\r
- *  it under the terms of the GNU General Public License as published by\r
- *  the Free Software Foundation; either version 2 of the License, or\r
- *  (at your option) any later version.\r
- *\r
- *  This program is distributed in the hope that it will be useful,\r
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- *  GNU General Public License for more details.\r
- *\r
- *  You should have received a copy of the GNU General Public License\r
- *  along with this program; if not, write to the Free Software\r
- *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA\r
- */\r
-\r
-#include <windows.h>\r
-#include <tchar.h>\r
-#include "resource.h"\r
-\r
-#define RANDOM( min, max ) ((rand() % (int)(((max)+1) - (min))) + (min))\r
-\r
-#define MAX_LOADSTRING 100\r
-#define MAX_STARS 1000\r
-\r
-#define APPNAME                                _T("Starfield")\r
-#define APP_TIMER                      1\r
-#define APP_TIMER_INTERVAL     20\r
-\r
-#define MAX_STARS 1000\r
-\r
-// Details of each individual star\r
-typedef struct star\r
-{\r
-       int m_nXPos, m_nYPos, m_nZPos;\r
-       int m_nOldX, m_nOldY;\r
-} STAR;\r
-\r
-HINSTANCE hInstance;\r
-BOOL fullscreen = FALSE;\r
-\r
-STAR *stars;\r
-\r
-int            m_nTotStars;\r
-int            m_nCenterX, m_nCenterY;\r
-\r
-void DrawStarField (HDC pDC)\r
-{\r
-       int nX, nY;\r
-       int i;\r
-       for (i = 0; i < m_nTotStars; i++)\r
-       {\r
-               //      Clear last position of this star\r
-               SetPixel (\r
-                       pDC,\r
-                       stars[i].m_nOldX,\r
-                       stars[i].m_nOldY,\r
-                       RGB (0, 0, 0));\r
-\r
-               nX = (int)((((long)stars[i].m_nXPos << 7) / (long)stars[i].m_nZPos) + m_nCenterX);\r
-               nY = (int)((((long)stars[i].m_nYPos << 7) / (long)stars[i].m_nZPos) + m_nCenterY);\r
-\r
-               // Draw star\r
-               SetPixel (\r
-                       pDC,\r
-                       nX,\r
-                       nY,\r
-                       RGB (255, 255, 255));\r
-\r
-               // Remember current position for clearing later\r
-               stars[i].m_nOldX = nX;\r
-               stars[i].m_nOldY = nY;\r
-       }\r
-}\r
-\r
-BOOL SetUpStars (int nNumStars)\r
-{\r
-       int i;\r
-       if (nNumStars > MAX_STARS)\r
-       {\r
-               MessageBox (0,\r
-                       _T("Too many stars! Aborting!"),\r
-                       _T("Error"),\r
-                       MB_OK | MB_ICONWARNING);\r
-               return FALSE;\r
-       }\r
-\r
-       if (stars)\r
-               free (stars);\r
-\r
-       m_nTotStars = nNumStars;\r
-\r
-       stars = (STAR*)malloc(nNumStars * sizeof(STAR));\r
-\r
-       if (!stars)\r
-       {\r
-               MessageBox (0,\r
-                       _T("Unable to allocate memory! Aborting!"),\r
-                       _T("Error"),\r
-                       MB_OK | MB_ICONWARNING);\r
-               return FALSE;\r
-       }\r
-\r
-       for (i = 0; i < m_nTotStars; i++)\r
-       {\r
-               do\r
-               {\r
-                       stars[i].m_nXPos = RANDOM (-320, 320);\r
-                       stars[i].m_nYPos = RANDOM (-200, 200);\r
-                       stars[i].m_nZPos = i+1;\r
-                       stars[i].m_nOldX = -1;\r
-                       stars[i].m_nOldY = -1;\r
-               } while ((stars[i].m_nXPos == 0) || (stars[i].m_nYPos == 0));\r
-       }\r
-\r
-       return TRUE;\r
-}\r
-\r
-void MoveStarField (int nXofs, int nYofs, int nZofs)\r
-{\r
-       int i;\r
-       for (i = 0; i < m_nTotStars; i++)\r
-       {\r
-               stars[i].m_nXPos += nXofs;\r
-               stars[i].m_nYPos += nYofs;\r
-               stars[i].m_nZPos += nZofs;\r
-\r
-               if (stars[i].m_nZPos > m_nTotStars)\r
-                       stars[i].m_nZPos -= m_nTotStars;\r
-               if (stars[i].m_nZPos < 1)\r
-                       stars[i].m_nZPos += m_nTotStars;\r
-       }\r
-}\r
-\r
-void SetDimensions (int nWidth, int nHeight)\r
-{\r
-       m_nCenterX = nWidth / 2;\r
-       m_nCenterY = nHeight / 2;\r
-}\r
-\r
-LRESULT WINAPI WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)\r
-{\r
-       static POINT ptLast;\r
-       static POINT ptCursor;\r
-       static BOOL  fFirstTime = TRUE;\r
-       static HDC pDC;\r
-\r
-       switch (msg)\r
-       {\r
-               case WM_CREATE :\r
-               {\r
-                       SetTimer (\r
-                               hwnd,\r
-                               APP_TIMER,\r
-                               APP_TIMER_INTERVAL,\r
-                               NULL);\r
-               }\r
-               break;\r
-               case WM_PAINT :\r
-               {\r
-                       PAINTSTRUCT     PtStr;\r
-                       HDC pDC = BeginPaint (hwnd, &PtStr);\r
-                       DrawStarField (pDC);\r
-                       EndPaint (hwnd, &PtStr);\r
-                       return (0);\r
-               }\r
-               break;\r
-               case WM_TIMER :\r
-               {\r
-                       if (wParam == APP_TIMER)\r
-                       {\r
-                               MoveStarField (0, 0, -3);\r
-                               pDC = GetDC(hwnd);\r
-                               DrawStarField (pDC);\r
-                               ReleaseDC(hwnd, pDC);\r
-                       }\r
-               }\r
-               break;\r
-               case WM_SIZE :\r
-               {\r
-                       //      Change the center point of the starfield\r
-                       SetDimensions (\r
-                               LOWORD(lParam),\r
-                               HIWORD(lParam));\r
-               }\r
-               break;\r
-               case WM_DESTROY :\r
-               {\r
-                       KillTimer (hwnd, APP_TIMER);\r
-                       free(stars);\r
-                       ShowCursor(TRUE);\r
-                       PostQuitMessage (0);\r
-                       return 0;\r
-               }\r
-               break;\r
-               // break out of screen-saver if any keyboard activity\r
-               case WM_NOTIFY:\r
-               case WM_SYSKEYDOWN:\r
-               {\r
-                       PostMessage(hwnd, WM_CLOSE, 0, 0);\r
-                       break;\r
-               }\r
-               // break out of screen-saver if any mouse activity\r
-               case WM_LBUTTONDOWN:\r
-               case WM_LBUTTONUP:\r
-               case WM_RBUTTONDOWN:\r
-               case WM_RBUTTONUP:\r
-               case WM_MBUTTONDOWN:\r
-               case WM_MBUTTONUP:\r
-               case WM_MOUSEMOVE:\r
-               {\r
-                       // If we've got a parent then we must be a preview\r
-                       if(GetParent(hwnd) != 0)\r
-                               return 0;\r
-\r
-                       if(fFirstTime)\r
-                       {\r
-                               GetCursorPos(&ptLast);\r
-                               fFirstTime = FALSE;\r
-                       }\r
-\r
-                       GetCursorPos(&ptCursor);\r
-\r
-                       // if the mouse has moved more than 3 pixels then exit\r
-                       if( (abs(ptCursor.x - ptLast.x) >= 3) ||\r
-                               (abs(ptCursor.y - ptLast.y) >= 3))\r
-                       {\r
-                               PostMessage(hwnd, WM_CLOSE, 0, 0);\r
-                       }\r
-\r
-                       ptLast = ptCursor;\r
-                       return 0;\r
-               }\r
-       }\r
-\r
-       return DefWindowProc(hwnd, msg, wParam, lParam);\r
-}\r
-\r
-\r
-void InitSaver(HWND hwndParent)\r
-{\r
-       WNDCLASS wc;\r
-       ZeroMemory(&wc, sizeof(wc));\r
-       wc.style            = CS_HREDRAW | CS_VREDRAW;\r
-       wc.lpfnWndProc      = WndProc;\r
-       wc.lpszClassName    = APPNAME;\r
-       wc.hbrBackground    = (HBRUSH)GetStockObject(BLACK_BRUSH);\r
-       RegisterClass(&wc);\r
-\r
-       if (hwndParent != 0)\r
-       {\r
-               RECT rect;\r
-               GetClientRect(hwndParent, &rect);\r
-               CreateWindow(APPNAME, APPNAME,\r
-                            WS_VISIBLE | WS_CHILD,\r
-                            0, 0,\r
-                            rect.right,\r
-                            rect.bottom,\r
-                            hwndParent, 0,\r
-                            hInstance, NULL);\r
-               fullscreen = FALSE;\r
-       }\r
-       else\r
-       {\r
-               HWND hwnd;\r
-               hwnd = CreateWindowEx(WS_EX_TOPMOST,\r
-                          APPNAME,\r
-                          APPNAME,\r
-                          WS_VISIBLE | WS_POPUP,\r
-                          0, 0,\r
-                          GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN),\r
-                          HWND_DESKTOP, 0,\r
-                          hInstance, NULL);\r
-\r
-    SetWindowPos(hwnd,\r
-                 0, 0, 0, 0, 0,\r
-                 SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOSIZE|SWP_SHOWWINDOW);\r
-\r
-               ShowCursor(FALSE);\r
-               fullscreen = TRUE;\r
-       }\r
-\r
-    SetUpStars(250);\r
-}\r
-\r
-void ParseCommandLine(PSTR szCmdLine, int *chOption, HWND *hwndParent)\r
-{\r
-       int ch = *szCmdLine++;\r
-\r
-       if(ch == '-' || ch == '/')\r
-               ch = *szCmdLine++;\r
-\r
-       if(ch >= 'A' && ch <= 'Z')\r
-               ch += 'a' - 'A';\r
-\r
-       *chOption = ch;\r
-       ch = *szCmdLine++;\r
-\r
-       if(ch == ':')\r
-               ch = *szCmdLine++;\r
-\r
-       while(ch == ' ' || ch == '\t')\r
-               ch = *szCmdLine++;\r
-\r
-       if(isdigit(ch))\r
-       {\r
-               unsigned int i = atoi(szCmdLine - 1);\r
-               *hwndParent = (HWND)i;\r
-       }\r
-       else\r
-               *hwndParent = 0;\r
-}\r
-\r
-void Configure(void)\r
-{\r
-       TCHAR szTitle[256];\r
-       TCHAR szText[256];\r
-\r
-       LoadString(hInstance,\r
-                  IDS_TITLE,\r
-                  szTitle,\r
-                  256);\r
-\r
-       LoadString(hInstance,\r
-                  IDS_TEXT,\r
-                  szText,\r
-                  256);\r
-\r
-       MessageBox(0,\r
-                  szText,\r
-                  szTitle,\r
-                  MB_OK | MB_ICONWARNING);\r
-}\r
-\r
-int WINAPI WinMain (HINSTANCE hInst,\r
-                    HINSTANCE hPrev,\r
-                    LPSTR lpCmdLine,\r
-                    int iCmdShow)\r
-{\r
-       HWND    hwndParent;\r
-       UINT    nPreviousState;\r
-       int     chOption;\r
-       MSG     Message;\r
-\r
-       hInstance = hInst;\r
-\r
-       ParseCommandLine(lpCmdLine, &chOption, &hwndParent);\r
-\r
-       SystemParametersInfo(SPI_SETSCREENSAVERRUNNING, TRUE, &nPreviousState, 0);\r
-\r
-       switch (chOption)\r
-       {\r
-               case 's':\r
-                       InitSaver(0);\r
-                       break;\r
-\r
-               case 'p':\r
-                       InitSaver(hwndParent);\r
-                       break;\r
-\r
-               case 'c':\r
-               default:\r
-                       Configure();\r
-                       return 0;\r
-       }\r
-\r
-       while (GetMessage(&Message, 0, 0, 0))\r
-               DispatchMessage(&Message);\r
-\r
-       SystemParametersInfo(SPI_SETSCREENSAVERRUNNING, FALSE, &nPreviousState, 0);\r
-\r
-       return Message.wParam;\r
-}\r
+/*
+ *  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.
+ *
+ *  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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#include <windows.h>
+#include <tchar.h>
+#include "resource.h"
+
+#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
+
+// Details of each individual star
+typedef struct star
+{
+       int m_nXPos, m_nYPos, m_nZPos;
+       int m_nOldX, m_nOldY;
+} STAR;
+
+HINSTANCE hInstance;
+BOOL fullscreen = FALSE;
+
+STAR *stars;
+
+int            m_nTotStars;
+int            m_nCenterX, m_nCenterY;
+
+void DrawStarField (HDC pDC)
+{
+       int nX, nY;
+       int i;
+       for (i = 0; i < m_nTotStars; i++)
+       {
+               //      Clear last position of this star
+               SetPixel (
+                       pDC,
+                       stars[i].m_nOldX,
+                       stars[i].m_nOldY,
+                       RGB (0, 0, 0));
+
+               nX = (int)((((long)stars[i].m_nXPos << 7) / (long)stars[i].m_nZPos) + m_nCenterX);
+               nY = (int)((((long)stars[i].m_nYPos << 7) / (long)stars[i].m_nZPos) + m_nCenterY);
+
+               // Draw star
+               SetPixel (
+                       pDC,
+                       nX,
+                       nY,
+                       RGB (255, 255, 255));
+
+               // Remember current position for clearing later
+               stars[i].m_nOldX = nX;
+               stars[i].m_nOldY = nY;
+       }
+}
+
+BOOL SetUpStars (int nNumStars)
+{
+       int i;
+       if (nNumStars > MAX_STARS)
+       {
+               MessageBox (0,
+                       _T("Too many stars! Aborting!"),
+                       _T("Error"),
+                       MB_OK | MB_ICONWARNING);
+               return FALSE;
+       }
+
+       if (stars)
+               free (stars);
+
+       m_nTotStars = nNumStars;
+
+       stars = (STAR*)malloc(nNumStars * sizeof(STAR));
+
+       if (!stars)
+       {
+               MessageBox (0,
+                       _T("Unable to allocate memory! Aborting!"),
+                       _T("Error"),
+                       MB_OK | MB_ICONWARNING);
+               return FALSE;
+       }
+
+       for (i = 0; i < m_nTotStars; i++)
+       {
+               do
+               {
+                       stars[i].m_nXPos = RANDOM (-320, 320);
+                       stars[i].m_nYPos = RANDOM (-200, 200);
+                       stars[i].m_nZPos = i+1;
+                       stars[i].m_nOldX = -1;
+                       stars[i].m_nOldY = -1;
+               } while ((stars[i].m_nXPos == 0) || (stars[i].m_nYPos == 0));
+       }
+
+       return TRUE;
+}
+
+void MoveStarField (int nXofs, int nYofs, int nZofs)
+{
+       int i;
+       for (i = 0; i < m_nTotStars; i++)
+       {
+               stars[i].m_nXPos += nXofs;
+               stars[i].m_nYPos += nYofs;
+               stars[i].m_nZPos += nZofs;
+
+               if (stars[i].m_nZPos > m_nTotStars)
+                       stars[i].m_nZPos -= m_nTotStars;
+               if (stars[i].m_nZPos < 1)
+                       stars[i].m_nZPos += m_nTotStars;
+       }
+}
+
+void SetDimensions (int nWidth, int nHeight)
+{
+       m_nCenterX = nWidth / 2;
+       m_nCenterY = nHeight / 2;
+}
+
+LRESULT WINAPI WndProc(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 :
+               {
+                       SetTimer (
+                               hwnd,
+                               APP_TIMER,
+                               APP_TIMER_INTERVAL,
+                               NULL);
+               }
+               break;
+               case WM_PAINT :
+               {
+                       PAINTSTRUCT     PtStr;
+                       HDC pDC = BeginPaint (hwnd, &PtStr);
+                       DrawStarField (pDC);
+                       EndPaint (hwnd, &PtStr);
+                       return (0);
+               }
+               break;
+               case WM_TIMER :
+               {
+                       if (wParam == APP_TIMER)
+                       {
+                               MoveStarField (0, 0, -3);
+                               pDC = GetDC(hwnd);
+                               DrawStarField (pDC);
+                               ReleaseDC(hwnd, pDC);
+                       }
+               }
+               break;
+               case WM_SIZE :
+               {
+                       //      Change the center point of the starfield
+                       SetDimensions (
+                               LOWORD(lParam),
+                               HIWORD(lParam));
+               }
+               break;
+               case WM_DESTROY :
+               {
+                       KillTimer (hwnd, APP_TIMER);
+                       free(stars);
+                       ShowCursor(TRUE);
+                       PostQuitMessage (0);
+                       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;
+               }
+               // 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)
+{
+       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);
+}
+
+//
+//     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)
+{
+       TCHAR szTitle[256];
+       TCHAR szText[256];
+
+       LoadString(hInstance,
+                  IDS_TITLE,
+                  szTitle,
+                  256);
+
+       LoadString(hInstance,
+                  IDS_TEXT,
+                  szText,
+                  256);
+
+       MessageBox(0,
+                  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;
+}
index ddec386..1244d1c 100644 (file)
@@ -1,15 +1,12 @@
-<?xml version="1.0"?>\r
-<!DOCTYPE module SYSTEM "../../../../tools/rbuild/project.dtd">\r
-<module name="starfield" type="win32scr" installbase="system32" installname="starfield.scr">\r
-       <define name="UNICODE" />\r
-       <define name="_UNICODE" />\r
-\r
-       <library>kernel32</library>\r
-       <library>user32</library>\r
-       <library>gdi32</library>\r
-\r
-       <metadata description = "Starfield simulation screensaver" />\r
-\r
-       <file>screensaver.c</file>\r
-       <file>starfield.rc</file>\r
-</module>\r
+<?xml version="1.0"?>
+<!DOCTYPE module SYSTEM "../../../../tools/rbuild/project.dtd">
+<module name="starfield" type="win32scr" installbase="system32" installname="starfield.scr" unicode="true">
+       <library>kernel32</library>
+       <library>user32</library>
+       <library>gdi32</library>
+
+       <metadata description = "Starfield simulation screensaver" />
+
+       <file>screensaver.c</file>
+       <file>starfield.rc</file>
+</module>