// TestOCXCtl.cpp : Implementation of the CTestOCXCtrl ActiveX Control class.

#include "stdafx.h"
#include "TestOCX.h"
#include "TestOCXCtl.h"
#include "TestOCXPpg.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


IMPLEMENT_DYNCREATE(CTestOCXCtrl, COleControl)


/////////////////////////////////////////////////////////////////////////////
// Message map

BEGIN_MESSAGE_MAP(CTestOCXCtrl, COleControl)
	//{{AFX_MSG_MAP(CTestOCXCtrl)
	// NOTE - ClassWizard will add and remove message map entries
	//    DO NOT EDIT what you see in these blocks of generated code !
	//}}AFX_MSG_MAP
	ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// Dispatch map

BEGIN_DISPATCH_MAP(CTestOCXCtrl, COleControl)
	//{{AFX_DISPATCH_MAP(CTestOCXCtrl)
	DISP_FUNCTION(CTestOCXCtrl, "SetArrayTest", SetArrayTest, VT_EMPTY, VTS_PI4)
	DISP_FUNCTION(CTestOCXCtrl, "SetArrayTest1", SetArrayTest1, VT_EMPTY, VTS_I4)
	//}}AFX_DISPATCH_MAP
	DISP_FUNCTION_ID(CTestOCXCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()


/////////////////////////////////////////////////////////////////////////////
// Event map

BEGIN_EVENT_MAP(CTestOCXCtrl, COleControl)
	//{{AFX_EVENT_MAP(CTestOCXCtrl)
	// NOTE - ClassWizard will add and remove event map entries
	//    DO NOT EDIT what you see in these blocks of generated code !
	//}}AFX_EVENT_MAP
END_EVENT_MAP()


/////////////////////////////////////////////////////////////////////////////
// Property pages

// TODO: Add more property pages as needed.  Remember to increase the count!
BEGIN_PROPPAGEIDS(CTestOCXCtrl, 1)
	PROPPAGEID(CTestOCXPropPage::guid)
END_PROPPAGEIDS(CTestOCXCtrl)


/////////////////////////////////////////////////////////////////////////////
// Initialize class factory and guid

IMPLEMENT_OLECREATE_EX(CTestOCXCtrl, "TESTOCX.TestOCXCtrl.1",
	0xa095ce1d, 0x941c, 0x45a4, 0xac, 0xb0, 0xae, 0xfa, 0xd5, 0x42, 0xe0, 0x2d)


/////////////////////////////////////////////////////////////////////////////
// Type library ID and version

IMPLEMENT_OLETYPELIB(CTestOCXCtrl, _tlid, _wVerMajor, _wVerMinor)


/////////////////////////////////////////////////////////////////////////////
// Interface IDs

const IID BASED_CODE IID_DTestOCX =
		{ 0xc56a060a, 0x44c7, 0x4949, { 0x87, 0x7c, 0x42, 0x6e, 0x25, 0x88, 0x1a, 0x15 } };
const IID BASED_CODE IID_DTestOCXEvents =
		{ 0x4d2ddc86, 0xa1ae, 0x410a, { 0xa8, 0xd7, 0xc9, 0x65, 0xec, 0x72, 0x7b, 0xb5 } };


/////////////////////////////////////////////////////////////////////////////
// Control type information

static const DWORD BASED_CODE _dwTestOCXOleMisc =
	OLEMISC_ACTIVATEWHENVISIBLE |
	OLEMISC_SETCLIENTSITEFIRST |
	OLEMISC_INSIDEOUT |
	OLEMISC_CANTLINKINSIDE |
	OLEMISC_RECOMPOSEONRESIZE;

IMPLEMENT_OLECTLTYPE(CTestOCXCtrl, IDS_TESTOCX, _dwTestOCXOleMisc)


/////////////////////////////////////////////////////////////////////////////
// CTestOCXCtrl::CTestOCXCtrlFactory::UpdateRegistry -
// Adds or removes system registry entries for CTestOCXCtrl

BOOL CTestOCXCtrl::CTestOCXCtrlFactory::UpdateRegistry(BOOL bRegister)
{
	// TODO: Verify that your control follows apartment-model threading rules.
	// Refer to MFC TechNote 64 for more information.
	// If your control does not conform to the apartment-model rules, then
	// you must modify the code below, changing the 6th parameter from
	// afxRegApartmentThreading to 0.

	if (bRegister)
		return AfxOleRegisterControlClass(
			AfxGetInstanceHandle(),
			m_clsid,
			m_lpszProgID,
			IDS_TESTOCX,
			IDB_TESTOCX,
			afxRegApartmentThreading,
			_dwTestOCXOleMisc,
			_tlid,
			_wVerMajor,
			_wVerMinor);
	else
		return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}


/////////////////////////////////////////////////////////////////////////////
// CTestOCXCtrl::CTestOCXCtrl - Constructor

CTestOCXCtrl::CTestOCXCtrl()
{
	InitializeIIDs(&IID_DTestOCX, &IID_DTestOCXEvents);

	// TODO: Initialize your control's instance data here.
}


/////////////////////////////////////////////////////////////////////////////
// CTestOCXCtrl::~CTestOCXCtrl - Destructor

CTestOCXCtrl::~CTestOCXCtrl()
{
	// TODO: Cleanup your control's instance data here.
}


/////////////////////////////////////////////////////////////////////////////
// CTestOCXCtrl::OnDraw - Drawing function

void CTestOCXCtrl::OnDraw(
			CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
	// TODO: Replace the following code with your own drawing code.
	pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
	pdc->Ellipse(rcBounds);
}


/////////////////////////////////////////////////////////////////////////////
// CTestOCXCtrl::DoPropExchange - Persistence support

void CTestOCXCtrl::DoPropExchange(CPropExchange* pPX)
{
	ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
	COleControl::DoPropExchange(pPX);

	// TODO: Call PX_ functions for each persistent custom property.

}


/////////////////////////////////////////////////////////////////////////////
// CTestOCXCtrl::OnResetState - Reset control to default state

void CTestOCXCtrl::OnResetState()
{
	COleControl::OnResetState();  // Resets defaults found in DoPropExchange

	// TODO: Reset any other control state here.
}


/////////////////////////////////////////////////////////////////////////////
// CTestOCXCtrl::AboutBox - Display an "About" box to the user

void CTestOCXCtrl::AboutBox()
{
	CDialog dlgAbout(IDD_ABOUTBOX_TESTOCX);
	dlgAbout.DoModal();
}


/////////////////////////////////////////////////////////////////////////////
// CTestOCXCtrl message handlers

void CTestOCXCtrl::SetArrayTest(__int64 FAR* param) 
{
	// TODO: Add your dispatch handler code here
		CString sLogMessage;
		CString sTemp;

	for (int i = 0; i < 5; i ++ )
	{
		sTemp.Format("%d ", param[i]);
		sLogMessage += sTemp;
		param[i] = i;
	}

	AfxMessageBox(sLogMessage);

}

void CTestOCXCtrl::SetArrayTest1(long param) 
{
	// TODO: Add your dispatch handler code here
		long *pBuffer = (long *)param;

		CString sLogMessage;
		CString sTemp;

		for (int i = 0; i < 5; i ++ )
		{
			sTemp.Format("%d ", pBuffer[i]);
			sLogMessage += sTemp;
			pBuffer[i] = i;
		}

		AfxMessageBox(sLogMessage);

}
