由电脑缺扫雷游戏想到的: 如何把自己的.exe放到系统中?

来源:互联网 发布:死亡录像 知乎 编辑:程序博客网 时间:2024/05/06 20:30

转自:http://blog.csdn.net/stpeace/article/details/8266821

在Windows中,有自带的扫雷游戏,但有的电脑上没有,怎么办呢?从另外电脑上把winmine.exe复制过来就可以了,下面不谈扫雷游戏,而谈如何把自己做的日历变成Windows操作系统的一部分.

 

      编译链接下面的程序,生成myCalendar.exe

#include<stdio.h>#include<windows.h>// 用了windows.h就不要用自定义的BOOL(而用MY_BOOL)// 否则冲突.typedef enum{MY_FALSE, MY_TRUE} MY_BOOL;// 提示用户void remindUsers(){printf("This is a calendar!\n");printf("Input a year(year >= 1990)!\n");printf("Press the key Enter afterwards!\n");}// 获得年份(year >= 1990)int getYear(){int year;while(1){scanf("%d", &year);if(year >= 1990)return year;printf("The year should not be before 1990.\n");}}// 闰年判断MY_BOOL isLeapYear(int year){if((0 == year % 400)||(0 == year % 4 && 0 !=year % 100))return MY_TRUE;return MY_FALSE;}// 一个月的天数(其中2月跟年份有关)int daysInMonth(int year, int month){switch(month){case 2:  if(isLeapYear(year)) return 29;return 28;case 4:case 6:case 9:case 11: return 30;default: return 31;}}// 返回第year年,第month天的第一天是星期几int firstDayOfMonth(int year, int month){int weekday = 1; // 1990年第一个月第一天刚好是:星期一int i;for(i = 1990; i < year; i++) // 不是i <= year{// 先把year作笼统处理weekday = (weekday + 365) % 7;// 如果是leap year,需要做特殊处理if(isLeapYear(i))weekday = (weekday + 1) % 7; }// 处理完year后,要处理monthfor(i = 1; i < month; i++)  // 不是i <= monthweekday = (weekday + daysInMonth(year, i)) % 7;return weekday;}// 缩进void indentFirstLine(int weekday){int i;for(i = 0; i < weekday; i++)printf("   ");}// 生成一个月的日历void printCalendarMonth(int year, int month){int weekday, days, i;printf("     %d %d\n",year,month);printf(" Su Mo Tu We Th Fr Sa\n");days = daysInMonth(year, month);weekday = firstDayOfMonth(year, month);indentFirstLine(weekday); // 缩进for(i = 1; i <= days; i++){printf(" %2d", i);if(6 == weekday)printf("\n"); // 星期六后换行weekday = (weekday + 1) % 7;}if(0 != weekday)printf("\n");}// 生成一年的日历void printCalendar(int year){int month;for(month = 1; month <= 12; month++){printCalendarMonth(year, month);printf("\n\n");}}// top-down design and bottom-up implementationint main(){int year;remindUsers();year = getYear();printCalendar(year);system("pause");return 0;}

      将myCalendar.exe复制到C:\WINDOWS\system32 目录下,这样在"开始","运行"中就可以直接输入myCalendar(或myCalendar.exe)打开了. 但是点击"开始","所有程序","附件", 依然没有发现有myCalendar.exe呢.

 

      继续,在C:\Documents and Settings\Administrator\「开始」菜单\程序\附件 目录下右键创立快捷方式,得到:

      在其中填写:C:\WINDOWS\system32\myCalendar.exe, 然后点击"下一步","完成". 一切OK.

 

     点击"开始","所有程序","附件", 便有了myCalendar.exe的显示,跟"计算器"在同一列中, 如下:

       

       这样就可以认为, myCalendar.exe变成了Windows的一部分.