/*
*********************************************************************
*
*	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
*****************************************************************************
*/


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 = (HBRUSH) 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.
If window could not be created, return "failure"
*/



    hMainWnd = CreateWindow(
        Class,                    
        "Essence of OLE Data1.exe",     
        WS_OVERLAPPEDWINDOW | WS_VISIBLE , 
		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);
	}


/*
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
*/

	if (SUCCEEDED(hr))
	{
		OleUninitialize ( ) ;
	}


/*
Finished with application.  Return value from PostQuitMessage
*/                                  


	 return (msg.wParam);

}

