home *** CD-ROM | disk | FTP | other *** search
/ Cutting-Edge 3D Game Programming with C++ / CE3DC++.ISO / BOOK / CHAP13 / HWORLD.CPP next >
Encoding:
C/C++ Source or Header  |  1996-05-24  |  4.0 KB  |  123 lines

  1. //
  2. // File name: HWorld.CPP
  3. //
  4. // Description: The main file for the Hello World example.
  5. //
  6. // Author: John De Goes
  7. //
  8. // Project: Cutting Edge 3D Game Programming
  9. //
  10.  
  11. // ------------------------------------------------------------
  12. // | Global include files:                                    |
  13. // ------------------------------------------------------------
  14.  
  15. #include <Math.H>
  16. #include <Conio.H>
  17. #include <Time.H>
  18. #include <Stdio.H>
  19. #include <Windows.H>
  20. #include <Iostream.H>
  21.  
  22. // ------------------------------------------------------------
  23. // | Local include files:                                     |
  24. // ------------------------------------------------------------
  25. #include "HWORLD.RH"
  26.  
  27. // ------------------------------------------------------------
  28. // | Global variables/constants:                              |
  29. // ------------------------------------------------------------
  30.  
  31. LRESULT CALLBACK WndProc ( HWND hWnd, unsigned int iMessage,
  32.                           unsigned int wParam, LONG lParam );
  33.  
  34. HANDLE ThisInstance;
  35.  
  36. // ------------------------------------------------------------
  37. // | Program entry:                                           |
  38. // ------------------------------------------------------------
  39.  
  40. int WINAPI WinMain ( HANDLE hInstance, HANDLE hPrevInstance,
  41.             LPSTR lpszCmdParam, int nCmdShow )
  42.  
  43.   {
  44.   hPrevInstance; lpszCmdParam;
  45.   ThisInstance = hInstance;
  46.   HWND hWnd;
  47.   MSG Message;
  48.   WNDCLASS WndClass;
  49.  
  50.   WndClass.cbClsExtra = 0;
  51.   WndClass.cbWndExtra = 0;
  52.   WndClass.hbrBackground = GetStockObject ( GRAY_BRUSH );
  53.   WndClass.hCursor =  LoadCursor ( NULL, IDC_ARROW );
  54.   WndClass.hIcon   = LoadIcon ( hInstance, NULL );
  55.   WndClass.hInstance = hInstance;
  56.   WndClass.lpfnWndProc = WndProc;
  57.   WndClass.lpszClassName = "HWORLD";
  58.   WndClass.lpszMenuName = ( const char * ) MENU_1;
  59.   WndClass.style = CS_HREDRAW | CS_VREDRAW;
  60.  
  61.   if ( !RegisterClass ( &WndClass ) )
  62.      return 0;           
  63.  
  64.   hWnd = CreateWindow ( "HWORLD",             // class name
  65.                         "Hello World!",  // Caption
  66.                         WS_OVERLAPPEDWINDOW,// Style
  67.                         CW_USEDEFAULT,           // x position
  68.                         CW_USEDEFAULT,           // y position
  69.                         CW_USEDEFAULT,           // cx - size
  70.                         CW_USEDEFAULT,           // cy - size
  71.                         NULL,                    // Parent window
  72.                         NULL,                    // Menu
  73.                         hInstance,               // Program Instance
  74.                         NULL );                  // Parameters
  75.  
  76.   ShowWindow ( hWnd, nCmdShow );
  77.  
  78.   while ( GetMessage ( &Message, hWnd, 0, 0 ) )
  79.         {
  80.         TranslateMessage ( &Message );
  81.         DispatchMessage ( &Message );
  82.         }
  83.  
  84.   return Message.wParam;
  85.   }
  86.  
  87. LRESULT CALLBACK WndProc ( HWND hWnd, unsigned int iMessage,
  88.                           unsigned int wParam, LONG lParam )
  89.    {
  90.    switch ( iMessage )
  91.           {
  92.           case ( WM_CREATE ):
  93.                {
  94.                break;
  95.                }
  96.           case ( WM_COMMAND ):
  97.                {
  98.                switch ( LOWORD ( wParam ) )
  99.                       {
  100.                       case ( CM_FILE_EXIT ):
  101.                            {
  102.                            PostQuitMessage ( 0 );
  103.                            break;
  104.                            }
  105.                       case ( CM_HELP_ABOUT ):
  106.                            {
  107.                            MessageBox ( hWnd, "Hello World Example", "About", MB_OK );
  108.                            break;
  109.                            }
  110.                       }
  111.                break;
  112.                }
  113.           case ( WM_DESTROY ):
  114.                {
  115.                PostQuitMessage ( 0 );
  116.                break;
  117.                }
  118.           default:
  119.                  return DefWindowProc ( hWnd, iMessage, wParam,
  120.                                       lParam );
  121.           }
  122.    return 0;
  123.    }