⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shareware.cpp

📁 VC++实现的多页面浏览器....实现了多种功能
💻 CPP
字号:
// Shareware.cpp: implementation of the CShareware class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Shareware.h"

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

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CShareware::CShareware()
{

}

CShareware::~CShareware()
{
	this->Close();
}


/*
*******************************************************************************/
// FUNCTION : long  CShareware::Create(LPCTSTR,DWORD,int,DWORD,HKEY)
//
// PURPOSE	 : create (open) the shareware information
//
// PARAMETERS : 
//		Base		- location in the registry
//		Number		- number max of uses (in times, or in DAYS!)
//		Type		- type of limitation: BY_DAY or BY_TIME
//		DWORD		- Version of the shareware
//		Parent		- base key parent in the registry
//
// RETURN VALUE : long 
//
//
// COMMENTS : the Version number allows the user to use an upgrade of the shareware
// if you want to upgrade your shareware, just give a new exe with a HIGHER build
// number and the count will start form the beginning.
//
//
/*******************************************************************************
*/
long CShareware::Create(LPCTSTR Base, DWORD Number, int Type, DWORD Version, HKEY Parent)
{
	// Parent can be HKEY_CURRENT_USER, HKEY_CLASSES_ROOT, HKEY_LOCAL_MACHINE e.g
	m_Parent = Parent;
	m_pszBase = Base;
	m_iType = Type;
	m_dNumber = Number;
	m_dVersion = Version;

	long hRes = CRegKey::Create(Parent,
		Base,
		REG_NONE,
		REG_OPTION_NON_VOLATILE);
	if (hRes != ERROR_SUCCESS)
		return hRes;

	// check for a previous value
	DWORD ver;
	hRes = QueryValue(ver,"Version");
	if (hRes == ERROR_SUCCESS) {
		// a previous version exists
		// compare the numbers.
		// if actual version > registry version, reset the count
		if (ver < m_dVersion) {
			DeleteValue(NULL);
			SetValue(m_dVersion,"Version");
		}
	}
	else {
		SetValue(m_dVersion,"Version");
	}



	hRes = QueryValue(m_dActualNumber,NULL);
	if (hRes != ERROR_SUCCESS) {
		// first time !
		switch (m_iType) {
		case BY_TIME:
			m_dActualNumber = 0;
			break;
		case BY_DAY:
			{
				CTime time = CTime::GetCurrentTime();
				m_dActualNumber = time.GetYear();
				m_dActualNumber = m_dActualNumber * 100;
				m_dActualNumber += time.GetMonth();
				m_dActualNumber = m_dActualNumber * 100;
				m_dActualNumber += time.GetDay();
				break;
			}
		}
		SetValue(m_dActualNumber,NULL);
	}
	return ERROR_SUCCESS;
}


/*
*******************************************************************************/
// FUNCTION : BOOL  CShareware::IsFinished()
//
// PURPOSE	 : true if the trial period is finished
//
// PARAMETERS : none
//
// RETURN VALUE : BOOL 
//
//
// COMMENTS : 
//
//
/*******************************************************************************
*/
BOOL CShareware::IsFinished()
{
	switch (m_iType) {
	case BY_TIME:
		return (m_dActualNumber > m_dNumber);
		break;
	case BY_DAY:
		{
			int Y,M,D; 
			DWORD tmp;
			tmp = m_dActualNumber;
			D = tmp - ((DWORD)(tmp/100)) * 100;
			tmp = (DWORD)(tmp/100);
			M = tmp - ((DWORD)(tmp/100)) * 100;
			Y = (int)(tmp/100);
			CTime time_limit(Y,M,D+m_dNumber,0,0,0,0);
			CTime today = CTime::GetCurrentTime();
			//CString s1 = time_limit.Format( "%A, %B %d, %Y" );
			//CString s2 = today.Format( "%A, %B %d, %Y" );
			//AfxMessageBox("Limit: "+s1+"\n\rToday: "+s2);
			if (today > time_limit)
				return TRUE;
			return FALSE;
			break;
		}
	}
	return FALSE;
}


/*
*******************************************************************************/
// FUNCTION : long  CShareware::Increment()
//
// PURPOSE	 : increment the number of uses
//
// PARAMETERS : none
//
// RETURN VALUE : long 
//
//
// COMMENTS : do nothing if BY_DAY mode
//
//
/*******************************************************************************
*/
long CShareware::Increment()
{
	switch (m_iType) {
	case BY_TIME:
		m_dActualNumber++;
		break;
	}
	return (SetValue(m_dActualNumber,NULL));
}


/*
*******************************************************************************/
// FUNCTION : DWORD  CShareware::GetCurrentNumber()
//
// PURPOSE	 : get the current of uses
//
// PARAMETERS : none
//
// RETURN VALUE : DWORD 
//
//
// COMMENTS : valid only if type == BY_TIME
//
//
/*******************************************************************************
*/
DWORD CShareware::GetCurrentNumber()
{
	return m_dActualNumber;
}


/*
*******************************************************************************/
// FUNCTION : long  CShareware::Reset()
//
// PURPOSE	 : 
//
// PARAMETERS : none
//
// RETURN VALUE : long 
//
//
// COMMENTS : 
//
//
/*******************************************************************************
*/
long CShareware::Reset()
{
	m_dActualNumber = 0;
	return DeleteValue(NULL);
}


/*
*******************************************************************************/
// FUNCTION : DWORD  CShareware::GetMaxNumber()
//
// PURPOSE	 : return the max number of uses
//
// PARAMETERS : none
//
// RETURN VALUE : DWORD 
//
//
// COMMENTS : valid if BY_TIME
//
//
/*******************************************************************************
*/
DWORD CShareware::GetMaxNumber()
{
	return m_dNumber;
}


/*
*******************************************************************************/
// FUNCTION : CTime  CShareware::GetLimitDay()
//
// PURPOSE	 : return the limit day of use
//
// PARAMETERS : none
//
// RETURN VALUE : CTime 
//
//
// COMMENTS : valid if BY_DAY
//
//
/*******************************************************************************
*/
CTime CShareware::GetLimitDay()
{
	int Y,M,D; 
	DWORD tmp;
	tmp = m_dActualNumber;
	D = tmp - ((DWORD)(tmp/100)) * 100;
	tmp = (DWORD)(tmp/100);
	M = tmp - ((DWORD)(tmp/100)) * 100;
	Y = (int)(tmp/100);
	CTime time_limit(Y,M,D+m_dNumber,0,0,0);
	return time_limit;
}


/*
*******************************************************************************/
// FUNCTION : int  CShareware::GetType()
//
// PURPOSE	 : return the type of limitation
//
// PARAMETERS : none
//
// RETURN VALUE : int 
//
//
// COMMENTS : return BY_DAY or BY_TIME
//
//
/*******************************************************************************
*/
int CShareware::GetType()
{
	return m_iType;
}


/*
*******************************************************************************/
// FUNCTION : DWORD  CShareware::GetVersion()
//
// PURPOSE	 : return the version of the shareware
//
// PARAMETERS : none
//
// RETURN VALUE : DWORD 
//
//
// COMMENTS : 
//
//
/*******************************************************************************
*/
DWORD CShareware::GetVersion()
{
	return m_dVersion;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -