// LicCtl.cpp : Implementation of the CLicCtrl OLE control class.

#include "stdafx.h"
#include "lic.h"
#include "LicCtl.h"
#include "LicPpg.h"
#include "nagdlg.h"

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


IMPLEMENT_DYNCREATE(CLicCtrl, COleControl)


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

BEGIN_MESSAGE_MAP(CLicCtrl, COleControl)
	//{{AFX_MSG_MAP(CLicCtrl)
	// 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(CLicCtrl, COleControl)
	//{{AFX_DISPATCH_MAP(CLicCtrl)
	// 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(CLicCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()


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

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


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

IMPLEMENT_OLECREATE_EX(CLicCtrl, "LIC.LicCtrl.1",
	0x72c27db3, 0xd682, 0x11cf, 0x9d, 0x9a, 0, 0x60, 0x8c, 0x87, 0x6f, 0xb3)


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

IMPLEMENT_OLETYPELIB(CLicCtrl, _tlid, _wVerMajor, _wVerMinor)


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

const IID BASED_CODE IID_DLic =
		{ 0x72c27db1, 0xd682, 0x11cf, { 0x9d, 0x9a, 0, 0x60, 0x8c, 0x87, 0x6f, 0xb3 } };
const IID BASED_CODE IID_DLicEvents =
		{ 0x72c27db2, 0xd682, 0x11cf, { 0x9d, 0x9a, 0, 0x60, 0x8c, 0x87, 0x6f, 0xb3 } };


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

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

IMPLEMENT_OLECTLTYPE(CLicCtrl, IDS_LIC, _dwLicOleMisc)


/////////////////////////////////////////////////////////////////////////////
// CLicCtrl::CLicCtrlFactory::UpdateRegistry -
// Adds or removes system registry entries for CLicCtrl

BOOL CLicCtrl::CLicCtrlFactory::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_LIC,
			IDB_LIC,
			afxRegApartmentThreading,
			_dwLicOleMisc,
			_tlid,
			_wVerMajor,
			_wVerMinor);
	else
		return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}


/////////////////////////////////////////////////////////////////////////////
// Licensing strings

static const TCHAR BASED_CODE _szLicFileName[] = _T("lic.lic");

static const WCHAR BASED_CODE _szLicString[] =
	L"Copyright (c) 1996 Rolling Thunder Computing";


/////////////////////////////////////////////////////////////////////////////
// CLicCtrl::CLicCtrlFactory::VerifyUserLicense -
// Checks for existence of a user license

BOOL CLicCtrl::CLicCtrlFactory::VerifyUserLicense()
{
	if (!AfxVerifyLicFile(AfxGetInstanceHandle(), _szLicFileName,
		_szLicString))
	{
		CNagDlg dlg ;

		dlg.DoModal ( ) ;
	}

	return TRUE ;
}


/////////////////////////////////////////////////////////////////////////////
// CLicCtrl::CLicCtrlFactory::GetLicenseKey -
// Returns a runtime licensing key

BOOL CLicCtrl::CLicCtrlFactory::GetLicenseKey(DWORD dwReserved,
	BSTR FAR* pbstrKey)
{
	if (pbstrKey == NULL)
		return FALSE;

	*pbstrKey = SysAllocString(_szLicString);
	return (*pbstrKey != NULL);
}


/////////////////////////////////////////////////////////////////////////////
// CLicCtrl::CLicCtrl - Constructor

CLicCtrl::CLicCtrl()
{
	InitializeIIDs(&IID_DLic, &IID_DLicEvents);

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


/////////////////////////////////////////////////////////////////////////////
// CLicCtrl::~CLicCtrl - Destructor

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


/////////////////////////////////////////////////////////////////////////////
// CLicCtrl::OnDraw - Drawing function

void CLicCtrl::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);
}


/////////////////////////////////////////////////////////////////////////////
// CLicCtrl::DoPropExchange - Persistence support

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

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

}


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

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

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


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

void CLicCtrl::AboutBox()
{
	CDialog dlgAbout(IDD_ABOUTBOX_LIC);
	dlgAbout.DoModal();
}


/////////////////////////////////////////////////////////////////////////////
// CLicCtrl message handlers
