mfc 编写万年历 怎么编 我是码示白痴 求指导
我这里有现成的代码,可供你参考,码示主要是码示自绘的实现,附件给你两个版本的码示ue源码开放,均是码示MFC的(如下图)。第一个是码示摘自网上的程序,但经我改良,码示农历数据使用自创的码示算法,年份支持也大大增加(从公元年至年),码示并且修正了部分错误。码示
第二个是码示自创的,是码示MFC绘制出来的界面,支持两种视图。码示
代码都是在VS上编译通过的,如需要源代码,请追问。
//判断闰年,易语言支持库授权源码参数:年份,闰年,返回值:FALSE-失败,TRUE-成功static BOOL IsLeapYear(WORD dwYear,BOOL &bLeapYear);
//计算日期在年内的序数,参数:年,月,日,年内序数,返回值:FALSE-失败,芒格选股标准源码TRUE-成功
static BOOL GetDaysNumInYear(WORD dwYear, WORD dwMonth, WORD dwDay,WORD &nDays);
//从年内序数计算月、日,参数:年,年内序数,月,日,返回值:FALSE-失败,TRUE-成功
static BOOL GetDateFromDays(WORD dwYear, WORD nDays, WORD &dwMonth, WORD &dwDay);
//获取农历新年的公历年内序数,参数:农历年,为什么没有跨境溯源码返回值:农历新年的公历年内序数
static short LunarGetNewYearOrdinal(WORD dwLunarYear);
//获取农历月的天数,参数:农历年,农历月,是否为闰月,返回值:该农历月的天数,为0代表参数无效
static WORD LunarGetDaysofMonth(WORD dwLunarYear,WORD dwLunarMonth,BOOL bLeapMonth);
//获取农历某一年的闰月情况,参数:农历年,返回值,该年的商城app会卖源码吗闰月月份,0表示无闰月
static WORD LunarGetLeapMonth(WORD dwLunarYear);
//公历转农历,参数:公历年、月、日,农历年、月、日,是否为闰月,返回值:FALSE-失败,TRUE-成功
static BOOL GetLunar(WORD dwYear,WORD dwMonth,WORD dwDay,WORD &dwLunarYear,WORD &dwLunarMonth,WORD &dwLunarDay,BOOL &bLeapMonth);
//农历转公历,参数:家历年、月、日,是否为闰月,公历年、月、日,返回值:FALSE-失败,TRUE-成功
static BOOL GetGregorian(WORD dwLunarYear,WORD dwLunarMonth,WORD dwLunarDay,BOOL bLeapMonth,WORD &dwYear,WORD &dwMonth,WORD &dwDay);
//得到指定年份的节气信息,首个是小寒
static BOOL GetJieQi(WORD dwYear,WORD dwMonth,WORD dwJieQi[2]);
//计算星期,返回-1表示输入的年月日不正确或者超出年份范围
static short GetDayOfWeek(WORD dwYear,WORD dwMonth,WORD dwDay);
//计算某个月的天数,返回天数,如果返回0表示年或月有误
static WORD GetDaysOfMonth(WORD dwYear,WORD dwMonth);
//把iYear年格式化成天干记年法表示的字符串
static void FormatLunarYear(WORD iYear, char *pBuffer);
//把iMonth格式化成中文字符串
static void FormatLunarMonth(WORD iMonth, char *pBuffer, BOOL bLeapMonth=FALSE);
//把iDay格式化成中文字符串
static void FormatLunarDay(WORD iDay, char *pBuffer);
请问大家谁会用MFC编万年历?会的话麻烦把源代码发上来,谢了!
#include
#include
struct mon
{
int maxdata;
int data;
};
void SeekWeekDay(void); //求某个日期对应的星期函数
int WeekDay(int year, int month, int day); //根据输入的日期,返回对应的星期
void HowManyDays(void);//求某年某月有的天数函数
int MonthDays(int year, int month);//根据输入的年号和月份,返回该月的天数
void PrintWeek(int weekday, FILE *fp);//打印星期几
void PrintMonth(int month, FILE *fp); //打印月份
void PrintData(); //打印日历
int main(void)
{
int choice;
while(1)
{
puts("------------------------------------------");
puts("请输入您的选择:");
puts("输入1求某个日期对应的星期");
puts("输入2求某年某月有的天数");
puts("输入3输出某年的日历");
puts("输入4结束程序");
puts("------------------------------------------");
scanf("%d", &choice); fflush(stdin);
switch(choice)
{
case 1: SeekWeekDay(); break;
case 2: HowManyDays(); break;
case 3: PrintData(); break;
case 4: return 0;
default: puts("输入错误,请重新输入"); break;
}
printf("\n"); printf("\n");
}
system("pause");
return 0;
}
void HowManyDays(void) //求某年某月有的天数函数
{
int year, month, days;
puts("请输入年号和月份:");
scanf("%d%d", &year, &month); fflush(stdin);
printf("你的输入为 %d年%d月,", year, month);
days = MonthDays(year, month); //根据输入的年号和月份,返回该月的天数
printf(" %d年%d月有%d天\n", year, month, days);
}
void SeekWeekDay(void) //求某个日期对应的星期函数
{
FILE *fp;
int year, month, day, weekday;
if ( (fp="fopen"("wnlweek.txt","w+")) == NULL)
{
fprintf(stderr,"\nError opening file\n");
exit(1);
}
puts("请输入年,月, 日:");
scanf("%d%d%d", &year, &month, &day); fflush(stdin);
printf("你的输入为 %d年%d月%d日\n", year, month, day);
weekday = WeekDay(year, month, day); //根据输入的日期,返回对应的星期
printf("这天是 ");
PrintWeek(weekday, fp); //打印星期几
}
void PrintWeek(int weekday, FILE *fp)//打印星期几
{
switch(weekday)
{
case 0 : fprintf(stdout, "%s","周日 "); fprintf(fp, "%s","周日 "); break;
case 1 : fprintf(stdout, "%s","周一 "); fprintf(fp, "%s","周一 ");break;
case 2 : fprintf(stdout, "%s","周二 "); fprintf(fp, "%s","周二 ");break;
case 3 : fprintf(stdout, "%s","周三 "); fprintf(fp, "%s","周三 ");break;
case 4 : fprintf(stdout, "%s","周四 "); fprintf(fp, "%s","周四 "); break;
case 5 : fprintf(stdout, "%s","周五 "); fprintf(fp, "%s","周五 ");break;
case 6 : fprintf(stdout, "%s","周六 "); fprintf(fp, "%s","周六 ");break;
}
}
void PrintMonth(int month, FILE *fp) //打印月份
{
switch(month)
{
case 1 : fprintf(stdout, "%s","一 月 "); fprintf(fp, "%s","一 月 ");break;
case 2 : fprintf(stdout, "%s","二 月 "); fprintf(fp, "%s","二 月 ");break;
case 3 : fprintf(stdout, "%s","三 月 "); fprintf(fp, "%s","三 月 ");break;
case 4 : fprintf(stdout, "%s","四 月 "); fprintf(fp, "%s","四 月 ");break;
case 5 : fprintf(stdout, "%s","五 月 "); fprintf(fp, "%s","五 月 ");break;
case 6 : fprintf(stdout, "%s","六 月 "); fprintf(fp, "%s","六 月 ");break;
case 7 : fprintf(stdout, "%s","七 月 "); fprintf(fp, "%s","七 月 ");break;
case 8 : fprintf(stdout, "%s","八 月 "); fprintf(fp, "%s","八 月 ");break;
case 9 : fprintf(stdout, "%s","九 月 "); fprintf(fp, "%s","九 月 ");break;
case : fprintf(stdout, "%s","十 月 "); fprintf(fp, "%s","十 月 ");break;
case : fprintf(stdout, "%s","十一 月 "); fprintf(fp, "%s","十一 月 "); break;
case : fprintf(stdout, "%s","十二 月 "); fprintf(fp, "%s","十二 月 "); break;
}
}
int WeekDay(int year, int month, int day) //根据输入的日期,返回对应的星期
{
int i;
int run="0", ping="0";
long sum;
for(i="1"; i {
if(i%4==0 && i%!=0 || i%==0)
run++;
else
ping++;
}
sum = *run + *ping;
for(i="1"; i sum += MonthDays(year, i);
sum += day; //计算总天数
return (int)sum%7;
}
int MonthDays(int year, int month)//根据输入的年号和月份,返回该月的天数
{
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case :
case : return ;
case 4:
case 6:
case 9:
case : return ;
case 2: if(year%4==0 && year%!=0 || year%==0)
return ;
else
return ;
default: puts("这是一个错误的月份!"); system("pause"); return 0;
}
}
void PrintData(void)//打印日历,对输出格式的控制较复杂
{
FILE *fp;
struct mon month[];
int i, j, k;
int year, mon, week;
if ( (fp="fopen"("wnldata.txt","w+")) == NULL)
{
fprintf(stderr,"\nError opening file\n");
exit(1);
}
puts("请输入年号:");
scanf("%d", &year);
fprintf(stdout, "--------------------------------------------------------------------------\n");
fprintf(fp, "--------------------------------------------------------------------------\n");
fprintf(stdout, "%d %s\n", year, "年"); fprintf(fp, "%d %s\n", year,"年");
fprintf(stdout, "--------------------------------------------------------------------------\n");
fprintf(fp, "--------------------------------------------------------------------------\n");
for(i="1"; i<; i++) //存储该年每个月的总天数和初始日期
{
month[i].data = 1;
month[i].maxdata = MonthDays(year, i);
}
for(i="0"; i<6; i++) //总共输出6排
{
for(j="1"; j<=2; j++)//每排输出2个月
{
mon = 2*i + j;
fprintf(stdout, "%s", " "); fprintf(fp, "%s", " ");
PrintMonth(mon, fp); //第一行打印月份
fprintf(stdout, "%s", " "); fprintf(fp, "%s", " ");
if(j==1)
{ fprintf(stdout, "\t"); fprintf(fp, "\t"); }
}
fprintf(stdout, "\n"); fprintf(stdout, "\n"); fprintf(fp, "\n"); fprintf(fp, "\n");
for(j="1"; j<=2; j++)
{
for(k="0"; k<7; k++)
{
PrintWeek(k, fp); //第2行打印星期
}
fprintf(stdout, "\t"); fprintf(fp, "\t");
}
printf("\n"); fprintf(fp, "\n");
for(j="1"; j<=2; j++)
{
mon = 2*i + j;
week = WeekDay(year, mon, 1); //根据输入的日期,返回对应的星期
//控制输出格式,把每月的1日打印在对应星期的下面
fprintf(stdout, "%*d ", week*5+2, month[mon].data); fprintf(fp, "%*d ", week*5+2, month[mon].data);
month[mon].data++;
week++;
while(week < 7) //接着在该行打印该周剩余的日期
{
fprintf(stdout, "%2d ", month[mon].data++); fprintf(fp, "%2d ", month[mon].data++);
week++;
}
if(j==1)
{ fprintf(stdout, "\t"); fprintf(fp, "\t"); }
}
fprintf(stdout, "\n"); fprintf(stdout, "\n"); fprintf(fp, "\n"); fprintf(fp, "\n");
//从第4行起打印该月剩余的日期,每7个一行;直至该月日期打印完毕
while(month[2*i+1].data<=month[2*i+1].maxdata || month[2*i+2].data<=month[2*i+2].maxdata)
{
for(j="1"; j<=2; j++)
{
mon = 2*i + j;
for(k="0"; k<7; k++)
{
if(month[mon].data<=month[mon].maxdata)
{ //如果该月日期未打印完,打印该日期
fprintf(stdout, "%2d ", month[mon].data);
fprintf(fp, "%2d ", month[mon].data);
month[mon].data++;
}
else //否则输出空格
{ fprintf(stdout, " "); fprintf(fp," "); }
}
if(j==1)
{ fprintf(stdout, "\t"); fprintf(fp, "\t"); }
}
fprintf(stdout, "\n"); fprintf(stdout, "\n"); fprintf(fp, "\n"); fprintf(fp, "\n");
}
fprintf(stdout, "\n"); fprintf(fp, "\n");
}
fclose(fp);
}
2024-12-24 08:25
2024-12-24 08:01
2024-12-24 07:58
2024-12-24 06:52
2024-12-24 06:17