home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PJ8_3.ZIP / WINCELMS.C < prev    next >
C/C++ Source or Header  |  1990-01-26  |  4KB  |  159 lines

  1. /* 
  2.  * Miscellaneous segment for the Windows cellular automaton demo
  3.  *
  4.  * Written by Bill Hall
  5.  * 3665 Benton Street, #66
  6.  * Santa Clara, CA 95051
  7.  *
  8.  */
  9.  
  10. #define NOCOMM
  11. #define NOKANJI
  12. #define NOATOM
  13. #define NOSOUND
  14. #define NOMINMAX
  15. #include <windows.h>
  16. #include <stdlib.h>
  17.  
  18. #include "wincel.h"
  19. #include "wcldlg.h"
  20.  
  21. static void NEAR InitParamBox(HWND hDlg);
  22. static void NEAR SetParamBox(HWND hDlg);
  23.  
  24. /* utility function to open a modal dialog box */
  25. BOOL OpenDlgBox(HWND hWnd, FARPROC fpProc, WORD boxnum)
  26. {
  27.  
  28.     FARPROC fp;
  29.     BOOL result;
  30.  
  31.   /* make a proc instance for the about box window function */
  32.     fp = MakeProcInstance(fpProc, hInst);
  33.   /* create a modal dialog box */
  34.     result = DialogBox(hInst, MAKEINTRESOURCE(boxnum),hWnd,fp);
  35.     FreeProcInstance(fp);
  36.     return result;
  37.  
  38. }
  39.  
  40. /* This is the window proc for the about box when it is displayed */
  41. BOOL FAR PASCAL AboutBoxProc(HWND hDlg,unsigned message,WORD wParam,LONG lParam)
  42. {
  43.  
  44.     switch (message) {
  45.  
  46.       /* nothing to initialize */
  47.     case WM_INITDIALOG:
  48.         break;
  49.  
  50.       /* this dialog box has only an OK button */
  51.     case WM_COMMAND:
  52.         switch (wParam) {
  53.         case IDOK:
  54.         case IDCANCEL:
  55.         /* destroy the dialog box */
  56.             EndDialog(hDlg,TRUE);
  57.             break;
  58.         default:
  59.             return FALSE;        /* we did not process */
  60.         }
  61.         break;
  62.         
  63.     default:
  64.         return FALSE;
  65.     }
  66.     return TRUE;        /* we processed message */
  67. }
  68.  
  69. BOOL FAR PASCAL ParamBoxProc(HWND hDlg,unsigned message,WORD wParam,LONG lParam)
  70. {
  71.  
  72.     switch (message) {
  73.  
  74.     case WM_INITDIALOG:
  75.         InitParamBox(hDlg);
  76.         break;
  77.  
  78.     case WM_COMMAND:
  79.         switch (wParam) {
  80.         /* OK selected */
  81.         case IDOK:
  82.             SetParamBox(hDlg);
  83.             EndDialog(hDlg,TRUE);
  84.             break;
  85.         /* destroy the dialog box */
  86.         case IDCANCEL:
  87.             EndDialog(hDlg,FALSE);
  88.             break;
  89.         default:
  90.             return FALSE;
  91.         }
  92.         break;
  93.         
  94.     default:
  95.         return FALSE;
  96.     }
  97.     return TRUE;        /* we processed message */
  98. }
  99.  
  100. /* set selected paramters */
  101. static void NEAR SetParamBox(HWND hDlg)
  102. {
  103.     WORD index;
  104.     char buf[40];
  105.  
  106.     /* read each list box for current selection and set values accordingly */
  107.  
  108.     index = (WORD)SendDlgItemMessage(hDlg, IDD_STATES, LB_GETCURSEL, 0, 0L);
  109.     if (index != LB_ERR) {
  110.     SendDlgItemMessage(hDlg, IDD_STATES, LB_GETTEXT, index,
  111.                         (LONG)(LPSTR)buf);
  112.     numstates = atoi(buf);
  113.     }
  114.     index = (WORD)SendDlgItemMessage(hDlg, IDD_ITERATIONS, LB_GETCURSEL, 0, 0L);
  115.     if (index != LB_ERR) {
  116.     SendDlgItemMessage(hDlg, IDD_ITERATIONS, LB_GETTEXT, index,
  117.                         (LONG)(LPSTR)buf);
  118.     maxiterates = atoi(buf);
  119.     }
  120. }
  121.  
  122. /* initialize the dialog box list boxes */
  123. static void NEAR InitParamBox(HWND hDlg)
  124. {
  125.     register int i;
  126.     int k;
  127.     char buf[40];
  128.     DWORD color;
  129.     HDC hDC;
  130.  
  131.     /* initialize the states list box */
  132.     for (i = 2; i <= maxstates; i++)
  133.         SendDlgItemMessage(hDlg, IDD_STATES, LB_INSERTSTRING, -1,
  134.                 (LONG)(LPSTR)itoa(i, buf, 10));
  135.     SendDlgItemMessage(hDlg, IDD_STATES, LB_SELECTSTRING, -1,
  136.             (LONG)(LPSTR)itoa(numstates, buf, 10));
  137.  
  138.     /* initialize the iterations list box */    
  139.     for (i = 1; i <= 100; i++)
  140.         SendDlgItemMessage(hDlg, IDD_ITERATIONS, LB_INSERTSTRING, -1,
  141.                 (LONG)(LPSTR)itoa(i, buf, 10));
  142.     SendDlgItemMessage(hDlg, IDD_ITERATIONS, LB_SELECTSTRING, -1,
  143.             (LONG)(LPSTR)itoa(maxiterates, buf, 10));
  144.     
  145.     /* finally, read the color table and display the values in hex */
  146.     hDC = GetDC(hDlg);
  147.     for (k = 0; k < maxstates; k++) {
  148.     if (monochrome)
  149.         color = 0xff0000 * ((k & 4) >> 2) +
  150.                 0x00ff00 * ((k & 2) >> 1) +
  151.                 0x0000ff * (k & 1);
  152.     else
  153.         Escape(hDC, GETCOLORTABLE, NULL, (LPSTR)&k, (LPSTR)&color);
  154.         SendDlgItemMessage(hDlg, IDD_COLORS, LB_INSERTSTRING, -1,
  155.                 (LONG)(LPSTR)ultoa(color, buf, 16));
  156.     }
  157.     ReleaseDC(hDlg, hDC);
  158. }
  159.