home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_01_02 / 1n02070a < prev    next >
Text File  |  1990-09-27  |  4KB  |  116 lines

  1.  
  2. Listing 1.
  3. ---------
  4.  
  5. /******************************************************************************
  6.  * BASE.C
  7.  */
  8.  
  9. #define LINT_ARGS
  10. #define NOCOMM
  11. #define NOMINMAX
  12.  
  13. #include <stdio.h>
  14. #include <windows.h>
  15.  
  16. HANDLE    hInst;                        /* Global Instance Handle           */
  17.  
  18. long FAR PASCAL MainFormWndProc(HWND, unsigned, WORD, LONG);
  19.  
  20. /*****************************************************************************
  21.  * WinMain()
  22.  */
  23. int PASCAL WinMain(hInstance, hPrevInstance, CmdLine, CmdShow)
  24.     HANDLE hInstance,hPrevInstance;
  25.     LPSTR CmdLine;
  26.     int CmdShow;
  27.     {
  28. /*   WNDCLASS WndClass;            REMOVED -- Seems to be redundant -LZ  */
  29.     HWND hWnd;
  30.     MSG msg;
  31.  
  32.     hInst=hInstance;                             /* Store Instance handle   */
  33.  
  34.     /*
  35.      * Register Main Form Window Class
  36.      */
  37.     if (!hPrevInstance){
  38.        WNDCLASS WndClass;
  39.        WndClass.lpszClassName = (LPSTR)"base";
  40.        WndClass.hInstance     = hInstance;
  41.        WndClass.lpfnWndProc   = MainFormWndProc;
  42.        WndClass.style         = CS_HREDRAW | CS_VREDRAW;
  43.        WndClass.hbrBackground = GetStockObject(WHITE_BRUSH);
  44.        WndClass.hIcon         = NULL;
  45.        WndClass.lpszMenuName  = NULL;
  46.        WndClass.hCursor       = LoadCursor(NULL,IDC_ARROW);
  47.        WndClass.cbClsExtra    = NULL;
  48.        WndClass.cbWndExtra    = NULL;
  49.        if (!RegisterClass(&WndClass))
  50.           return(NULL);
  51.        }
  52.  
  53.     /*
  54.      * Create MainForm Window
  55.      */
  56.     hWnd = CreateWindow("base",              /* window class name       */
  57.                         "App Template",      /* window caption          */
  58.                         WS_OVERLAPPEDWINDOW, /* window style            */
  59.                         0,                   /* initial x position      */
  60.                         0,                   /* initial y position      */
  61.                         CW_USEDEFAULT,       /* initial x size          */
  62.                         0,                   /* initial y size          */
  63.                         NULL,                /* parent window handle    */
  64.                         NULL,                /* window menu handle      */
  65.                         hInstance,           /* program instance handle */
  66.                         NULL);               /* create parameters       */
  67.     if (!hWnd)
  68.       return (NULL);
  69.     /*
  70.      * Message Loop
  71.      */
  72.     while (GetMessage (&msg,NULL,0,0)){   
  73.        TranslateMessage (&msg) ;
  74.        DispatchMessage (&msg) ;
  75.        }
  76.     return (msg.wParam);
  77.     }
  78. /*****************************************************************************
  79.  * MainFormWndProc()
  80.  */
  81. long FAR PASCAL MainFormWndProc(hWnd, message, wParam, lParam)
  82.   HWND hWnd;
  83.   unsigned message;
  84.   WORD wParam;
  85.   LONG lParam;
  86.   {
  87.   switch (message){
  88.      case WM_SYSCOMMAND:
  89.           if(wParam==SC_MAXIMIZE)
  90.              MessageBox(hWnd,"Intercepted Maximize Message",
  91.                         (LPSTR)"App Template",MB_OK);
  92.           if(wParam==SC_MINIMIZE)
  93.              MessageBox(hWnd,"Intercepted Minimize Message",
  94.                         (LPSTR)"App Template",MB_OK);
  95.           return(DefWindowProc(hWnd,message,wParam,lParam));
  96.      case WM_CREATE:
  97.           ShowWindow(hWnd,SW_SHOWNORMAL);
  98.           UpdateWindow(hWnd);
  99.           break;
  100.      case WM_ENDSESSION:
  101.           if(MessageBox(hWnd, "This will end the program",
  102.                 (LPSTR)"App Template",
  103.                 MB_OKCANCEL|MB_ICONEXCLAMATION)==IDCANCEL)
  104.              break;
  105.           DestroyWindow(hWnd); 
  106.           break;
  107.      case WM_DESTROY:
  108.           PostQuitMessage(0);
  109.           break;
  110.      default:return(DefWindowProc(hWnd,message,wParam,lParam));
  111.      }
  112.   return (NULL);
  113.   }
  114.  
  115.  
  116.