home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / pcmagazi / 1992 / 17 / bugs / bugsbc.c < prev    next >
C/C++ Source or Header  |  1992-09-24  |  19KB  |  622 lines

  1. //========================================================================
  2. //       Bugsbc.c - A screen saver that does not need SCRNSAVE.LIB 
  3. //  
  4. //        Douglas Boling
  5. //
  6. //        Copyright (c) 1992 Doulgas Boling
  7. //========================================================================
  8.  
  9. #include <windows.h>
  10.  
  11. //------------------------------------------------------------------------
  12. //Includes specific to Bugs
  13. //------------------------------------------------------------------------
  14. #include "bugsbc.h"
  15. #include <stdlib.h>
  16. #include <string.h>
  17.  
  18. //------------------------------------------------------------------------
  19. //Function prototypes used by all screen savers
  20. //------------------------------------------------------------------------
  21. BOOL    RegisterDialogClasses (HANDLE hInst);
  22. LONG FAR PASCAL ScreenSaverProc(HWND, WORD, WORD, LONG);
  23. extern BOOL FAR PASCAL ScreenSaverConfigureDialog(HWND hDlg, WORD msg, 
  24.                                                   WORD wParam, LONG lParam);
  25. LONG FAR PASCAL DefScreenSaverProc(HWND, unsigned, WORD, LONG);
  26.  
  27. //------------------------------------------------------------------------
  28. //Function prototypes used by Bugs
  29. //------------------------------------------------------------------------
  30. BOOL FAR PASCAL AboutDlgProc(HWND, WORD, WORD, LONG);
  31. void BugSmarts (HWND);
  32. void GetProfile (void);
  33. void SetText (HWND, int, int, char*);
  34. int BugCmp (const BUGSTRUCT *, const BUGSTRUCT *);
  35.  
  36. //------------------------------------------------------------------------
  37. //Global Data required for SCRNSAVE.LIB
  38. //------------------------------------------------------------------------
  39. HANDLE    hMainInstance;
  40. HWND        hMainWindow;
  41.  
  42. //------------------------------------------------------------------------
  43. //Global Data for Bugs
  44. //------------------------------------------------------------------------
  45. char        szAppName[] = "Screen Saver.Bugs";
  46. char        szIniName[] = "CONTROL.INI";
  47.  
  48. BUGSTRUCT bsBugArray [MAXBUGS+1];
  49.  
  50. WORD    wRNutrition = 1;
  51. WORD    wGNutrition = 1;
  52. WORD    wBNutrition = 1;
  53. int    sStartBugs = 10;
  54. int    sScoutLimit = 10;
  55. int    sBabyLevel;
  56. int    sSustenance;
  57. int    sBugLimit;
  58. BOOL    bBColorFlag;
  59. BOOL    bDColorFlag;
  60. int    sNumBugs = 1;
  61.  
  62. //========================================================================
  63. //RegisterDialogClasses - Called by the screen saver applet during
  64. //                        initialzation.
  65. //========================================================================
  66. BOOL    RegisterDialogClasses (HANDLE hInst) {
  67.  
  68.     return TRUE;
  69. }
  70. //------------------------------------------------------------------------
  71. //Compare function used for sorting Bug array
  72. //------------------------------------------------------------------------
  73. int BugCmp (const BUGSTRUCT * Bug1, const BUGSTRUCT * Bug2) {
  74.     
  75.     if (Bug1->lFood > Bug2->lFood)
  76.         return -1;
  77.     else
  78.         return 1;
  79. }
  80.  
  81. //========================================================================
  82. //ScreenSaverProc - The Window procedure
  83. //========================================================================
  84. LONG FAR PASCAL ScreenSaverProc(HWND hwnd, WORD msg, WORD wParam, 
  85.                                 LONG lParam) {
  86.     static    HWND    hwndDesktop;
  87.     static    int    sScreenCx, sScreenCy;
  88.     static    WORD    wTimer = 0;
  89.     static    WORD    wTimer1 = 0;
  90.  
  91.     HDC        hdc;
  92.     int        i, j;
  93.  
  94.     switch(msg) {
  95.         case WM_CREATE:
  96.             hwndDesktop = GetDesktopWindow();
  97.  
  98.             hdc = GetDC (hwndDesktop);
  99.             sScreenCx = GetDeviceCaps (hdc, HORZRES);
  100.             sScreenCy = GetDeviceCaps (hdc, VERTRES);
  101.             ReleaseDC (hwndDesktop, hdc);
  102.  
  103.             GetProfile();
  104.             
  105.             srand (LOWORD (GetCurrentTime()));
  106.             sScoutLimit = sBugLimit / 10;
  107.             if (sSustenance > 100)
  108.                 sSustenance += sSustenance/100;
  109.             else
  110.                 sSustenance++;
  111.  
  112.             PostMessage (hwnd, WM_USER, 0, 0);
  113.  
  114.             //----------------------------------------------------------
  115.             //Use timer 1 if BugSmarts routine is called from WM_TIMER
  116.             //instead of from the message loop.
  117.             //----------------------------------------------------------
  118.             //wTimer = SetTimer (hwnd, 1, 100, NULL);
  119.             //
  120.             //Timer 2 used for population ctl
  121.             //
  122.             wTimer1 = SetTimer (hwnd, 2, 15000, NULL);
  123.             break;
  124.  
  125.  
  126.         case WM_USER:
  127.             //
  128.             // WM_USER message used to reseed bug population
  129.             //
  130.             hdc = GetDC (hwnd);
  131.             for (i = 0; i < 6; i++)
  132.                 for (j = 0; j < 6; j++)
  133.                     SetPixel (hdc, i, j, 0x000000);
  134.             
  135.             if (sSustenance > 100)
  136.                 sSustenance -= (sSustenance/100);
  137.             else 
  138.                 if (sSustenance > 0) sSustenance--;
  139.                 
  140.             sNumBugs = 1;
  141.             //
  142.             //10 trys to find a non black pixel
  143.             //
  144.             for (i = 0; i < 10; i++) {
  145.                 bsBugArray[0].PosX = (sScreenCx / 100) * (rand() % 100)+50;
  146.                 bsBugArray[0].PosY = (sScreenCy / 100) * (rand() % 100)+50;
  147.                 if (GetPixel (hdc, bsBugArray[0].PosX, bsBugArray[0].PosY)) 
  148.                     break;
  149.             }
  150.             bsBugArray[0].wXVec = rand() % 3;
  151.             bsBugArray[0].wYVec = rand() % 3;
  152.             bsBugArray[0].lFood = sSustenance * 20;
  153.             bsBugArray[0].dwColor = 0x00000000;
  154.  
  155.             ReleaseDC (hwnd, hdc);
  156.             break;
  157.  
  158.         case WM_TIMER:
  159.             //----------------------------------------------------------
  160.             //Use two timers if BugSmarts called from timer routine
  161.             //----------------------------------------------------------
  162.             if (wParam == 1) {
  163.                 BugSmarts(hwnd);
  164.             } else {
  165.                 if (sNumBugs > (sBugLimit/5) * 4) { 
  166.                     qsort (bsBugArray, sNumBugs, sizeof(BUGSTRUCT), 
  167.                              (const) BugCmp);
  168.                     sNumBugs -= (sNumBugs / 5);
  169.                 }
  170.             }
  171.             break;
  172.  
  173.         case WM_ERASEBKGND:
  174.             //
  175.             // We don't want the background erased
  176.             //
  177.             return 0;
  178.  
  179.         case WM_DESTROY:
  180.  
  181.             //----------------------------------------------------------
  182.             //Use timer 1 if BugSmarts routine is called from WM_TIMER
  183.             //instead of from the message loop.
  184.             //----------------------------------------------------------
  185.             if (wTimer) KillTimer(hwnd, 1);
  186.             if (wTimer1) KillTimer(hwnd, 2);
  187.             break;
  188.     }
  189.     return DefScreenSaverProc(hwnd, msg, wParam, lParam);
  190. }
  191.  
  192. //========================================================================
  193. //ScreenSaverConfigureDialog - Dialog procedure for configure dialog box
  194. //========================================================================
  195. BOOL FAR PASCAL ScreenSaverConfigureDialog(HWND hDlg, WORD msg, WORD wParam, 
  196.                                            LONG lParam) {
  197.     int    i, j;
  198.     char    szTemp[10];
  199.  
  200.     switch (msg) {
  201.         case WM_INITDIALOG:
  202.  
  203.             GetProfile();
  204.             SetText (hDlg, IDD_REDTEXT, wRNutrition, "Red: ");
  205.             SetText (hDlg, IDD_GREENTEXT, wGNutrition, "Green: ");
  206.             SetText (hDlg, IDD_BLUETEXT, wBNutrition, "Blue: ");
  207.             SetText (hDlg, IDD_MAXBTEXT, sBugLimit, "Max Number of Bugs: ");
  208.             SetText (hDlg, IDD_BIRTHTEXT, sBabyLevel, "Reproduction Level: ");
  209.             SetText (hDlg, IDD_SUSTEXT, sSustenance, "Sustenance Level: ");
  210.  
  211.             SetScrollRange (GetDlgItem (hDlg, IDD_REDLEVEL), 
  212.                             SB_CTL, 0, 10, FALSE);
  213.             SetScrollPos (GetDlgItem (hDlg, IDD_REDLEVEL), 
  214.                           SB_CTL, wRNutrition, TRUE);
  215.  
  216.             SetScrollRange (GetDlgItem (hDlg, IDD_GREENLEVEL), 
  217.                             SB_CTL, 0, 10, FALSE);
  218.             SetScrollPos (GetDlgItem (hDlg, IDD_GREENLEVEL), 
  219.                           SB_CTL, wGNutrition, TRUE);
  220.  
  221.             SetScrollRange (GetDlgItem (hDlg, IDD_BLUELEVEL), 
  222.                             SB_CTL, 0, 10, FALSE);
  223.             SetScrollPos (GetDlgItem (hDlg, IDD_BLUELEVEL), 
  224.                           SB_CTL, wBNutrition, TRUE);
  225.  
  226.             if (sBugLimit > 100)
  227.                 i = ((sBugLimit - 100) / 10) + 100;
  228.             else
  229.                 i = sBugLimit;
  230.             SetScrollRange (GetDlgItem (hDlg, IDD_MAXBLEVEL), 
  231.                             SB_CTL, 0, (MAXBUGS-100)/10+100, FALSE);
  232.             SetScrollPos (GetDlgItem (hDlg, IDD_MAXBLEVEL), 
  233.                           SB_CTL, i, TRUE);
  234.  
  235.             if (sBabyLevel > 100)
  236.                 i = ((sBabyLevel - 100) / 10) + 100;
  237.             else
  238.                 i = sBabyLevel;
  239.             SetScrollRange (GetDlgItem (hDlg, IDD_BIRTHLEVEL), 
  240.                             SB_CTL, 0, 500, FALSE);
  241.             SetScrollPos (GetDlgItem (hDlg, IDD_BIRTHLEVEL), 
  242.                           SB_CTL, i, TRUE);
  243.  
  244.             if (sSustenance > 100)
  245.                 i = ((sSustenance - 100) / 10) + 100;
  246.             else
  247.                 i = sSustenance;
  248.             SetScrollRange (GetDlgItem (hDlg, IDD_SUSLEVEL), 
  249.                             SB_CTL, 0, 500, FALSE);
  250.             SetScrollPos (GetDlgItem (hDlg, IDD_SUSLEVEL), 
  251.                           SB_CTL, i, TRUE);
  252.  
  253.             SendDlgItemMessage (hDlg, IDD_BIRTHCOLOR, BM_SETCHECK, 
  254.                                 bBColorFlag, 0);
  255.             SendDlgItemMessage (hDlg, IDD_DEATHCOLOR, BM_SETCHECK, 
  256.                                 bDColorFlag, 0);
  257.             return TRUE;
  258.  
  259.         case WM_COMMAND:
  260.             switch (wParam) {
  261.  
  262.                 case IDD_BIRTHCOLOR:
  263.                     if (HIWORD (lParam) == 0) {
  264.                         bBColorFlag = !bBColorFlag;
  265.                         SendDlgItemMessage (hDlg, IDD_BIRTHCOLOR, BM_SETCHECK,
  266.                                         bBColorFlag, 0);
  267.                     }
  268.                     break;
  269.  
  270.                 case IDD_DEATHCOLOR:
  271.                     if (HIWORD (lParam) == 0) {
  272.                         bDColorFlag = !bDColorFlag;
  273.                         SendDlgItemMessage (hDlg, IDD_DEATHCOLOR, BM_SETCHECK,
  274.                                         bDColorFlag, 0);
  275.                     }
  276.                     break;
  277.  
  278.                 case IDD_HELP: {
  279.                         FARPROC    lpfnAboutDlgProc;
  280.                         lpfnAboutDlgProc = MakeProcInstance (AboutDlgProc, 
  281.                                                              hMainInstance);
  282.                         DialogBox (hMainInstance, "About", hDlg, lpfnAboutDlgProc);
  283.                         FreeProcInstance (lpfnAboutDlgProc);
  284.                     }
  285.                     break;
  286.  
  287.                 case IDOK:
  288.                     i = GetScrollPos (GetDlgItem (hDlg, IDD_REDLEVEL), SB_CTL);
  289.                     itoa (i, szTemp, 10);
  290.                     WritePrivateProfileString (szAppName, "Red", szTemp,
  291.                                                szIniName);
  292.  
  293.                     i = GetScrollPos (GetDlgItem (hDlg, IDD_GREENLEVEL), SB_CTL);
  294.                     itoa (i, szTemp, 10);
  295.                     WritePrivateProfileString (szAppName, "Green", szTemp,
  296.                                                szIniName);
  297.  
  298.                     i = GetScrollPos (GetDlgItem (hDlg, IDD_BLUELEVEL), SB_CTL);
  299.                     itoa (i, szTemp, 10);
  300.                     WritePrivateProfileString (szAppName, "Blue", szTemp,
  301.                                                szIniName);
  302.  
  303.                     i = GetScrollPos (GetDlgItem (hDlg, IDD_MAXBLEVEL), SB_CTL);
  304.                     if (i > 100) i = 100 + ((i - 100) * 10);
  305.                     itoa (i, szTemp, 10);
  306.                     WritePrivateProfileString (szAppName, "MaxBugs", szTemp,
  307.                                                szIniName);
  308.  
  309.                     i = GetScrollPos (GetDlgItem (hDlg, IDD_BIRTHLEVEL), SB_CTL);
  310.                     if (i > 100) i = 100 + ((i - 100) * 10);
  311.                     itoa (i, szTemp, 10);
  312.                     WritePrivateProfileString (szAppName, "BabyLevel", szTemp,
  313.                                                szIniName);
  314.  
  315.                     i = GetScrollPos (GetDlgItem (hDlg, IDD_SUSLEVEL), SB_CTL);
  316.                     if (i > 100) i = 100 + ((i - 100) * 10);
  317.                     itoa (i, szTemp, 10);
  318.                     WritePrivateProfileString (szAppName, "Sustenance", szTemp,
  319.                                                szIniName);
  320.  
  321.                     i = (int) SendDlgItemMessage (hDlg, IDD_BIRTHCOLOR, 
  322.                                                   BM_GETCHECK, 0, 0);
  323.                     itoa (i, szTemp, 10);
  324.                     WritePrivateProfileString (szAppName, "BirthColor", szTemp,
  325.                                                szIniName);
  326.                     i = (int) SendDlgItemMessage (hDlg, IDD_DEATHCOLOR, 
  327.                                                   BM_GETCHECK, 0, 0);
  328.                     itoa (i, szTemp, 10);
  329.                     WritePrivateProfileString (szAppName, "DeathColor", szTemp,
  330.                                                szIniName);
  331.                     EndDialog (hDlg, TRUE);
  332.                     return TRUE;
  333.                 case IDCANCEL:
  334.                     EndDialog (hDlg, FALSE);
  335.                     return TRUE;
  336.             }
  337.             break;
  338.  
  339.  
  340.         case WM_HSCROLL:
  341.  
  342.             i = GetScrollPos (HIWORD (lParam), SB_CTL);    // Get Scroll bar Pos
  343.             j = GetDlgCtrlID (HIWORD (lParam));            // Get Scroll bar ID
  344.  
  345.             switch (wParam) {
  346.                 case SB_LINEUP:
  347.                     i--;
  348.                     break;
  349.  
  350.                 case SB_LINEDOWN:
  351.                     i++;
  352.                     break;
  353.  
  354.                 case SB_PAGEUP:
  355.                     if (j == IDD_REDLEVEL || 
  356.                         j == IDD_GREENLEVEL || 
  357.                         j == IDD_BLUELEVEL)
  358.                         i -=2;
  359.                     else
  360.                         i -= 10;
  361.                     break;
  362.  
  363.                 case SB_PAGEDOWN:
  364.                     if (j == IDD_REDLEVEL || 
  365.                         j == IDD_GREENLEVEL || 
  366.                          j == IDD_BLUELEVEL)
  367.                         i += 2;
  368.                     else
  369.                         i += 10;
  370.                     break;
  371.  
  372.                 case SB_THUMBTRACK:
  373.                 case SB_THUMBPOSITION:
  374.                     i = LOWORD (lParam);
  375.                     break;
  376.             }
  377.             SetScrollPos (HIWORD (lParam), SB_CTL, i, TRUE);
  378.  
  379.             switch (j) {
  380.                 case IDD_REDLEVEL:
  381.                     SetText (hDlg, IDD_REDTEXT, i, "Red: ");
  382.                     break;
  383.  
  384.                 case IDD_GREENLEVEL:
  385.                     SetText (hDlg, IDD_GREENTEXT, i, "Green: ");
  386.                     break;
  387.  
  388.                 case IDD_BLUELEVEL:
  389.                     SetText (hDlg, IDD_BLUETEXT, i, "Blue: ");
  390.                     break;
  391.  
  392.                 case IDD_MAXBLEVEL:
  393.                     if (i > 100) i = 100 + ((i - 100) * 10);
  394.                     SetText (hDlg, IDD_MAXBTEXT, i, "Max Number of Bugs: ");
  395.                     break;
  396.  
  397.                 case IDD_SUSLEVEL:
  398.                     if (i > 100) i = 100 + ((i - 100) * 10);
  399.                     SetText (hDlg, IDD_SUSTEXT, i, "Sustenance Level: ");
  400.                     break;
  401.  
  402.                 case IDD_BIRTHLEVEL:
  403.                     if (i > 100) i = 100 + ((i - 100) * 10);
  404.                     SetText (hDlg, IDD_BIRTHTEXT, i, "Reproduction Level: ");
  405.                     break;
  406.             }
  407.             break;
  408.     }
  409.     return FALSE;
  410. }    
  411. //========================================================================
  412. //About Dlg Proc - Processes messages for the About box.
  413. //========================================================================
  414. BOOL FAR PASCAL AboutDlgProc(HWND hDlg, WORD msg, WORD wParam, LONG lParam) {
  415.  
  416.     switch (msg) {
  417.  
  418.         case WM_INITDIALOG:
  419.             return TRUE;
  420.  
  421.         case WM_COMMAND:
  422.             switch (wParam) {
  423.  
  424.                 case IDOK:
  425.                 case IDCANCEL:
  426.                     EndDialog (hDlg, TRUE);
  427.                     return TRUE;
  428.             }
  429.             break;
  430.     }
  431.     return FALSE;
  432. }    
  433.  
  434. //------------------------------------------------------------------------
  435. //Process dead bugs using C code.
  436. //------------------------------------------------------------------------
  437. void DeadBugs (HDC hdc, int sNumBugs, int sDeadBugs, BUGSTRUCT *bsBugArray) {
  438.  
  439.     BUGSTRUCT    * bspCurrBug;
  440.     BUGSTRUCT    * bspNextBug;
  441.     int            i, j;
  442.  
  443.     if (sDeadBugs) {
  444.         i = 0;
  445.         j = 1;
  446.         while (i < sNumBugs && j < sNumBugs) {
  447.  
  448.             bspCurrBug = &bsBugArray[i];
  449.             bspNextBug = &bsBugArray[j];
  450.  
  451.             if (bspCurrBug->lFood <= 0) {
  452.                 if (bDColorFlag)
  453.                     SetPixel (hdc, bspCurrBug->PosX, bspCurrBug->PosY, 0x000040);
  454.                 bspCurrBug->PosX = bspNextBug->PosX;
  455.                 bspCurrBug->PosY = bspNextBug->PosY;
  456.                 bspCurrBug->wXVec = bspNextBug->wXVec;
  457.                 bspCurrBug->wYVec = bspNextBug->wYVec;
  458.                 bspCurrBug->lFood = bspNextBug->lFood;
  459.                 bspCurrBug->dwColor = bspNextBug->dwColor;
  460.                 j++;
  461.             } else {
  462.                 i++;
  463.                 if (i <= j) j = i + 1;
  464.             }
  465.         }
  466.     }
  467. }
  468.  
  469. //-----------------------------------------------------------------------
  470. //BugSmarts - Routine that computes the next move for each of the bugs
  471. //-----------------------------------------------------------------------
  472. void BugSmarts (HWND hwnd) {
  473.  
  474.     HDC            hdc;
  475.     int            i, sNewBugs, sDeadBugs, sRandom;
  476.     DWORD            dwOldPel;
  477.     long            lPelFood;
  478.  
  479.     BUGSTRUCT    * bspCurrBug;
  480.     BUGSTRUCT    * bspNextBug;    
  481.  
  482.     hdc = GetDC (hwnd);
  483.     sNewBugs = 0;
  484.     sDeadBugs = 0;
  485.  
  486.     for (i = 0; i < sNumBugs; i++) {
  487.  
  488.         bspCurrBug = &bsBugArray[i];
  489.         sRandom = rand();
  490.         //
  491.         //Compute next move
  492.         //
  493.         if (i < sScoutLimit) {
  494.             bspCurrBug->PosX += bspCurrBug->wXVec + (sRandom % 3) - 2;
  495.             bspCurrBug->PosY += bspCurrBug->wYVec + ((sRandom >> 2) % 3) - 2;
  496.         } else {
  497.             bspCurrBug->PosX += (sRandom % 3) - 1;
  498.             bspCurrBug->PosY += ((sRandom >> 2) % 3) - 1;
  499.         }
  500.         //
  501.         //Get pixel
  502.         //
  503.         dwOldPel = GetPixel (hdc, bspCurrBug->PosX, bspCurrBug->PosY);
  504.         //
  505.         //Determine the nutritional value of Pel by its color
  506.         //
  507.         if (dwOldPel == -1) {
  508.             bspCurrBug->lFood = 0;
  509.         } else {
  510.             lPelFood = (BYTE)dwOldPel * wRNutrition +
  511.                         ((WORD)dwOldPel >> 8) * wGNutrition +
  512.                         (dwOldPel >> 16) * wBNutrition;
  513.             bspCurrBug->lFood += lPelFood;
  514.             bspCurrBug->lFood -= sSustenance;
  515.         }
  516.         //
  517.         //Check for dead bugs
  518.         //
  519.         if (bspCurrBug->lFood <= 0) 
  520.             sDeadBugs++;
  521.         else {
  522.             //
  523.             //If not getting enough food, try a new direction
  524.             //
  525.             if (lPelFood <= sSustenance) {
  526.                 bspCurrBug->wXVec = (sRandom >> 4) % 3;
  527.                 bspCurrBug->wYVec = (sRandom >> 6) % 3;
  528.             }
  529.             if (dwOldPel != 0)
  530.                 SetPixel (hdc, bspCurrBug->PosX, bspCurrBug->PosY, 
  531.                           bspCurrBug->dwColor);
  532.         }
  533.         //
  534.         //See if bug can reproduce
  535.         //
  536.         if (sNumBugs + sNewBugs < sBugLimit) 
  537.             if (bspCurrBug->lFood > sBabyLevel) {
  538.  
  539.                 bspNextBug = &bsBugArray[sNumBugs + sNewBugs];
  540.  
  541.                 bspNextBug->wXVec = (sRandom % 3) - 1;
  542.                 bspNextBug->wYVec = ((sRandom >> 2) % 3) - 1;
  543.  
  544.                 bspNextBug->PosX = bspCurrBug->PosX + 
  545.                                      bspCurrBug->wXVec +
  546.                                      bspNextBug->wXVec;
  547.                 bspNextBug->PosY = bspCurrBug->PosY + 
  548.                                      bspCurrBug->wYVec +
  549.                                      bspNextBug->wYVec;
  550.  
  551.                 bspNextBug->lFood = sSustenance * 2;
  552.                 bspNextBug->dwColor = 0x000000;
  553.                 if (bBColorFlag)
  554.                     SetPixel (hdc, bspCurrBug->PosX, bspCurrBug->PosY, 0x008000);
  555.  
  556.                 bspCurrBug->lFood -= sBabyLevel/2;
  557.                 sNewBugs++;
  558.             }
  559.     }
  560.     sNumBugs += sNewBugs;
  561.     //
  562.     //If any dead bugs, compress data in array
  563.     //
  564.     DeadBugs (hdc, sNumBugs, sDeadBugs, bsBugArray);
  565.     
  566.     if (sDeadBugs) {
  567.         sNumBugs -= sDeadBugs;
  568.     }
  569.     if (sNumBugs >= sBugLimit) {
  570.         SetPixel (hdc, 0, 0, 0x0000ff);
  571.         SetPixel (hdc, 0, 1, 0x0000ff);
  572.         SetPixel (hdc, 1, 0, 0x0000ff);
  573.         SetPixel (hdc, 1, 1, 0x0000ff);
  574.     } else {
  575.         SetPixel (hdc, 0, 0, 0x00ff00);
  576.         SetPixel (hdc, 0, 1, 0x00ff00);
  577.         SetPixel (hdc, 1, 0, 0x00ff00);
  578.         SetPixel (hdc, 1, 1, 0x00ff00);
  579.     }     
  580.     ReleaseDC (hwnd, hdc);
  581.     if (sNumBugs == 0) 
  582.         PostMessage (hwnd, WM_USER, 0, 0);
  583.  
  584.     return;
  585. }
  586.  
  587. //------------------------------------------------------------------------
  588. //Get Profile - Reads the profile info from CONTROL.INI.
  589. //------------------------------------------------------------------------
  590. void GetProfile (void) {
  591.     wRNutrition = GetPrivateProfileInt (szAppName, "Red", 1,
  592.                                         szIniName);
  593.     wGNutrition = GetPrivateProfileInt (szAppName, "Green", 1,
  594.                                         szIniName);         
  595.     wBNutrition = GetPrivateProfileInt (szAppName, "Blue", 1,
  596.                                         szIniName);         
  597.     sBugLimit = GetPrivateProfileInt (szAppName, "MaxBugs", 512,
  598.                                         szIniName);
  599.     sSustenance = GetPrivateProfileInt (szAppName, "Sustenance", 512,
  600.                                         szIniName);
  601.     sBabyLevel = GetPrivateProfileInt (szAppName, "BabyLevel", 128,
  602.                                        szIniName);
  603.     bBColorFlag = GetPrivateProfileInt (szAppName, "BirthColor", TRUE,
  604.                                        szIniName);
  605.     bDColorFlag = GetPrivateProfileInt (szAppName, "DeathColor", TRUE,
  606.                                        szIniName);
  607.     return;
  608. }
  609. //------------------------------------------------------------------------
  610. //Set Text - Sets the text for a dialog box control
  611. //------------------------------------------------------------------------
  612. void SetText (HWND hwnd, int sCtlID, int sVal, char* szText) {
  613.  
  614.     char    szTemp[80], szTemp1[10];
  615.  
  616.     strcpy (szTemp, szText);
  617.     itoa (sVal, szTemp1, 10);
  618.     strcat (szTemp, szTemp1);
  619.     SetDlgItemText (hwnd, sCtlID, szTemp);
  620.     return;
  621.