Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

206 lines
3.0 KiB

  1. #ifdef PM
  2. #include <cstd.h>
  3. #define INCL_WIN
  4. #define INCL_GPI
  5. #include <os2.h>
  6. INT _acrtused = 0;
  7. #endif
  8. #ifdef WIN
  9. #include <windows.h>
  10. #include <port1632.h>
  11. #endif
  12. #include "std.h"
  13. #include "scrsave.h"
  14. INT rand();
  15. INT dxScreen, dyScreen;
  16. INT dxScreenD2, dyScreenD2;
  17. typedef struct _str
  18. {
  19. SHORT x, y, z;
  20. SHORT xo, yo;
  21. } STR;
  22. #define istrMax 64
  23. STR rgstr [istrMax];
  24. Animate(CVS hps);
  25. MakeStar(STR * pstr);
  26. SetPel(HDC hdc, INT x, INT y, INT brght);
  27. #define dzStep 4
  28. #define magic 256
  29. BOOL APIENTRY CoolProc(hwnd, wm, wParam, lParam)
  30. HWND hwnd;
  31. WORD wm;
  32. WPARAM wParam;
  33. LONG lParam;
  34. {
  35. switch (wm)
  36. {
  37. case WM_INITDIALOG:
  38. MessageBeep(0);
  39. MessageBeep(0);
  40. MessageBeep(0);
  41. MessageBeep(0);
  42. MessageBeep(0);
  43. MessageBeep(0);
  44. MessageBeep(0);
  45. return TRUE;
  46. case WM_COMMAND:
  47. EndDialog(hwnd, TRUE);
  48. return TRUE;
  49. }
  50. return FALSE;
  51. }
  52. BOOL EXPENTRY ScrSaveProc(INT ssm, LPVOID l1, LONG_PTR l2, LONG_PTR l3)
  53. {
  54. CHAR FAR * lpsz;
  55. CHAR FAR * lpch;
  56. switch (ssm)
  57. {
  58. default:
  59. return fFalse;
  60. case SSM_DIALOG:
  61. MessageBeep(0);
  62. MessageBeep(0);
  63. MessageBeep(0);
  64. MessageBeep(0);
  65. MessageBeep(0);
  66. MessageBeep(0);
  67. MessageBeep(0);
  68. /* {
  69. FARPROC lpproc;
  70. lpproc = MakeProcInstance(CoolProc, (HANDLE) l1);
  71. DialogBox((HANDLE) l1, "Cool", (HWND) l2, lpproc);
  72. FreeProcInstance(lpproc);
  73. }*/
  74. break;
  75. case SSM_OPEN:
  76. lpsz = (PSZ) l1;
  77. lpch = "Stars";
  78. while ((*lpsz++ = *lpch++) != '\0')
  79. ;
  80. lpsz = (PSZ) l2;
  81. lpch = "Drifting Through Space\n\nby Brad Christian";
  82. while ((*lpsz++ = *lpch++) != '\0')
  83. ;
  84. dxScreen = GetSystemMetrics(SM_CXSCREEN);
  85. dyScreen = GetSystemMetrics(SM_CYSCREEN);
  86. dxScreenD2 = dxScreen / 2;
  87. dyScreenD2 = dyScreen / 2;
  88. break;
  89. case SSM_ANIMATE:
  90. Animate((CVS) l1);
  91. break;
  92. }
  93. return fTrue;
  94. }
  95. Animate(CVS hps)
  96. {
  97. INT x, y;
  98. INT istr;
  99. STR * pstr;
  100. pstr = rgstr;
  101. for (istr = 0; istr < istrMax; istr += 1, pstr += 1)
  102. {
  103. if ((pstr->z -= dzStep) <= 0)
  104. MakeStar(pstr);
  105. x = pstr->x * magic / pstr->z + dxScreenD2;
  106. y = pstr->y * magic / pstr->z + dyScreenD2;
  107. SetPel(hps, pstr->xo, pstr->yo, 0);
  108. if (x < 0 || y < 0 || x >= dxScreen || y >= dyScreen)
  109. MakeStar(pstr);
  110. else
  111. {
  112. SetPel(hps, x, y, 256 - pstr->z);
  113. pstr->xo = (SHORT)x;
  114. pstr->yo = (SHORT)y;
  115. }
  116. }
  117. }
  118. MakeStar(STR * pstr)
  119. {
  120. pstr->x = WRand(dxScreen) - dxScreenD2;
  121. pstr->y = WRand(dyScreen) - dyScreenD2;
  122. pstr->z = WRand(256) + 1;
  123. }
  124. #ifdef PM
  125. LONG mpbrghtclr [] =
  126. {
  127. CLR_BLACK,
  128. CLR_DARKGRAY,
  129. CLR_PALEGRAY,
  130. CLR_WHITE,
  131. CLR_YELLOW
  132. };
  133. #endif
  134. #ifdef PM
  135. SetPel(HPS hps, INT x, INT y, INT brght)
  136. {
  137. RECTL rectl;
  138. rectl.xLeft = x;
  139. rectl.xRight = x + 1;
  140. rectl.yBottom = y;
  141. rectl.yTop = y + 1;
  142. if (brght != 0)
  143. {
  144. brght >>= 5; // 0 <= brght <= 7
  145. if (brght > 3)
  146. {
  147. rectl.xRight += 1;
  148. rectl.yTop += 1;
  149. brght >>= 1;
  150. }
  151. brght += 1;
  152. }
  153. else
  154. {
  155. rectl.xRight += 1;
  156. rectl.yTop += 1;
  157. }
  158. WinFillRect(hps, &rectl, mpbrghtclr[brght]);
  159. }
  160. #endif
  161. #ifdef WIN
  162. SetPel(HDC hdc, INT x, INT y, INT brght)
  163. {
  164. SetPixel(hdc, x, y, ((LONG) brght << 16) | (brght << 8) | brght);
  165. }
  166. #endif