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

📄 public.cpp

📁 嵌入式DOS系统上位升级程序FileUpgrade, 需配合本人上传的FileUpr程序应用, VC++开发, 非常实用, 内附说明及源码
💻 CPP
字号:
#include "stdafx.h"
#include "public.h"

const int MonthDays4Year[48+1]={
	0,
	31,  60,  91, 121, 152, 182, 213, 244, 274, 305, 335, 366, 
	397, 425, 456, 486, 517, 547, 578, 609, 639, 670, 700, 731, 
	762, 790, 821, 851, 882, 912, 943, 974,1004,1035,1065,1096,
	1127,1155,1186,1216,1247,1277,1308,1339,1369,1400,1430,1461
};
//转换从2000年1月1日开始的天数为日期值:年、月、日
static void GDate(unsigned long int Days,unsigned short int &wYear,unsigned short  int &wMonth,  unsigned short int &wDay)
{
	short int n4Years=(short int )(Days/1461);//从2000年开始的多少4年
	short int  n4Day=(short int )(Days%1461);  
	int k=0;
	while(n4Day>=MonthDays4Year[k+1]) k++;
	wYear=n4Years*4+2000+k/12;
	wMonth=k%12+1;
	wDay=n4Day-MonthDays4Year[k]+1;
}
//把日期值:年、月、日转换为2000年1月1日开始的天数
static unsigned long GDays(short int wYear,short int wMonth,short int wDay)
{
	wYear-=2000;
	unsigned long nDate = wYear*365L + (wYear+3)/4 +MonthDays4Year[wMonth-1] + wDay-1;
	if ((wMonth >2) && ((wYear & 3)!=0)) --nDate;//如果是3月以后,还是闰年
	return nDate;
}

SYSTEMTIME GetSYSTEMTIMEDate(unsigned long int longtime)
{
	SYSTEMTIME RValue;
	RValue.wSecond=(unsigned char)(longtime%60);
	longtime/=60;
	RValue.wMinute=(unsigned char)(longtime%60);longtime/=60;
	RValue.wHour=(unsigned char)(longtime%24);longtime/=24;
	GDate(longtime,RValue.wYear,RValue.wMonth,RValue.wDay);
	return RValue;
}
unsigned long int GetDefineTime(int y,int mon,int d,int h,int m,int s)
{
	unsigned long int RVlaue=0;
	long nDate = GDays(y,mon,d);
	RVlaue=nDate*24L*60*60+h*60L*60+m*60L+s;
	return RVlaue;
};

unsigned long int GetSystemDefineTime()
{
	SYSTEMTIME RValue;
	GetLocalTime(&RValue);
	return GetDefineTime(RValue.wYear,RValue.wMonth,RValue.wDay,RValue.wHour,RValue.wMinute,RValue.wSecond);
}

char *GetDateString(SYSTEMTIME RValue)
{
	static char buf[20];
	sprintf(buf,"%04d.%02d.%02d %02d:%02d:%02d",
		RValue.wYear,
		RValue.wMonth,
		RValue.wDay,
		RValue.wHour,
		RValue.wMinute,
		RValue.wSecond);
	return buf;
}
char *GetDateString(unsigned long int longtime)
{
	return GetDateString(GetSYSTEMTIMEDate(longtime));
}



BOOL isdigit(TCHAR ch)
{
	return (ch>='0')&&(ch<='9');
}

BOOL isHexdigit(char ch)
{
	if((ch>='0')&&(ch<='9')) return 1;
	if((ch>='A')&&(ch<='F')) return 1;
	if((ch>='a')&&(ch<='f')) return 1;
	return 0;
}

unsigned long int HexStrToInt(TCHAR str[])
{
	unsigned long int value=0,k;
	TCHAR ch;
	for(k=0;isHexdigit(str[k]);k++)
	{
		value*=16;
		ch=str[k];
		if((ch>='0')&&(ch<='9')) value+=str[k]-'0';
		else if((ch>='A')&&(ch<='F')) value+=str[k]-'A'+10;
		else if((ch>='a')&&(ch<='f')) value+=str[k]-'a'+10;
	}
	return value;
}
unsigned long int StrToInt(TCHAR str[])
{
	unsigned long int value=0,k;
	for(k=0;isdigit(str[k]);k++)
	{
		value*=10;
		value+=str[k]-'0';
	}
	return value;
}
double StrToFloat(TCHAR str[])
{
	double value=0,r;
	int k;
	for(k=0;isdigit(str[k]);k++)
	{
		value*=10;
		value+=str[k]-'0';
	}	
	if(str[k]!='.')  return value;

	for(k++,r=0.1;isdigit(str[k]);k++)
	{
		value+=(str[k]-'0')*r;
		r/=10;
	}
	return value;
}

⌨️ 快捷键说明

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