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

📄 commfun.cpp

📁 GPS定位报警程序
💻 CPP
字号:
// CommFun.cpp: implementation of the CCommFun class.
//
//////////////////////////////////////////////////////////////////////
//公共函数类
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "CommFun.h"
#include <math.h>

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

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

CCommFun::CCommFun()
{

}

CCommFun::~CCommFun()
{

}
CString CCommFun::GetAppPath()
{	//返回当前目录
	char Buffer[250];
	CString strPath;
	GetModuleFileName(NULL,Buffer,250);
	strPath=CString(Buffer);
	strPath=strPath.Left(strPath.ReverseFind('\\'));
	return strPath;
}
//得到EXE路径
CString CCommFun::GetAppFilename()
{
	char Buffer[250];
	CString strPath;
	GetModuleFileName(NULL,Buffer,250);
	strPath=CString(Buffer);
	return strPath;
}

CString CCommFun::GetAppPath(CString FileName)
{	//返回当前目录指定文件的全路经
	if(!FileName!=NULL)
		return FileName;
	CString strPath;
	strPath=GetAppPath();
	if(strPath.Right(1)=="\\")
		strPath+=FileName;
	else
		strPath+="\\"+FileName;
	return strPath;
}

CString CCommFun::Getini(CString AppName, CString KeyName, CString Defaule, CString FileName)
{	//读取INI文件的值
	char chr[254]={"\0"};
	GetPrivateProfileString(AppName,KeyName,Defaule,chr,254,FileName);
	return CString(chr);
}

int CCommFun::Getini(CString AppName, CString KeyName, int Default, CString FileName)
{	//读取ini文件的值(数字)
	CString strTmp;
	int intTmp;
	strTmp.Format("%d",Default);
	strTmp=Getini(AppName,KeyName,strTmp,FileName);
	intTmp=atoi(strTmp);
	return intTmp;
}

BOOL CCommFun::Writeini(CString AppName, CString KeyName, CString Value, CString FileName)
{	//写入ini文件
	return WritePrivateProfileString(AppName,KeyName,Value,FileName);
}

BOOL CCommFun::Writeini(CString AppName, CString KeyName, int Value, CString FileName)
{	//写入ini文件
	CString sValue;
	sValue.Format("%d",Value);
	return WritePrivateProfileString(AppName,KeyName,sValue,FileName);
}
SYSTEMTIME CCommFun::GetSysTime()
{	//得到系统时间
	SYSTEMTIME systime;
	GetLocalTime(&systime);
	return systime;
}
CString CCommFun::GetSysTimeString()
{	//得到字符串时间
	CString strHH;
	CString strMI;
	CString strSS;
	CString strReturn;
	SYSTEMTIME systime=GetSysTime();
	strHH.Format("0%d",systime.wHour);
	strHH=strHH.Right(2);
	strMI.Format("0%d",systime.wMinute);
	strMI=strMI.Right(2);
	strSS.Format("0%d",systime.wSecond);
	strSS=strSS.Right(2);
	strReturn.Format("%s:%s:%s",strHH,strMI,strSS);
	return strReturn;
}

CString CCommFun::GetSysDateString()
{	//得到字符串日期
	CString strYYYY;
	CString strMM;
	CString strDD;
	CString strReturn;
	SYSTEMTIME systime=GetSysTime();
	strYYYY.Format("%d",systime.wYear);
	strMM.Format("0%d",systime.wMonth);
	strMM=strMM.Right(2);
	strDD.Format("0%d",systime.wDay);
	strDD=strDD.Right(2);
	strReturn.Format("%s-%s-%s",strYYYY,strMM,strDD);
	return strReturn;
}

CString CCommFun::GetSysDateTimeString()
{	//得到字符串日期时间
	CString strReturn;
	strReturn.Format("%s %s",GetSysDateString(),GetSysTimeString());
	return strReturn;
}
//检索出命令行
CString CCommFun::GetCmdLine()
{
	CString strCmdLine;
	strCmdLine=GetCommandLine();
	int i=strCmdLine.ReverseFind(' ');
	if(i==-1)
		return "";
	else
		return strCmdLine.Mid(i+1);
}

CString CCommFun::GetSysDateString(CTime ctime)
{	//得到字符串日期
	CString strYYYY;
	CString strMM;
	CString strDD;
	CString strReturn;

	strYYYY.Format("%d",ctime.GetYear());
	strMM.Format("0%d",ctime.GetMonth());
	strMM=strMM.Right(2);
	strDD.Format("0%d",ctime.GetDay());
	strDD=strDD.Right(2);
	strReturn.Format("%s-%s-%s",strYYYY,strMM,strDD);
	return strReturn;
}

//返回当前时间经过的毫秒数
long CCommFun::GetSyslongTime()
{
	SYSTEMTIME systime;
	long lngS;
	GetSystemTime(&systime);
	lngS=systime.wHour*3600+systime.wMinute*60+systime.wSecond;
	//lngS*=1000;
	//lngS+=systime.wMilliseconds;
	return lngS;
}
//16进制转10进制
int CCommFun::strHexToInt(CString strHex)
{
	int nTemp=0;
	CString strTemp;
	strTemp=strHex;
	for(char cc='G',dd='g';   cc<='Z',dd<='z';  cc++,dd++)    //判断输入的字符串是否合法
	{
		if(strTemp.Find(cc,0) !=-1  ||  strTemp.Find(dd,0) !=-1)
		{
			return -1;
		}
	}
	for(int i = 0;  i<strTemp.GetLength();  i++)
	{
		int nDecNum;
		switch(strTemp.GetAt(i))
		{
			case 'a':
			case 'A': nDecNum = 10; break;
			case 'b':
			case 'B': nDecNum = 11; break;
			case 'c':
			case 'C': nDecNum = 12;   break;
			case 'd':
			case 'D': nDecNum = 13;   break;
			case 'e':
			case 'E': nDecNum = 14;   break;
			case 'f':
			case 'F': nDecNum = 15;   break;
			case '0':
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':
			case '9': nDecNum = strTemp.GetAt(i) - '0';     break;
			default:  return 0;   
        }
		nTemp += nDecNum * (int)pow(16,strTemp.GetLength()-i-1);
	}
	return nTemp;
}
////判断是否为数字
BOOL CCommFun::IsNumber(CString sNum)
{
	for(int i=0;i<sNum.GetLength();i++)
		if(!_istdigit(sNum.GetAt(i)))
			return FALSE;
	return TRUE;
}

⌨️ 快捷键说明

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