/*
**************************************************************************

	Filename: WINMAIN.C

	Purpose:  Initial entry point for WINSV, the Windows Server


	Rev #		Date	Engineer			Reason
	--------------------------------------------------------------------------
	1.0									Initial Release


	--------------------------------------------------------------------------

	Copyright (C) 1990

	Rolling Thunder Computing, Inc.
	20 Hilltop Terrace
	Woburn MA 01801 USA

*****************************************************************************
*/


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

	HRESULT hr = OleInitialize (NULL) ;

/*
Initialize window classes, exits if it can't
First for the main window
*/

	wc.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW; 			 /* Class style(s).                    */
    wc.lpfnWndProc = MainWndProc;       /* Function to retrieve messages for  windows of this class	*/
    wc.cbClsExtra = 0;                  /* No per-class extra data.           */
    wc.cbWndExtra = 0;                  /* No per-window extra data.          */
    wc.hInstance = hInst;           /* Application that owns the class.   */
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName =  "MainMenu";   /* Name of menu resource in .RC file. */
    wc.lpszClassName = Class; /* Name used in call to CreateWindow. */

	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.
Position and size it as it was the last time it was shut down with SAVE
CHANGES checked
If window could not be created, return "failure"
*/



    hMainWnd = CreateWindow(
        Class,                    /* See RegisterClass() call.          */
        "Essence of COM Remote Data Object Client",      /* Text for window title bar.         */
        WS_OVERLAPPEDWINDOW ,          /* Window style.                      */
	 	CW_USEDEFAULT,  
	 	CW_USEDEFAULT,   
	 	400,   
	 	200,
	 	NULL,                           /* Overlapped windows have no parent. */
        NULL,                           /* Use the window class menu.         */
        hInst,	                      /* This instance owns this window.    */
        NULL                            /* Pointer not needed.                */
    );


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


/*
Make main window visible; update its client area
Zoom if was zoomed last time changes were saved
*/

    ShowWindow(hMainWnd, nCmdShow);             


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

	 while (GetMessage(&msg,	   /* message structure			     */
	    NULL,							   /* handle of window receiving the message */
	    NULL,		   					/* lowest message to examine		     */
	    NULL))		   					/* highest message to examine	     */
	{
	 	TranslateMessage(&msg);	   /* Translates virtual key codes	     */
		DispatchMessage(&msg);	   /* Dispatches message to window	     */
	}


/*
Shut down OLE libraries
*/

	OleUninitialize ( ) ;


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


	 return (msg.wParam);

}

