  //-----------------------------------------------------------------------------
  // Filename: Win32Creation.cpp
  // Description: Creates a simple Win32 window on screen  
  //-----------------------------------------------------------------------------

  #define WIN32_LEAN_AND_MEAN
  #include "Windows.h"

  // Function declarations
  int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);
  LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );

  // Globals
  static char strAppname[]="Our First Win32 App!";


  //-----------------------------------------------------------------------------
  // Name: WinMain()
  // Desc: The application's entry point
  //-----------------------------------------------------------------------------

  int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  {
      // Register the window class
      WNDCLASSEX wc;

      ZeroMemory(&wc, sizeof(WNDCLASSEX));
      wc.cbSize=sizeof(WNDCLASSEX);                       // size of the window struct in bytes
      wc.style=CS_HREDRAW | CS_VREDRAW | CS_OWNDC;        // window styles to use
      wc.lpfnWndProc=MsgProc;                             // function name of event handler
      wc.hInstance=hInstance;                             // handle to this apps instance
      wc.hbrBackground=(HBRUSH)GetStockObject(GRAY_BRUSH);// background colour of window
      wc.hIcon= LoadIcon(NULL, IDI_APPLICATION);          // icon for the app window
      wc.hIconSm=LoadIcon(NULL, IDI_APPLICATION);         // icon when minimized to taskbar
      wc.hCursor=LoadCursor(NULL, IDC_ARROW);             // cursor to use for this window
      wc.lpszClassName=strAppname;                        // name for this class

      RegisterClassEx( &wc );

      // Create the application's window
      HWND hWnd = CreateWindow(strAppname, strAppname,
          WS_OVERLAPPEDWINDOW, 100, 100, 640, 480,
          NULL, NULL, wc.hInstance, NULL );

      // Show the window
      ShowWindow( hWnd, nCmdShow );
      UpdateWindow( hWnd );

      // Enter the message loop
      MSG msg;
      ZeroMemory( &msg, sizeof(msg) );
      while( msg.message!=WM_QUIT )
      {
          if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
          {
              TranslateMessage( &msg );
              DispatchMessage( &msg );
          }
          else
          {
              // no winmessages, idle code here
          }
      }

      UnregisterClass( strAppname, wc.hInstance );
      return 0;

  }


  //-----------------------------------------------------------------------------
  // Name: MsgProc()
  // Desc: The window's message handler
  //-----------------------------------------------------------------------------
  LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
  {
      HDC hDC;
      PAINTSTRUCT PaintStruct;

      switch( msg )
      {
      case WM_PAINT:
          {
              hDC=BeginPaint(hWnd, &PaintStruct);     // Tell windows we want to update the window

              // Do GDI drawing here

              EndPaint(hWnd, &PaintStruct);
              return 0;
          }


      case WM_DESTROY:
          {
              PostQuitMessage( 0 );
              return 0;
          }

      default:

          return DefWindowProc( hWnd, msg, wParam, lParam );
      }

  }

