/*
*********************************************************************
*
*	The Essence of OLE
*
*	Source code sample
*
*	Copyright (c) 1996, Rolling Thunder Computing, Ipswich MA
*
*	e-mail: essence@rollthunder.com
*	CompuServe: 73540.3430
*	Web: http://www.rollthunder.com
*
*	File Name: WINMAIN.CPP
*
*	Purpose: Windows entry point.
*
*********************************************************************
*/

/*
*****************************************************************************
System header files
*****************************************************************************
*/

#include	<windows.h>

/*
*****************************************************************************
Application header files
*****************************************************************************
*/


#include "main.h"

/*
*****************************************************************************
Function prototype files
*****************************************************************************
*/


/*
*****************************************************************************
Global Variables defined here
*****************************************************************************
*/


HINSTANCE hInst;
HWND  hMainWnd ;


/*
*****************************************************************************
EXTERNS of global variables defined in other files
*****************************************************************************
*/


/*
**************************************************************************
*
*		Function Name:  WinMain
*
*		Purpose: initializes, processes message loop
*        Windows recognizes this function by name as the initial entry point
*        for the program.  This function calls the application initialization
*        routine, if no other instance of the program is running, and always
*        calls the instance initialization routine.  It then executes a message
*        retrieval and dispatch loop that is the top-level control structure
*        for the remainder of execution.  The loop is terminated when a WM_QUIT
*        message is received, at which time this function exits the application
*        instance by returning the value passed by PostQuitMessage().
*
*
*		Calling Parmeters, provided automatically by Windows
*			HANDLE hInstance:	 current instance	handle
*			HANDLE hPrevInstance: previous instance handle
*			LPSTR lpCmdLine: command line
*			int nCmdShow:  show-window type (open/icon)
*
*		Returns:
*			NULL if terminated before window message loop activates, otherwise
*			value provided by call elsewhere to PostQuitMessage
*
*		Global Variables Used:
*			Sets values for hIWWInst and IWWMainWindow, used by many other fns
*
*		Side Effects: None Known
*
*		Caveats: None Known
*
*
**************************************************************************
*/

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
	LPSTR lpCmdLine, int nCmdShow)
{
    MSG msg;
    WNDCLASS  wc;
 	
	hInst = hInstance ;
	char *Class = "Ole Demo" ;
	
/*
Initialize Ole Libraries
*/

	HRESULT hr = OleInitialize (NULL) ;

/*
Initialize window classes, exits if it can't
*/

	wc.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW; 		
    wc.lpfnWndProc = MainWndProc;       
    wc.cbClsExtra = 0;                  
    wc.cbWndExtra = 0;                 
    wc.hInstance = hInst;           
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName =  "MainMenu";   
    wc.lpszClassName = Class; 

	if (RegisterClass(&wc) == FALSE)
	{
		MessageBox (NULL, "FATAL ERROR\nCould not register Main window class", 
			"ERROR", MB_ICONSTOP) ;
		return FALSE ;
	}



/*
Create a main window for this application instance.
*/



    hMainWnd = CreateWindow(
        Class, "Essence of OLE iperstreamcl.exe", WS_OVERLAPPEDWINDOW ,          
	 	CW_USEDEFAULT, CW_USEDEFAULT, 400, 200,
	 	NULL, NULL, hInst, NULL);


    if (!hMainWnd)
	{
		MessageBox (NULL, "FATAL ERROR\nCould not create Main window", 
			ERROR, MB_ICONSTOP) ;
        return (FALSE);
	}


/*
Make main window visible; update its client area
*/

    ShowWindow(hMainWnd, nCmdShow);             


/*
Acquire and dispatch messages until a WM_QUIT message is received.
*/

	 while (GetMessage(&msg, NULL, NULL, NULL))	
	{
	 	TranslateMessage(&msg);	   
		DispatchMessage(&msg);	 
	}


/*
Shut down OLE libraries
*/

	OleUninitialize ( ) ;



	return (msg.wParam);

}

