home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 15 / CDACTUAL15.iso / cdactual / program / c / WTJ9304.ZIP / APIARY.ZIP / MYGENRIC.C next >
Encoding:
C/C++ Source or Header  |  1993-01-18  |  3.3 KB  |  93 lines

  1. #include <windows.h>
  2. #include "MyGenric.h"
  3.  
  4. HWND hAppWnd;    // global Window handle for use as needed
  5. HANDLE hInst;    // global instance handle for use as needed
  6. char szAppName[] = APP_NAME;  // ID string
  7.  
  8. long FAR PASCAL WndProc( HWND hWnd,
  9.                          WORD msg,
  10.                          WORD wParam,
  11.                          long lParam )
  12. { long retval = 0L;      // local for return value
  13.   switch( msg )               // dispatch the messages
  14.     {
  15.     case WM_COMMAND: // only these are usually needed
  16.       switch( wParam )
  17.         {
  18.         case 101:     // do it -- insert code
  19.                               // for testing after this line
  20.           break;
  21.         case 999:     // quit just fakes the
  22.                               // System Menu's CLOSE
  23.           SendMessage( hWnd, WM_SYSCOMMAND, SC_CLOSE, 0L );
  24.         }
  25.       break;
  26.     default:             // handles all other messages
  27.       retval = DefWindowProc( hWnd, msg, wParam, lParam );
  28.         }
  29.   return retval;
  30. }
  31.  
  32. BOOL FAR PASCAL RegApp( void )
  33. { WNDCLASS    wc;
  34.  
  35.   wc.style          = 0;     // plain vanilla style bits
  36.   wc.lpfnWndProc    = &WndProc;
  37.   wc.cbClsExtra     = 0;
  38.   wc.cbWndExtra     = 0;
  39.   wc.hInstance      = hInst;
  40.   wc.hIcon          = NULL;
  41.   wc.hCursor        = NULL;  // use system defaults
  42.   wc.hbrBackground  = COLOR_APPWORKSPACE+1;
  43.   wc.lpszMenuName   = "MyGenric";
  44.   wc.lpszClassName  = szAppName;   // initialized via macro
  45.  
  46.   return RegisterClass( &wc );
  47. }
  48.  
  49. BOOL FAR PASCAL InitInst(LPSTR lpCmdLine, WORD nCmdShow)
  50. { hAppWnd = CreateWindow (szAppName,     // class name
  51.                           szAppName,     // window name
  52.                           WS_OVERLAPPEDWINDOW
  53.                             | WS_CLIPCHILDREN
  54.                             | WS_VSCROLL
  55.                             | WS_HSCROLL
  56.                             ,            // style bits
  57.                           0,             // X
  58.                           0,             // Y
  59.                           CW_USEDEFAULT, // width
  60.                           0,             // height
  61.                           NULL,          // parent
  62.                           NULL,          // menu
  63.                           hInst,         // instance handle
  64.                           NULL);         // param block LP
  65.   if (!hAppWnd)                  // CreateWindow failed
  66.     return FALSE;
  67.   ShowWindow (hAppWnd, nCmdShow);  // Success
  68.   UpdateWindow (hAppWnd);
  69.   return TRUE;
  70. }
  71.  
  72. int PASCAL WinMain( HANDLE hInstance,     // current instance
  73.                     HANDLE hPrevInstance, // previous instance
  74.                     LPSTR lpszCmdLine,    // command line
  75.                     int nCmdShow )        // min, max, or
  76.                                           // normal
  77. { MSG msg;
  78.    hInst = hInstance;    // set global instance handle
  79.    if( !hPrevInstance )  // If this is first instance,
  80.                          // register window class
  81.     { if( !RegApp() )
  82.         return 0;        // If registration failed, get out
  83.     }
  84.   if( !InitInst( lpszCmdLine, nCmdShow ))
  85.     { return 0;          // If initialization failed,get out
  86.     }
  87.   while( GetMessage( &msg, NULL, 0, 0 ))     // run the loop
  88.     { TranslateMessage( &msg );
  89.       DispatchMessage( &msg );
  90.     }
  91.   return 0;
  92. }
  93.