/*
*********************************************************************
*
*	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: ENUMDLG.CPP
*
*	Purpose: Dialog box response function for storage element enumerator
*
*********************************************************************
*/


#include <windows.h>
#include "resource.h"
#include "main.h"



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

/*
This dialog box was launched with a call to DialogBoxParam.  When this message
is processed, lParam contains a pointer to the storage whose elements we
want to enumerate.  Use its methid EnumElements( ) to get a pointer to an
IEnumSTATSTG object, then use that object to fill a STATSTG structure for
each element of the storage. Take relevant pieces of the STATSTG and put
compose a string for each element to be shown in this dialog box's list box.
*/
		case WM_INITDIALOG:
		{
			LPSTORAGE pStg = (LPSTORAGE) lParam ;
			LPENUMSTATSTG pEnum ;
			STATSTG stat ;
			char out [256] ;

			pStg->EnumElements(0, NULL, 0, &pEnum) ;		

			while (pEnum->Next(1, &stat, NULL) == S_OK)
			{
				if (stat.type == STGTY_STORAGE)
				{
					wsprintf (out, "Strg: ") ;
				}
				else if (stat.type == STGTY_STREAM)
				{
					wsprintf (out, "Strm: ") ;
				} 
			
				wsprintf (out+6, "%ls, %d bytes", stat.pwcsName, stat.cbSize.LowPart) ; 

				SendDlgItemMessage (hDlg, IDC_LIST1, LB_ADDSTRING, 0, (LPARAM)out) ;
			}

			pEnum->Release ( ) ;

			return FALSE ;
		}

		case WM_COMMAND:
		{
			if (LOWORD(wParam) == IDOK)
			{  
				EndDialog (hDlg, IDOK) ;
				return TRUE ;
			}
			
			return FALSE ;
		}
	}

	return FALSE ;
}
