/*
*********************************************************************
*
*	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: SUMMRDLG.CPP
*
*	Purpose: Dialog box response function for summary information editing 
*
*********************************************************************
*/


#include <windows.h>

#include "resource.h"
#include "main.h"


BOOL WINAPI SummaryDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{

	static LPSTORAGE pSubStg ;
	static LPSTREAM pTitle, pAuthor ;

	switch (message)
	{

/*
STEP 5
Open substorage and streams where author and title live. Read them in and
set them into the edit controls.  Hang on to objects until done.
*/

		case WM_INITDIALOG:
		{

			char buf [256] ; 
			LPSTORAGE pMainStg = (LPSTORAGE) lParam ;

			SetDlgItemText (hDlg, IDC_EDIT1, buf) ;

			SetDlgItemText (hDlg, IDC_EDIT2, buf) ;


	
			SetFocus (GetDlgItem (hDlg, IDC_EDIT1)) ;
			SendDlgItemMessage (hDlg, IDC_EDIT1, EM_SETSEL, 0, -1) ;
			return FALSE ;
		}

		case WM_COMMAND:
		{

			char buf [256] ;  

/*
STEP 5
If user clicked OK, then check each edit control.  If its contents have
changed, fetch them and write them into the respective streams.  Then release
all storages and streams
*/

			if (LOWORD(wParam) == IDOK)
			{

				if (SendDlgItemMessage (hDlg, IDC_EDIT2, EM_GETMODIFY, 0, 0))
				{
					LARGE_INTEGER ZeroL = {0, 0} ;	

					GetDlgItemText (hDlg, IDC_EDIT2, buf, sizeof(buf)) ;

				}
	
				if (SendDlgItemMessage (hDlg, IDC_EDIT1, EM_GETMODIFY, 0, 0))
				{
					LARGE_INTEGER ZeroL = {0, 0} ;	

					GetDlgItemText (hDlg, IDC_EDIT1, buf, sizeof(buf)) ;

				}
			
				pAuthor->Release( ) ;
				pTitle->Release( ) ;
				pSubStg->Release( ) ;

				EndDialog (hDlg, IDOK) ;
				return TRUE ;
			}
			else  if (LOWORD (wParam) == IDCANCEL)
			{
				EndDialog (hDlg, IDCANCEL) ;
				pAuthor->Release( ) ;
				pTitle->Release( ) ;
				pSubStg->Release( ) ;
			}

			return FALSE ;
		}
	}

	return FALSE ;
}
