万年历c语言源程序
更新时间:2023-05-23 11:45:01 阅读量: 实用文档 文档下载
#include <stdio.h> #include <windows.h> #include <wincon.h> #include<string.h> #include<stdlib.h> #include<conio.h> #include<time.h> #include<math.h> #define NULL 0
CONSOLE_SCREEN_BUFFER_INFO csbiInfo; extern WINBASEAPI HWND WINAPI GetConsoleWindow(); time_t T;
struct tm * now; int min,sec;
int hour,nowyear,nowmonth,nowday; void ti2() { time ( &T ); now = localtime ( &T ); hour=now->tm_hour%12; min=now->tm_min-15; sec=now->tm_sec-15; }
void ti(){ time ( &T ); now = localtime ( &T ); hour=now->tm_hour; min=now->tm_min; sec=now->tm_sec; nowyear=now->tm_year+1900; nowmonth=now->tm_mon+1; nowday=now->tm_mday; }
int yearbak=0; void clock_sz(); int pd( int year);
void huizs(int line_head_month); void hzdy(int year,int nowmonth_hz); void menu(); void clear();
int main(int argc, char* argv[]) { int x=0; ti();
clock_sz(); hzdy(nowyear,nowmonth); menu(); return 0; }
void clear() { int i; HWND hwnd; HANDLE hOut; HDC hdc; HBRUSH hbr; COORD pos={1,4}; hwnd=GetConsoleWindow(); hdc = GetDC(hwnd); hOut = GetStdHandle(STD_OUTPUT_HANDLE); hbr= CreateSolidBrush(RGB(0,0,0)); SelectObject(hdc,hbr); Rectangle(hdc,0,65,670,470); SetConsoleCursorPosition(hOut, pos); for(i=0;i<10;i++) printf(" \n "); SetConsoleCursorPosition(hOut, pos); Rectangle(hdc,0,65,670,470); ReleaseDC(hwnd, hdc); }
void menu() { int year=0,xyear=0,x, xy=0,i ; struct re { int top; int left; int right; int bottom; }rt[13]; HWND hwnd; HDC hdc,dc; HBRUSH hbr; COORD pos3_1 = {1, 4},pos3_2= {1, 1},pos = {1, 4},pos2_3 = {1, 6},pos2_4 = {1, 7}; INPUT_RECORD mouseRec; DWORD state = 0, res=0; POINT pt; HPEN pn;
HANDLE hOut, hIn;
hwnd=GetConsoleWindow();//得到控制台窗口句柄 hdc = GetDC(hwnd); //得到画图设备句柄 dc = GetDC(hwnd);//画刷
hbr= CreateSolidBrush(RGB(255,0,0)); SelectObject(dc,hbr);
for(rt[1].left=20,i=2;i<=12;i++) rt[i].left=rt[i-1].left+50;
for(rt[1].right=50,i=2;i<=12;i++) rt[i].right=rt[i-1].right+50; //定位按钮 for(i=0;i<=12;i++) rt[i].top=40; for(i=0;i<=12;i++) rt[i].bottom=60;
hOut = GetStdHandle(STD_OUTPUT_HANDLE); hIn=GetStdHandle(STD_INPUT_HANDLE); pn=CreatePen(PS_SOLID,1,RGB(255,0,255)); GetClientRect(hwnd, &rt); SelectObject(hdc, pn);
SetBkMode(hdc,TRANSPARENT); MoveToEx(hdc,1,35,NULL); LineTo(hdc,620,35); LineTo(hdc,620,62); LineTo(hdc,1,62); LineTo(hdc,1,35);
pn=CreatePen(PS_SOLID,2,RGB(255,255,0)); SelectObject(hdc, pn);
MoveToEx(hdc,5,75,NULL); LineTo(hdc,45,75);
hbr= CreateSolidBrush(RGB(0,0,190)); SelectObject(dc,hbr); for(i=1;i<=12;i++) Rectangle(dc,rt[i].left,rt[i].top,rt[i].right,rt[i].bottom);
SetTextColor(hdc,RGB(0,255,255));
TextOut(hdc,280,10,TEXT("万年历"),6);//输出文本
SetTextColor(hdc,RGB(255,255,0));////设颜色
TextOut(hdc,rt[1].left,rt[1].top,TEXT(" 1"),3);//输出文本
TextOut(hdc,rt[1].left+=50,rt[1].top,TEXT(" 2"),3);//输出文本 TextOut(hdc,rt[1].left+=50,rt[1].top,TEXT(" 3"),3);//输出文本 TextOut(hdc,rt[1].left+=50,rt[1].top,TEXT(" 4"),3);//输出文本 TextOut(hdc,rt[1].left+=50,rt[1].top,TEXT(" 5"),3);//输出文本 TextOut(hdc,rt[1].left+=50,rt[1].top,TEXT(" 6"),3);//输出文本 TextOut(hdc,rt[1].left+=50,rt[1].top,TEXT(" 7"),3);//输出文本 TextOut(hdc,rt[1].left+=50,rt[1].top,TEXT(" 8"),3);//输出文本
TextOut(hdc,rt[1].left+=50,rt[1].top,TEXT(" 9"),3);//输出文本 TextOut(hdc,rt[1].left+=50,rt[1].top,TEXT(" 0"),3);//输出文本 TextOut(hdc,rt[1].left+=50,rt[1].top,TEXT("确定"),4);//输出文本 TextOut(hdc,rt[1].left+=50,rt[1].top,TEXT("清除"),4);//输出文本 TextOut(hdc,40,350,TEXT("提示:双击窗口退出"),18);//输出文本 SetConsoleCursorPosition(hOut, pos3_1); ShowWindow(hwnd,SW_SHOW); SetConsoleTextAttribute(hOut, 10); for(;;) { SetConsoleTextAttribute(hOut, 10); ReadConsoleInput(hIn, &mouseRec, 1, &res); Sleep(100); if (mouseRec.EventType == MOUSE_EVENT) { if (mouseRec.Event.MouseEvent.dwEventFlags == DOUBLE_CLICK) break; if (mouseRec.Event.MouseEvent.dwButtonState == FROM_LEFT_1ST_BUTTON_PRESSED) { GetCursorPos(&pt); ScreenToClient(hwnd,&pt); if(pt.x>20&& pt.x<50 &&pt.y>rt[1].top && pt.y<rt[1].bottom) { if(xyear<4) printf("1"); xyear++; if(xyear==1) year=1*1000; if(xyear==2) year=year+1*100; if(xyear==3) year=year+1*10; if(xyear==4) { year=year+1; printf("\n你选择的年为%d",year); } continue; } else if(pt.x>rt[2].left && pt.x<rt[2].right &&pt.y>rt[2].top && pt.y<rt[2].bottom) { if(xyear<4) printf("2"); xyear++; if(xyear==1) year=2*1000; if(xyear==2) year=year+2*100;
if(xyear==3) year=year+2*10; if(xyear==4){ year=year+2; printf("\n你选择的年为%d",year); } continue; } else if(pt.x>rt[3].left && pt.x<rt[3].right pt.y<rt[3].bottom) { if(xyear<4) printf("3"); xyear++; if(xyear==1) year=3*1000; if(xyear==2) year=year+3*100; if(xyear==3) year=year+3*10; if(xyear==4){ year=year+3; printf("\n你选择的年为%d",year); } continue; } else if(pt.x>rt[4].left && pt.x<rt[4].right pt.y<rt[4].bottom){ if(xyear<4) printf("4"); xyear++; if(xyear==1) year=4*1000; if(xyear==2) year=year+4*100; if(xyear==3) year=year+4*10; if(xyear==4){ year=year+4; printf("\n你选择的年为%d",year); } continue; } else if(pt.x>rt[5].left && pt.x<rt[5].right pt.y<rt[5].bottom){ if(xyear<4) printf("5"); xyear++; if(xyear==1) year=5*1000; if(xyear==2) year=year+5*100; if(xyear==3) year=year+5*10; if(xyear==4){ year=year+5;
&&pt.y>rt[3].top &&pt.y>rt[4].top &&pt.y>rt[5].top &&
&&
&&
printf("\n你选择的年为%d",year); } continue; } else if(pt.x>rt[6].left && pt.x<rt[6].right pt.y<rt[6].bottom){ if(xyear<4) printf("6"); xyear++; if(xyear==1) year=6*1000; if(xyear==2) year=year+6*100; if(xyear==3) year=year+6*10; if(xyear==4){ year=year+6; printf("\n你选择的年为%d",year); } continue; } else if(pt.x>rt[7].left && pt.x<rt[7].right pt.y<rt[7].bottom){ if(xyear<4) printf("7"); xyear++; if(xyear==1) year=7*1000; if(xyear==2) year=year+7*100; if(xyear==3) year=year+7*10; if(xyear==4){ year=year+7; printf("\n你选择的年为%d",year); } continue; } else if(pt.x>rt[8].left && pt.x<rt[8].right pt.y<rt[8].bottom){ if(xyear<4) printf("8"); xyear++; if(xyear==1) year=8*1000; if(xyear==2) year=year+8*100; if(xyear==3) year=year+8*10; if(xyear==4){ year=year+8; printf("\n你选择的年为%d",year);
&&pt.y>rt[6].top &&pt.y>rt[7].top &&pt.y>rt[8].top &&
&&
&&
} continue; } else if(pt.x>rt[9].left && pt.x<rt[9].right pt.y<rt[9].bottom){ if(xyear<4) printf("9"); xyear++; if(xyear==1) year=9*1000; if(xyear==2) year=year+9*100; if(xyear==3) year=year+9*10; if(xyear==4){ year=year+9; printf("\n你选择的年为%d",year); } continue; } else if(pt.x>rt[10].left && pt.x<rt[10].right pt.y<rt[10].bottom){ if(xyear<4) printf("0"); xyear++; if(xyear==1) year=0*1000; if(xyear==2) year=year+0*100; if(xyear==3) year=year+0*10; if(xyear==4){ year=year+0; printf("\n你选择的年为%d",year); } continue; } else if(pt.x>rt[11].left && pt.x<rt[11].right pt.y<rt[10].bottom){ if(xyear>=1&&year!=0) { clear(); yearbak=year; SetConsoleCursorPosition(hOut, pos3_2); printf("公元%d年",yearbak); SetConsoleCursorPosition(hOut, pos3_1); for(i=1;i<=6;i+=3) huizs(i);
&&pt.y>rt[9].top &&pt.y>rt[10].top &&pt.y>rt[11].top && && &&
x=MessageBox(NULL,"是否显示后六个月?", "提示",MB_YESNO); if(x==6) { SetConsoleTextAttribute(hOut, 14); clear(); for(i=7;i<=12;i+=3) huizs(i); } } else printf("输入不合法,请点击清除 重新输入"); continue; } else if(pt.x>rt[12].left && pt.x<rt[12].right &&pt.y>rt[12].top pt.y<rt[12].bottom){ xyear=0; year=0; clear(); clock_sz(); hzdy(nowyear,nowmonth); pn=CreatePen(PS_SOLID,2,RGB(255,255,0)); SelectObject(hdc, pn);//选画笔 MoveToEx(hdc,5,75,NULL); LineTo(hdc,45,75); SetConsoleCursorPosition(hOut, pos); continue; } }; } } ReleaseDC(hwnd,hdc); }
int pd( int year) { int pr=0; if((year%100==0)&&(year%400==0)) pr=1; else if(year%4==0&&year%100!=0) pr=1; else pr=0; return pr; }
void huizs(int line_head_month) { int i=0,j=0,k=0,month=0,n=0,daysum=0,jlw=0;
&&
int monthhead[13]={0},mlt[3]={1,1,1}; int endline=0,test=0; int year=0; year=yearbak; for(i=1;i<year;i++) { if(pd(i)) daysum+=366; else daysum+=365; } j=daysum%7; monthhead[0]=j; for(month=1;month<=12;month++) { if(pd(year)&&month==2) n=29; else if(pd(year)==0&&month==2) n=28; else if(month==4||month==6||month==9||month==11) n=30; else n=31; monthhead[month]=(monthhead[month-1]+n)%7; } while(test<=5) { for(month=line_head_month;month<=(line_head_month+2);month++) { if(month%3==1&&endline==0) { printf("\t%d月\t\t\t%d月 \n",month,month+1,month+2); printf("一 二 三 四 五 六 日 一 二 三 四 五 六 日三 四 五 六 日\n"); } if(endline==0) { for(k=0;k<monthhead[month-1];k++) printf(" "); j=monthhead[month-1]; } if(endline==0) i=1; else i=mlt[month-1]; for(;j<7;i++,j++) { if(pd(year)&&month==2) n=29; else if(pd(year)==0&&month==2) n=28;
%d月 一 二
else if(month==4||month==6||month==9||month==11) n=30; else n=31; if(i>n) { for(k=0;k<7-j;k++) printf(" "); break; } printf("%-3.0d",i); } printf(" "); mlt[month-1]=i; if(month%3==0) { printf("\n"); endline=1; } j=0; } test++; } }
void hzdy(int year,int nowmonth_hz) { int i=0,j=0,k=0,month=0,n=0,daysum=0,jlw=0; int monthhead[13]={0},mlt[3]={1,1,1}; int endline=0,test=0; for(i=1;i<year;i++) { if(pd(i)) daysum+=366; else daysum+=365; } j=daysum%7; monthhead[0]=j; for(month=1;month<=12;month++) { if(pd(year)&&month==2) n=29; else if(pd(year)==0&&month==2) n=28;//平年 else if(month==4||month==6||month==9||month==11) n=30; else n=31; monthhead[month]=(monthhead[month-1]+n)%7; }
if(pd(year)&&nowmonth_hz==2) n=29;//闰年 else if(pd(year)==0&&nowmonth_hz==2) n=28;//平年 else if(nowmonth_hz==4||nowmonth_hz==6||nowmonth_hz==9||nowmonth_hz==11) n=30;//4,6,9,11月 else n=31; printf("\n\n\n\n\n\n\n\n 当前时间:%d年%d月%d日%d时%d分\n\n",nowyear,nowmonth,nowday,hour,min); printf("\t一 二 三 四 五 六 日\n\t"); for(k=0;k<monthhead[nowmonth_hz-1];k++) printf(" "); j=monthhead[nowmonth_hz-1]; for(i=1;i<=n;i++,j++) { if(j==7) { printf("\n\t"); j=0; } printf("%-3.0d",i); } printf("\n"); }
void clock_sz() { float a,b,c; float x=0,y=0,ex=100,ey=160,radian=0,oldx,oldy,radius=90; float mx=0,my=0,oldmx,oldmy,mradius=40; float hx=0,hy=0,oldhx,oldhy,hradius=20; int
kd_r1,kd_r2,kd_radius=170,kd_radius1,old_kd_x,old_kd_y,kd_radian=0,k=0,q=0,oldk,oldq; HWND hwnd; HANDLE hOut; HDC hdc; COLORREF C1=RGB(0,0,0),C2=RGB(0,0,0); HBRUSH hbr,hbr1,hbr2; HPEN hpn,gpn,rpn,ppn2,ypn,bpn,kdpn,rkdpn,dotpn,blue,black,blkdpn,pkdpn,hpn2; hwnd=GetConsoleWindow(); hdc = GetDC(hwnd); hOut = GetStdHandle(STD_OUTPUT_HANDLE); hbr= CreateSolidBrush(RGB(0,100,0)); hbr1= CreateSolidBrush(C1); hbr2= CreateSolidBrush(RGB(0,0,150)); hpn2=CreatePen(PS_SOLID,1,RGB(255,0,0)); rpn=CreatePen(PS_SOLID,1,RGB(255,0,0));
hpn=CreatePen(PS_SOLID,1,RGB(0,255,255)); blue=CreatePen(PS_SOLID,3,RGB(0,0,255)); bpn=CreatePen(PS_SOLID,1,RGB(255,255,255)); gpn=CreatePen(PS_SOLID,2,RGB(0,255,0)); pkdpn=CreatePen(PS_SOLID,3,RGB(0,255,255)); kdpn=CreatePen(PS_SOLID,1,RGB(255,255,0)); rkdpn=CreatePen(PS_SOLID,4,RGB(255,0,0)); blkdpn=CreatePen(PS_SOLID,6,RGB(0,0,0)); black=CreatePen(PS_SOLID,4,C1); ex=400;//时钟圆心位置 ey=230;
while(kd_radian<=360){ if(kd_radian%5==0) { if(kd_radian%90==0){ kd_radius=130; SelectObject(hdc,rkdpn); } else{ kd_radius=125; SelectObject(hdc,pkdpn); } } else { kd_radius=130; SelectObject(hdc, kdpn); kd_radius1=120; } y=kd_radius*sin(kd_radian/180.0*3.14); x=kd_radius*cos(kd_radian/180.0*3.14); MoveToEx(hdc,ex,ey,NULL); LineTo(hdc,ex+x,ey+y); y=kd_radius1*sin(kd_radian/180.0*3.14); x=kd_radius1*cos(kd_radian/180.0*3.14); old_kd_x=x; old_kd_y=y; SelectObject(hdc,blkdpn); MoveToEx(hdc,ex,ey,NULL); LineTo(hdc,ex+old_kd_x,ey+old_kd_y); kd_radian+=6; };
SetTextColor(hdc,RGB(0,255,0));
}
TextOut(hdc,ex+kd_radius+8,ey-7,TEXT("3"),1); TextOut(hdc,ex-4,ey+kd_radius+3,TEXT("6"),1); TextOut(hdc,ex-kd_radius-15,ey-5,TEXT("9"),1); TextOut(hdc,ex-7,ey-kd_radius-18,TEXT("12"),2); radius=110;
mradius=90;//分针半径 hradius=70;//时针半径 x=0,y=0; radian=0;
SetTextColor(hdc,RGB(0,255,225));////设颜色 SetBkColor(hdc,RGB(0,0,0));////设颜色 ti2();
a=sec*6/180.0*3.14; b=min*6/180.0*3.14;
c=(hour*30.0-90.0+(min+15)/2.0)/180.0*3.14; SetTextColor(hdc,RGB(0,255,255)); my=mradius*sin(b); mx=mradius*cos(b); SelectObject(hdc, gpn);
MoveToEx(hdc,ex,ey,NULL); LineTo(hdc,ex+mx,ey+my); LineTo(hdc,ex+mx,ey+my); hy=hradius*sin(c); hx=hradius*cos(c); SelectObject(hdc, blue);
MoveToEx(hdc,ex,ey,NULL); LineTo(hdc,ex+hx,ey+hy); ReleaseDC(hwnd, hdc);
正在阅读:
万年历c语言源程序05-23
2019-2020年高一上学期期末质量检测 化学(A)试题 解析05-09
螺纹连接设计 - 图文04-22
2013年新课标高考数学模拟试卷205-28
水电安装施工组织设计范本10-20
天津房地产估价师《案例与分析》:未定事项假设考试试卷10-21
Module1Unit 1 Its more than twenty thousand kilometers long01-25
会员管理系统使用说明书12-30
- 教学能力大赛决赛获奖-教学实施报告-(完整图文版)
- 互联网+数据中心行业分析报告
- 2017上海杨浦区高三一模数学试题及答案
- 招商部差旅接待管理制度(4-25)
- 学生游玩安全注意事项
- 学生信息管理系统(文档模板供参考)
- 叉车门架有限元分析及系统设计
- 2014帮助残疾人志愿者服务情况记录
- 叶绿体中色素的提取和分离实验
- 中国食物成分表2020年最新权威完整改进版
- 推动国土资源领域生态文明建设
- 给水管道冲洗和消毒记录
- 计算机软件专业自我评价
- 高中数学必修1-5知识点归纳
- 2018-2022年中国第五代移动通信技术(5G)产业深度分析及发展前景研究报告发展趋势(目录)
- 生产车间巡查制度
- 2018版中国光热发电行业深度研究报告目录
- (通用)2019年中考数学总复习 第一章 第四节 数的开方与二次根式课件
- 2017_2018学年高中语文第二单元第4课说数课件粤教版
- 上市新药Lumateperone(卢美哌隆)合成检索总结报告
- 源程序
- 万年历
- 语言
- 办公室通报第1期
- 速冻地瓜项目可行性研究报告(发改立项备案+2013年最新案例范文)详细编制方案
- 14 制药工艺放大研究
- 数据库习题(含参考答案)
- 高二数学必修3总复习(用)
- VaR-GARCH模型在我国股指期货风险管理中的应用
- 冬季施工技术交底
- 高职院校班主任工作模式新探
- 无线通信系统维特比译码的FPGA仿真验证_高志斌
- 特灵离心机荣获美国环保大奖
- 大学生党员参与社会实践的意义与现状分析
- 博思堂-半岛城邦2期整合推广策略-巅峰之上
- Hadoop集群(第5期)_Hadoop安装配置
- 中国隋唐时期的服饰文化
- 海运船舶知识入门
- 达依中学食堂食物中毒应急预案处理方案3-31
- 宝宝5个月发育标准_第1周
- 3D篮球游戏最篮球全新进阶攻略大放送
- 幼儿园新教师个人实习工作总结 三篇
- 工程预算成本测算思路