/*
*********************************************************************
*
*	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"
#include "cclassf.h"


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


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


HINSTANCE hInst;
HWND  hMainWnd ;

UINT cfTimeData ;


// {E0DA1130-5117-11cf-89F4-00AA00A58097}
GUID GUID_PersistTimeData = { 0xe0da1130, 0x5117, 0x11cf, { 0x89, 0xf4, 0x0, 0xaa, 0x0, 0xa5, 0x80, 0x97 } };

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



    hMainWnd = CreateWindow(Class,                    
        "Essence of OLE Data iperstreamsv.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);
	}

/*
Register private clipboard formats
*/

	cfTimeData = RegisterClipboardFormat ("TimeDataObject") ;

/*
Check command line to see if launched as an OLE server.  If so, register
the class factory for this app.
*/

	DWORD dwRegister ;

	if (strstr (lpCmdLine, "-Embedding"))
	{
		LPCLASSFACTORY pCF = new CClassFactory ( ) ;

		CoRegisterClassObject(
			GUID_PersistTimeData, 
			pCF, 
			CLSCTX_LOCAL_SERVER,
			REGCLS_MULTIPLEUSE,
			&dwRegister) ;

	}

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

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


/*
App going down, shut down class factory
*/

	CoRevokeClassObject (dwRegister) ;


/*
Shut down OLE libraries
*/

	OleUninitialize ( ) ;

	return (msg.wParam);

}

