// ----------------------------
// Title:		Simple win32 application
// File:		WinMain.cpp
// Author:		Jaap Suter
// Created:		November 29 1999
//
// Info:		This file contains a simple win32 application.
//



// ----------------------------
// Includes;
#include "windows.h"

// ----------------------------
// Function declarations;
LRESULT WINAPI MainWindowProcedure( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

// -----------------------
// Global message enum
enum tag_MessageEnum
{
	APPLICATION_RUNNING,
	APPLICATION_ACTIVATED,
	APPLICATION_DEACTIVATED,
	APPLICATION_QUIT,
	APPLICATION_RESIZE,
	APPLICATION_MOVE,
} g_MessageEnum;


// -----------------------------
// WinMain 
// Application entry point function
// -----------------------
int WINAPI WinMain(  HINSTANCE hInstance,  
                     HINSTANCE hPrevInstance,  
                     LPSTR lpCmdLine,      
                     int nCmdShow          
                   )
{
	// -----------------------
	// Variables;
	WNDCLASS windowClass;        // Declare a windowsClass structure;
	HWND windowHandle;           // Declare a handle to the window;
	MSG  message;				 // Declare a message struct;
	
	bool bQuit = false;			 // True if the application should quit;

	// ------------------------
	// Start of program
	
	
	// Fill the windowClass structure with relevant info;
	windowClass.lpszClassName     = "Simple Application Window Class";
	windowClass.lpfnWndProc       = MainWindowProcedure;
	windowClass.style             = CS_VREDRAW | CS_HREDRAW;
	windowClass.hInstance         = hInstance;
	windowClass.hIcon             = LoadIcon( NULL, IDI_APPLICATION );
	windowClass.hCursor           = LoadCursor( NULL, IDC_ARROW );
	windowClass.hbrBackground     = (HBRUSH)( COLOR_WINDOW+1 );
	windowClass.lpszMenuName      = NULL;
	windowClass.cbClsExtra        = 0;
	windowClass.cbWndExtra        = 0;

	// And register at Bill's place;
	RegisterClass( &windowClass );


	// Create the window itself;
	windowHandle = CreateWindow( "Simple Application Window Class",
								 "Simple Application",
								 WS_OVERLAPPEDWINDOW,
								 0,    
								 0,
								 CW_USEDEFAULT,
								 CW_USEDEFAULT,
								 NULL,
								 NULL,
								 hInstance,
								 NULL
							   );

	
	// Show the window;
	ShowWindow( windowHandle, nCmdShow );

	// Enter the message Loop;
	while( !bQuit ) 
	{
		// Handle the messages;
		while ( PeekMessage( &message, NULL, 0, 0, PM_REMOVE ) )
		{
			TranslateMessage( &message );
			DispatchMessage( &message );
		}
		
		// ----------------------------------------------------
		// Do all game related stuff here;



		// End of game related stuff;
		// ----------------------------------------------------

		// Quit when ESC is pressed or the window is closed;
		if ( (GetAsyncKeyState( VK_ESCAPE )) || (g_MessageEnum == APPLICATION_QUIT) ) 
		{
			bQuit = true;
		}

	}

	// Everythin went fine;
	return 0;
}
// ------------------------------------------
// End of WinMain;
// ------------------------------------------


// ------------------------------------------
// ::MainWindowProcedure
// Handles all the messages;
// ------------------------------------------
LRESULT WINAPI MainWindowProcedure( HWND hWnd,                                     
								    UINT msg,                                     
									WPARAM wParam,                                     
									LPARAM lParam )
{
	switch ( msg )
	{
		case ( WM_CLOSE ):
			g_MessageEnum = APPLICATION_QUIT;
			DestroyWindow( hWnd );
			return 0;
		break;

		// Note:
		// You might want to handle window resize, 
		// window movement and other messages as well in 
		// the future, 
		// just extend this switch-case statement;
	}
    
	return( DefWindowProc( hWnd, msg, wParam, lParam ));
}
// ------------------------------------------
// End of MainWindowProcedure
// ------------------------------------------


// End of File
// ------------------------------------------

 
