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

UINT LastBytes = sizeof (SYSTEMTIME) ;
UINT LastReps = 1 ;
extern DWORD TransferTime ;
extern LPDATAOBJECT lpd ;
extern UINT cfTimeData ;

extern IDataObject *pAptObj, *pFreeObj ;
extern DWORD		AptTransferTime, FreeTransferTime ;

IDataObject *pTestObj ;
DWORD *pTransferTime ;

BOOL CALLBACK TestDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg)
	{
		case WM_INITDIALOG:
		{
			if (lParam == TRUE)
			{
				pTestObj = (IDataObject *) pFreeObj ;
				pTransferTime = &FreeTransferTime ;
			}
			else
			{
				pTestObj = (IDataObject *) pAptObj ;
				pTransferTime = &AptTransferTime ;
			}

			SetDlgItemInt (hDlg, IDC_EDIT1, LastBytes, FALSE) ;
			SetDlgItemInt (hDlg, IDC_EDIT2, LastReps, FALSE) ;

			SetFocus (GetDlgItem (hDlg, IDC_EDIT1)) ;
			return FALSE ;
		}

		case WM_COMMAND:
		{
			if (LOWORD(wParam) == IDCANCEL)
			{
				EndDialog (hDlg, 0) ;
			}
			else if (LOWORD(wParam) == IDOK)
			{
				UINT i ;

				LastBytes = GetDlgItemInt (hDlg, IDC_EDIT1, NULL, FALSE) ;
				LastReps = GetDlgItemInt (hDlg, IDC_EDIT2, NULL, FALSE) ;

				DWORD InitTickCount = GetTickCount ( ) ;

				for (i = 0 ; i < LastReps ; i ++)
				{
					FORMATETC fe ;
					STGMEDIUM stm ;

					fe.cfFormat = cfTimeData ;
					fe.ptd = NULL ;
					fe.dwAspect = DVASPECT_CONTENT ;
					fe.lindex = LastBytes ;
					fe.tymed = TYMED_HGLOBAL ;

				 	if (SUCCEEDED(pTestObj->GetData (&fe, &stm)))
					{
						ReleaseStgMedium (&stm) ;
					}
				}

				*pTransferTime = GetTickCount( ) - InitTickCount ;
			//	InvalidateRect (GetParent(hDlg), NULL, TRUE) ;
				EndDialog (hDlg, 0) ;
			}

			return TRUE ;
		}

	}

	return FALSE ;
}
