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

📄 definefunction.cpp

📁 序列号生成工具,使用MD5加密算法,生成程序的序列号,帮助程序员保护自己的产权.
💻 CPP
字号:
// DefineFunction.cpp: implementation of the CDefineFunction class.
//
//////////////////////////////////////////////////////////////////////
#include "StdAfx.h"
#include "DefineFunction.h"

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

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

CDefineFunction::CDefineFunction()
{

}

CDefineFunction::~CDefineFunction()
{

}

//切割字符串
//将strToSplit字符串用splitStr切割符切割后返回保存切割后字符串的CStringArray类型对象的指针
CStringArray* CDefineFunction::SplitString(CString strToSplit, LPCTSTR splitStr)
{
	int startIndex=0;
	int SplitLength=strlen(splitStr);
	CStringArray* strArray=new CStringArray();

	while(TRUE)
	{
		int retIndex=strToSplit.Find(splitStr,startIndex);
		if(retIndex<0)
		{
			CString strRet=strToSplit.Mid(startIndex);
			if(strRet.GetLength()>0) strArray->Add(strRet);
			break;
		}
		CString strRet=strToSplit.Mid(startIndex,retIndex-startIndex);
		if(strRet.GetLength()>0) strArray->Add(strRet);
		startIndex=retIndex+SplitLength;
		if(startIndex>strToSplit.GetLength()-1) break;
	}
	return strArray;
}

///////切割字符串
///////将strToSplit字符串用splitStr切割符切割后保存在strArray对象中返回
void CDefineFunction::SplitString(CString strToSplit, LPCTSTR splitStr,CStringArray&strArray)
{
	int startIndex=0;
	int SplitLength=strlen(splitStr);
	strArray.RemoveAll();

	while(TRUE)
	{
		int retIndex=strToSplit.Find(splitStr,startIndex);
		if(retIndex<0)
		{
			CString strRet=strToSplit.Mid(startIndex);
			if(strRet.GetLength()>0) strArray.Add(strRet);
			break;
		}
		CString strRet=strToSplit.Mid(startIndex,retIndex-startIndex);
		if(strRet.GetLength()>0) strArray.Add(strRet);
		startIndex=retIndex+SplitLength;
		if(startIndex>strToSplit.GetLength()-1) break;
	}
}

//切割字符串,将strToSplit字符串用splitStr切割符切割后保
//存在strArray对象中返回,strArray中可以包含空字符串
void CDefineFunction::SplitStringWithNull(CString strToSplit, LPCTSTR splitStr,CStringArray&strArray)
{
	int startIndex=0;
	int SplitLength=strlen(splitStr);
	strArray.RemoveAll();

	while(TRUE)
	{
		int retIndex=strToSplit.Find(splitStr,startIndex);
		if(retIndex<0)
		{
			CString strRet=strToSplit.Mid(startIndex);
			if(strRet.GetLength()<1) strRet="";
			strArray.Add(strRet);
			break;
		}
		CString strRet=strToSplit.Mid(startIndex,retIndex-startIndex);
		if(strRet.GetLength()<1) strRet="";
		strArray.Add(strRet);
		startIndex=retIndex+SplitLength;
		if(startIndex>strToSplit.GetLength()-1)
		{
			strArray.Add(_T(""));
			break;
		}
	}
}

//////////将yyyy-mm-dd hh:mm:ss格式的字符串时间处理成数字时间,封装在CTime对象中返回
void CDefineFunction::getTimeFromString(CString strDateTime,CTime& retTime)
{
	CStringArray strArray;
	SplitString(strDateTime," ",strArray);
	if(strArray.GetSize()<1) return;
	CString strDate= strArray.GetAt(0);
	CString strTime="00:00:00";
	if(strArray.GetSize()>1) strTime=strArray.GetAt(1);
	CStringArray strArrayYYMMDD;
	SplitString(strDate,"-",strArrayYYMMDD);
	CString strYY="1900";CString strMM="01";CString strDD="01";
	if(strArrayYYMMDD.GetSize()>0) strYY=strArrayYYMMDD[0];
	if(strArrayYYMMDD.GetSize()>1) strMM=strArrayYYMMDD[1];
	if(strArrayYYMMDD.GetSize()>2) strDD=strArrayYYMMDD[2];
	int nYY=(int)strtol(strYY,NULL,10);
	int nMM=(int)strtol(strMM,NULL,10);
	int nDD=(int)strtol(strDD,NULL,10);

	CStringArray strArrayhhmmss;
	SplitString(strTime,":",strArrayhhmmss);
	CString strhh="00",strmm="00",strss="00";
	if(strArrayhhmmss.GetSize()>0) strhh=strArrayhhmmss[0];
	if(strArrayhhmmss.GetSize()>1) strmm=strArrayhhmmss[1];
	if(strArrayhhmmss.GetSize()>2) strss=strArrayhhmmss[2];
	int nhh=(int)strtol(strhh,NULL,10);
	int nmm=(int)strtol(strmm,NULL,10);
	int nss=(int)strtol(strss,NULL,10);
	
	CTime time(nYY,nMM,nDD,nhh,nmm,nss);
	retTime=time;
}

//计算整数base的count次幂
int CDefineFunction::powerint(int base,int count) 
{
	int result=1;
	for(int i=0;i<count;i++)
	{
		result *= base;
	}
	return result;
}

//获取语言的编码,通过字符串进行比对,返回语言1和语言2的值.
void CDefineFunction::getLangEncode(CString strLang,byte&btFirst,byte&btSecond)
{
	//American English
	if(strLang=="American English")
	{
		btFirst=0x32;btSecond=0x30;return;
	}
	if(strLang=="Japanese")
	{
		btFirst=0x32;btSecond=0x31;return;
	}
	if(strLang=="Latin American Spanish")
	{
		btFirst=0x32;btSecond=0x32;return;
	}
	if(strLang=="Greek")
	{
		btFirst=0x32;btSecond=0x33;return;
	}
	if(strLang=="Mandarin")
	{
		btFirst=0x32;btSecond=0x34;return;
	}
	if(strLang=="Reserved for future use")
	{
		btFirst=0x32;btSecond=0x35;return;
	}
	if(strLang=="UK English")
	{
		btFirst=0x32;btSecond=0x36;return;
	}
	if(strLang=="Canadian French")
	{
		btFirst=0x32;btSecond=0x37;return;
	}
	if(strLang=="Brazilian Portuguese")
	{
		btFirst=0x32;btSecond=0x38;return;
	}
	if(strLang=="German")
	{
		btFirst=0x32;btSecond=0x61;return;
	}
	if(strLang=="Parisian French")
	{
		btFirst=0x32;btSecond=0x62;return;
	}
	if(strLang=="Arabic Female")
	{
		btFirst=0x32;btSecond=0x64;return;
	}
	if(strLang=="Russian")
	{
		btFirst=0x32;btSecond=0x64;return;
	}
}

void CDefineFunction::getLangName(CString& strLang,byte btFirst,byte btSecond)
{
	if(btFirst==0x32 && btSecond==0x30)
	{
		strLang="American English";return;
	}
	if(btFirst==0x32 && btSecond==0x31)
	{
		strLang="Japanese";return;
	}
	if(btFirst==0x32 && btSecond==0x32)
	{
		strLang="Latin American Spanish";return;
	}
	if(btFirst==0x32 && btSecond==0x33)
	{
		strLang="Greek";return;
	}
	if(btFirst==0x32 && btSecond==0x34)
	{
		strLang="Mandarin";return;
	}
	if(btFirst==0x32 && btSecond==0x35)
	{
		strLang="Reserved for future use";return;
	}
	if(btFirst==0x32 && btSecond==0x36)
	{
		strLang="UK English";return;
	}
	if(btFirst==0x32 && btSecond==0x37)
	{
		strLang="Canadian French";return;
	}
	if(btFirst==0x32 && btSecond==0x38)
	{
		strLang="Brazilian Portuguese";return;
	}
	if(btFirst==0x32 && btSecond==0x61)
	{
		strLang="German";return;
	}
	if(btFirst==0x32 && btSecond==0x62)
	{
		strLang="Parisian French";return;
	}
	if(btFirst==0x32 && btSecond==0x64)
	{
		strLang="Arabic Female";return;
	}
	if(btFirst==0x32 && btSecond==0x64)
	{
		strLang="Russian";return;
	}
}

//得到当前应用程序所在的全路径名
CString CDefineFunction::getAppStartPath()
{
	HMODULE hModule=GetModuleHandle(NULL);
	char path[200];
	GetModuleFileName(hModule,path,sizeof(path));
	CString strPath(path);
	int index= strPath.ReverseFind('\\');
	strPath=strPath.Mid(0,index);
	return strPath;
}

⌨️ 快捷键说明

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