/*
*********************************************************************
*
*	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: MDI Child window for custom marshaling IEliza 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:
		{
		
			CREATESTRUCT *cs = (CREATESTRUCT *)lParam ;
			RECT r ;
			HWND hEdit ;
			
			GetClientRect (hWnd, &r) ;
			hEdit = 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_SIZE:
		{
			MoveWindow(GetDlgItem (hWnd, IDC_INCOMING), 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE) ;
			return 0 ;
    	}

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


