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

       在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后,要处理month
    for(i = 1; i < month; i++)  // 不是i <= month
		weekday = (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 implementation
int 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的一部分.

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值