/*
*********************************************************************
*
*	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: CHANLWND.CPP
*
*	Purpose: Main window response function for IEliza custom interface
*		local server. 
*
*********************************************************************
*/

#include <windows.h>
#include "pipesv.h"


extern HINSTANCE hInst ;
extern HWND hMainWnd ;
extern int ObjectCount, LockCount ;

LONG CALLBACK ChannelWndProc (HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
	switch (Message)
	{
/*
Allocate a structure of type CHANNEL, store its pointer in our extra bytes
Create and fill it with the elements it needs
*/

		case WM_CREATE:
		{
		
			CHANNEL *pCh ;
			CREATESTRUCT *cs = (CREATESTRUCT *)lParam ;
			RECT r ;
		

			GetClientRect (hWnd, &r) ;

			pCh = (CHANNEL *) GlobalAlloc (GMEM_FIXED, sizeof (CHANNEL)) ;
			SetWindowLong (hWnd, 0, (LONG)pCh) ;

			pCh->hInWnd = CreateWindow (TEXT("edit"), TEXT(""),
				WS_CHILD | WS_BORDER | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY,
				0, 0, r.right, r.bottom,
				hWnd, (HMENU) IDC_INCOMING, hInst, NULL) ;

			return 0 ;

		}


		case WM_PAINT:
		{
			HDC hDC ;
			PAINTSTRUCT ps ;

			hDC = BeginPaint (hWnd, &ps) ;

			TextOut (hDC, 10, 70, TEXT("Incoming Text"), 13) ;

			EndPaint (hWnd, &ps) ;
			return 0 ;

		}

		case WM_SIZE:
		{
			CHANNEL *pCh ;

			pCh = (CHANNEL *) GetWindowLong (hWnd, 0) ;

			MoveWindow(pCh->hInWnd, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE) ;
			return 0 ;
    	}

		case WM_CLOSE:
		{
			CHANNEL *pCh ;

			pCh = (CHANNEL *) GetWindowLong (hWnd, 0) ;
			GlobalFree (pCh) ;

			ObjectCount -- ;
			if (ObjectCount == 0 && LockCount == 0)
			{
				DestroyWindow (hMainWnd) ;
			}			
			return DefMDIChildProc (hWnd, Message, wParam, lParam) ;
		}

		default:
		{
			return DefMDIChildProc (hWnd, Message, wParam, lParam) ;
		}
	}
}


