// SafecntrlCtl.cpp : Implementation of the CSafecntrlCtrl OLE control class.

#include "stdafx.h"
#include "safecntrl.h"
#include "SafecntrlCtl.h"
#include "SafecntrlPpg.h"


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


IMPLEMENT_DYNCREATE(CSafecntrlCtrl, COleControl)


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

BEGIN_MESSAGE_MAP(CSafecntrlCtrl, COleControl)
	//{{AFX_MSG_MAP(CSafecntrlCtrl)
	// 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(CSafecntrlCtrl, COleControl)
	//{{AFX_DISPATCH_MAP(CSafecntrlCtrl)
	// NOTE - ClassWizard will add and remove dispatch map entries
	//    DO NOT EDIT what you see in these blocks of generated code !
	//}}AFX_DISPATCH_MAP
	DISP_FUNCTION_ID(CSafecntrlCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()


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

BEGIN_EVENT_MAP(CSafecntrlCtrl, COleControl)
	//{{AFX_EVENT_MAP(CSafecntrlCtrl)
	// 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(CSafecntrlCtrl, 1)
	PROPPAGEID(CSafecntrlPropPage::guid)
END_PROPPAGEIDS(CSafecntrlCtrl)


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

IMPLEMENT_OLECREATE_EX(CSafecntrlCtrl, "SAFECNTRL.SafecntrlCtrl.1",
	0x4b3c0653, 0xbd2, 0x11d0, 0x8b, 0xfd, 0, 0x60, 0x8c, 0x87, 0x6f, 0xb3)


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

IMPLEMENT_OLETYPELIB(CSafecntrlCtrl, _tlid, _wVerMajor, _wVerMinor)


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

const IID BASED_CODE IID_DSafecntrl =
		{ 0x4b3c0651, 0xbd2, 0x11d0, { 0x8b, 0xfd, 0, 0x60, 0x8c, 0x87, 0x6f, 0xb3 } };
const IID BASED_CODE IID_DSafecntrlEvents =
		{ 0x4b3c0652, 0xbd2, 0x11d0, { 0x8b, 0xfd, 0, 0x60, 0x8c, 0x87, 0x6f, 0xb3 } };


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

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

IMPLEMENT_OLECTLTYPE(CSafecntrlCtrl, IDS_SAFECNTRL, _dwSafecntrlOleMisc)


/////////////////////////////////////////////////////////////////////////////
// CSafecntrlCtrl::CSafecntrlCtrlFactory::UpdateRegistry -
// Adds or removes system registry entries for CSafecntrlCtrl

BOOL CSafecntrlCtrl::CSafecntrlCtrlFactory::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_SAFECNTRL,
			IDB_SAFECNTRL,
			afxRegApartmentThreading,
			_dwSafecntrlOleMisc,
			_tlid,
			_wVerMajor,
			_wVerMinor);
	else
		return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}


/////////////////////////////////////////////////////////////////////////////
// CSafecntrlCtrl::CSafecntrlCtrl - Constructor

CSafecntrlCtrl::CSafecntrlCtrl()
{
	InitializeIIDs(&IID_DSafecntrl, &IID_DSafecntrlEvents);

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


/////////////////////////////////////////////////////////////////////////////
// CSafecntrlCtrl::~CSafecntrlCtrl - Destructor

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


/////////////////////////////////////////////////////////////////////////////
// CSafecntrlCtrl::OnDraw - Drawing function

void CSafecntrlCtrl::OnDraw(
			CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
	pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
	pdc->Ellipse(rcBounds);

	pdc->DrawText ("Safe", -1, (LPRECT) &rcBounds, DT_CENTER | DT_VCENTER | DT_SINGLELINE) ;
}


/////////////////////////////////////////////////////////////////////////////
// CSafecntrlCtrl::DoPropExchange - Persistence support

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

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

}


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

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

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


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

void CSafecntrlCtrl::AboutBox()
{
	CDialog dlgAbout(IDD_ABOUTBOX_SAFECNTRL);
	dlgAbout.DoModal();
}


/////////////////////////////////////////////////////////////////////////////
// CSafecntrlCtrl message handlers
