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

  1. /* 
  2.  * Initialization segment for the Windows cellular automaton demo
  3.  * This code is discarded after it is used.
  4.  *
  5.  * Written by Bill Hall
  6.  * 3665 Benton Street, #66
  7.  * Santa Clara, CA 95051
  8.  *
  9.  */
  10.  
  11. #define NOCOMM
  12. #define NOKANJI
  13. #define NOATOM
  14. #define NOSOUND
  15. #include <windows.h>
  16. #include "wincel.h"
  17.  
  18. /* local function declarations */
  19. static BOOL NEAR RegisterWindowClass(HANDLE);
  20. static void NEAR GetPrevInstanceData(HANDLE);
  21. static BOOL NEAR MakeAndShowMainWnd(HANDLE, int);
  22.  
  23. /* This routine is FAR since it is called from another segment */
  24. BOOL FAR InitProgram(hInstance,hPrevInstance, lpszCmdLine, cmdShow)
  25. HANDLE hInstance, hPrevInstance;
  26. LPSTR lpszCmdLine;
  27. int cmdShow;
  28. {
  29.  
  30.     hInst = hInstance;
  31.  
  32.   /* if this is the first instance of the program ... */
  33.     if (!hPrevInstance) {
  34.      /* register the window */
  35.     if (!RegisterWindowClass(hInstance))
  36.         return FALSE;
  37.      /* get the icon string */
  38.     LoadString(hInstance, IDS_ICON,(LPSTR)szIcon,sizeof(szIcon));
  39.     }
  40.  
  41.   /* A previous instance already exists so get global data from there */
  42.     else
  43.     GetPrevInstanceData(hPrevInstance);
  44.  
  45.   /* Create and show the window */
  46.     if (!MakeAndShowMainWnd(hInstance, cmdShow))
  47.     return FALSE;
  48.  
  49.     return TRUE;
  50. }
  51.  
  52. /* Every window must belong to a class. We register ours here */
  53. static BOOL NEAR RegisterWindowClass(hInstance)
  54. HANDLE hInstance;
  55. {
  56.  
  57.     PWNDCLASS pWndClass;
  58.     HANDLE hTemp;
  59.  
  60.   /* Load the name string from resources */
  61.     LoadString(hInstance, IDS_APPNAME,(LPSTR)szAppName,sizeof(szAppName));
  62.  
  63.   /* allocate space for the WNDCLASS structure and lock it down */
  64.     hTemp = LocalAlloc(LPTR,sizeof(WNDCLASS));
  65.     pWndClass = (PWNDCLASS)LocalLock(hTemp);
  66.  
  67.   /* fill the structure */    
  68.     pWndClass->hCursor    = LoadCursor(NULL, IDC_ARROW);  /* standard cursor */
  69.     pWndClass->hIcon    = NULL;                /* no icon */
  70.     pWndClass->lpszMenuName = (LPSTR)szAppName;
  71.     pWndClass->lpszClassName = (LPSTR)szAppName;    /* our class name */
  72.     pWndClass->hbrBackground = COLOR_APPWORKSPACE + 1;
  73.     pWndClass->hInstance = hInstance;        /* instance handle */
  74.     pWndClass->style = CS_VREDRAW | CS_HREDRAW; /* standard redraw values */
  75.     pWndClass->lpfnWndProc = MainWndProc;    /* pointer to our window proc */
  76.  
  77.   /* register the class.  if fail, abort */
  78.     if (!RegisterClass((LPWNDCLASS)pWndClass))
  79.     return FALSE;
  80.  
  81.   /* free the memory used */
  82.     LocalUnlock(hTemp);
  83.     LocalFree(hTemp);
  84.  
  85.   /* show success */
  86.     return TRUE;
  87. }
  88.  
  89. /*
  90.    If this not the first instance, we can retrieve static data from a
  91.    previous invocation of the program
  92. */
  93. static void NEAR GetPrevInstanceData(hInstance)
  94. HANDLE hInstance;
  95. {
  96.  
  97.     GetInstanceData(hInstance, (PSTR)szAppName, sizeof(szAppName));
  98.     GetInstanceData(hInstance, (PSTR)szIcon, sizeof(szIcon));
  99.  
  100. }
  101.  
  102. /*
  103.  Create the window, making sure that its position and size are suitable
  104.  for the display.
  105. */
  106. static BOOL NEAR MakeAndShowMainWnd(HANDLE hInstance, int cmdShow)
  107. {
  108.  
  109.    char szTitle[50];
  110.  
  111.     LoadString(hInstance, IDS_TITLE,(LPSTR)szTitle,sizeof(szTitle));
  112.  
  113.   /* create the window, letting it fall where Windows wants */
  114.     hWndMain = CreateWindow((LPSTR)szAppName,
  115.                  (LPSTR)szTitle,
  116.                  WS_OVERLAPPEDWINDOW,
  117.                  CW_USEDEFAULT,0,
  118.                  CW_USEDEFAULT,0,
  119.                  (HWND)NULL,
  120.                  (HMENU)NULL,
  121.                  (HANDLE)hInstance,
  122.                  (LPSTR)NULL);
  123.  
  124.   /* if we fail, give up */
  125.     if (hWndMain == NULL)
  126.     return FALSE;
  127.  
  128.   /* finally, display the window and show success */
  129.     ShowWindow(hWndMain, cmdShow);
  130.     UpdateWindow(hWndMain);
  131.  
  132.     return TRUE;
  133. }
  134.  
  135. // get the maximum number of states for the display and set some values
  136. void FAR WndInit(HWND hWnd)
  137. {
  138.     register HDC hDC;
  139.  
  140.     hDC = GetDC(hWnd);
  141.     maxstates = GetDeviceCaps(hDC, NUMCOLORS);
  142.     ReleaseDC(hWnd, hDC);
  143.  
  144.     if (maxstates == 2) {
  145.     maxstates = 8;
  146.     monochrome = TRUE;
  147.     }
  148.     numstates = maxstates > MAXSTATES ? MAXSTATES : maxstates;
  149.     maxiterates = UPDATECOUNT;
  150.     update = maxiterates;
  151. }
  152.  
  153.