home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / m / m003_1 / sb_bc.ddi / BC / CH2 / WINAPP-1.C next >
Encoding:
C/C++ Source or Header  |  1991-09-19  |  2.2 KB  |  77 lines

  1. /***              Windows Application 1                ***/
  2. /***                                                   ***/
  3. /***              WINAPP-1 includes                    ***/
  4. /***                       (1) WINAPP-1.C              ***/
  5. /***                       (2) WINAPP-1.DEF            ***/
  6.  
  7. #include <windows.h>
  8.  
  9. // Declaration
  10.  
  11. long FAR PASCAL AppWndProc (HWND, WORD, WORD, LONG) ;
  12.  
  13.  
  14. // Definition
  15.  
  16. int PASCAL WinMain(HANDLE hInstance,
  17.            HANDLE hPrevInstance,
  18.            LPSTR  lpszCmdLine,
  19.            int    nCmdShow)
  20. { char      szAppName[]="WinApp" ;
  21.   WNDCLASS  wndclass ;
  22.   MSG        msg ;
  23.   HWND        hwnd ;
  24.  
  25.   if ( !hPrevInstance )
  26.      { wndclass.style        = CS_HREDRAW | CS_VREDRAW ;
  27.        wndclass.lpfnWndProc    = AppWndProc ;
  28.        wndclass.cbClsExtra     = 0 ;
  29.        wndclass.cbWndExtra    = 0 ;
  30.        wndclass.hInstance     = hInstance ;
  31.        wndclass.hIcon         = LoadIcon(NULL,IDI_APPLICATION) ;
  32.        wndclass.hCursor            = LoadCursor(NULL,IDC_ARROW) ;
  33.        wndclass.hbrBackground    = GetStockObject(WHITE_BRUSH) ;
  34.        wndclass.lpszMenuName    = NULL ;
  35.        wndclass.lpszClassName    = szAppName ;
  36.  
  37.        RegisterClass(&wndclass) ;
  38.      }
  39.  
  40.   hwnd = CreateWindow(szAppName,              // window class name
  41.               "Windows Application",  // window caption
  42.               WS_OVERLAPPEDWINDOW,    // window style
  43.               CW_USEDEFAULT,      // initial x position
  44.               0,                  // initial y position
  45.               CW_USEDEFAULT,      // initial x length
  46.               0,                  // initial y length
  47.               NULL,               // parent window handle
  48.               NULL,               // window menu handle
  49.               hInstance,          // program instance handle
  50.               NULL) ;             // parameters
  51.  
  52.   ShowWindow(hwnd,nCmdShow) ;
  53.   UpdateWindow(hwnd) ;
  54.  
  55.   while ( GetMessage(&msg, NULL, 0, 0) )
  56.     { TranslateMessage(&msg) ;
  57.       DispatchMessage(&msg) ;
  58.     }
  59.   return msg.wParam ;
  60. }
  61.  
  62.  
  63. long FAR PASCAL AppWndProc (HWND hwnd,
  64.                 WORD message,
  65.                 WORD wParam,
  66.                 LONG lParam)
  67. { switch (message)
  68.     { case WM_DESTROY:
  69.     PostQuitMessage(0) ;
  70.     break ;
  71.  
  72.       default:
  73.     return DefWindowProc(hwnd, message, wParam, lParam) ;
  74.     }
  75.   return 0 ;
  76. }
  77.