home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / WINDOWS / APPS / FUSE.ZIP / FUSE.C next >
Encoding:
C/C++ Source or Header  |  1990-06-08  |  4.4 KB  |  226 lines

  1. #include <windows.h>
  2. #include "fuse2.h"
  3.  
  4. /*****************
  5.  
  6.         Brian's incredible Fuse app.
  7.  
  8.  
  9.         This program was compiled Win 3.0 SDK and MSC 6.0.
  10.  
  11.  
  12.  
  13.         Brian Farmer
  14.         Computer Science Center
  15.         University of Maryland
  16.         College Park,  MD 20742
  17.  
  18.         brianf@umd5.umd.edu
  19.  
  20.  
  21. ******************/
  22.  
  23.  
  24. #define max_fuses       40
  25.  
  26. HANDLE  hInst;
  27.  
  28. typedef struct FUSESTR
  29.         {
  30.                 int     x1, y1, x2, y2;
  31.                 BOOL    drawn;
  32.         } FUSE;
  33.  
  34. FUSE    fuses[max_fuses];
  35.  
  36. int     dx1, dy1, dx2, dy2, xextent, yextent;
  37. HWND    hDesk;
  38. HPEN    mypen;
  39. FARPROC oldproc;
  40.  
  41. long FAR PASCAL MyProc (HWND hWnd, WORD message, WORD wParam, LONG lParam)
  42.  
  43. {
  44.         if (message == WM_ERASEBKGND)
  45.                 ReDoLines ();
  46.  
  47.         CallWindowProc (oldproc, hWnd, message, wParam, lParam);
  48. }
  49.  
  50. void SetBack (HWND hWnd)
  51.  
  52. {
  53.  
  54.         oldproc = (FARPROC)GetWindowLong (hWnd, GWL_WNDPROC);
  55.  
  56.         SetWindowLong (hWnd, GWL_WNDPROC, (LONG)MakeProcInstance ((FARPROC)MyProc, hInst));
  57. }
  58.  
  59. void InitFuses(void)
  60. {
  61.  
  62.         int     i;
  63.         RECT    rect;
  64.  
  65.         hDesk = GetDesktopHwnd ();
  66.  
  67.         SetBack (hDesk);
  68.  
  69.         GetClientRect (hDesk, &rect);
  70.         yextent = rect.bottom-rect.top;
  71.         xextent = rect.right-rect.left;
  72.  
  73.         mypen = CreatePen (0, 1, RGB (255, 255, 255));
  74.  
  75.         for (i=0;i<max_fuses;i++)
  76.                 fuses[i].drawn = FALSE;
  77.  
  78.         fuses[max_fuses-1].x1 = xextent/2;
  79.         fuses[max_fuses-1].x2 = xextent/2 - 50;
  80.  
  81.         fuses[max_fuses-1].y1 = yextent/2;
  82.         fuses[max_fuses-1].y2 = yextent/2 - 50;
  83.  
  84.         dx1 = 10;
  85.         dy1 = 10;
  86.         dx2 = -10;
  87.         dy2 = -10;
  88. }
  89.  
  90. void DrawFuse (HDC hDC, FUSE *fuse)
  91.  
  92. {
  93.         MoveTo (hDC, fuse->x1, fuse->y1);
  94.         LineTo (hDC, fuse->x2, fuse->y2);
  95. }
  96.  
  97.  
  98. int MyRand ()
  99.  
  100. {
  101.         return (rand ()/3277);
  102. }
  103.  
  104. void MoveFuse (FUSE *previous, FUSE *tomove)
  105.  
  106. {
  107.         tomove->x1 = previous->x1 + dx1;
  108.         tomove->x2 = previous->x2 + dx2;
  109.         tomove->y1 = previous->y1 + dy1;
  110.         tomove->y2 = previous->y2 + dy2;
  111.  
  112.         if (tomove->x1 > xextent)
  113.                 dx1 = -MyRand ();
  114.  
  115.         if (tomove->x1 < 0)
  116.                 dx1 = MyRand ();
  117.  
  118.         if (tomove->x2 > xextent)
  119.                 dx2 = -MyRand ();
  120.  
  121.         if (tomove->x2 < 0)
  122.                 dx2 = MyRand ();
  123.  
  124.         if (tomove->y1 > yextent)
  125.                 dy1 = -MyRand ();
  126.  
  127.         if (tomove->y1 < 0)
  128.                 dy1 = MyRand ();
  129.  
  130.         if (tomove->y2 > yextent)
  131.                 dy2 = -MyRand ();
  132.  
  133.         if (tomove->y2 < 0)
  134.                 dy2 = MyRand ();
  135.  
  136. }
  137.  
  138. void ReDoLines ()
  139.  
  140. {
  141. static  int     current=0;
  142.         HDC     hDC;
  143.         int     oldrop, i;
  144.         HANDLE  oldpen;
  145.  
  146.         hDC = GetDC (hDesk);
  147.  
  148.         oldrop = SetROP2 (hDC, R2_XORPEN);
  149.         oldpen = SelectObject (hDC, mypen);
  150.  
  151.  
  152.         for (i=0; i<max_fuses;i++)
  153.         {
  154.                 if (fuses[i].drawn)
  155.                 {
  156.                         DrawFuse (hDC, &fuses[i]);
  157.                         fuses[i].drawn = FALSE;
  158.                 }
  159.         }
  160.  
  161.  
  162.         SetROP2 (hDC, oldrop);
  163.         SelectObject (hDC, oldpen);
  164.  
  165.         ReleaseDC (hDesk, hDC);
  166. }
  167.  
  168. void DoFuses ()
  169.  
  170. {
  171. static  int     current=0;
  172.         HDC     hDC;
  173.         int     oldrop;
  174.         HANDLE  oldpen;
  175.  
  176.         hDC = GetDC (hDesk);
  177.  
  178.         oldrop = SetROP2 (hDC, R2_XORPEN);
  179.         oldpen = SelectObject (hDC, mypen);
  180.  
  181.         if (fuses[current].drawn)
  182.                 DrawFuse (hDC, &fuses[current]);
  183.  
  184.         if (!current)
  185.                 MoveFuse (&fuses[max_fuses-1], &fuses[0]);
  186.         else
  187.                 MoveFuse (&fuses[current-1], &fuses[current]);
  188.  
  189.  
  190.         DrawFuse (hDC, &fuses[current]);
  191.  
  192.         fuses[current].drawn = TRUE;
  193.  
  194.         current = ++current % max_fuses;
  195.  
  196.         SetROP2 (hDC, oldrop);
  197.         SelectObject (hDC, oldpen);
  198.  
  199.         ReleaseDC (hDesk, hDC);
  200. }
  201.  
  202.  
  203. long PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  204.  
  205. HANDLE hInstance, hPrevInstance;
  206. LPSTR  lpszCmdLine;
  207. int    cmdShow;
  208.  
  209.  
  210. {
  211.         MSG     msg;
  212.         BOOL    ext = FALSE;
  213.  
  214.  
  215.         hInst = hInstance;
  216.  
  217.         InitFuses ();
  218.  
  219.         while (TRUE)
  220.         {
  221.                 PeekMessage( (LPMSG)&msg, 0, 0, 0, PM_REMOVE);
  222.                 DoFuses ();
  223.         }
  224. }
  225.  
  226.