C++C#控制台字体颜色与标题

system("color b0"); 
   //SetConsoleTitle("浤济专栏");方法:右键点击当前解决方案→属性→配置属性→字符集→使用多字节字符集 即可。
    string 标题 = "浤济专栏";
    system(("title " + 标题).data());//c_str

#define whiteFont FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_INTENSITY  //对标志位进行组合设置成白字红底
#define whiteFont_redBck  BACKGROUND_RED|FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN|BACKGROUND_INTENSITY|FOREGROUND_INTENSITY  //对标志位进行组合设置成红字白底

	int aa = 0;//参考https://www.cnblogs.com/kzang/archive/2012/07/17/2595716.html
	while (++aa < 44)
	{
		if (aa == 22)
		{
			HANDLE outPutHandle = GetStdHandle(STD_OUTPUT_HANDLE);//获得控制台设备描述表的句柄
			SetConsoleTextAttribute(outPutHandle, whiteFont_redBck);
		}
		else
		{
			HANDLE outPutHandle = GetStdHandle(STD_OUTPUT_HANDLE);//获得控制台设备描述表的句柄
			SetConsoleTextAttribute(outPutHandle, whiteFont);//设置白字黑背景
		}
		cout << aa << ends;
	}
        static void 输出万年历(int 年, int 月, int 日)
        {
            int r = 1, z = r, nn = 年, yy = 月, bu = 0; string aa = "  ";
            Func<int, string> 补零 = (int 数据) => { return (数据 > 9 ? "" : "0"); };
            while (nn > 0) if (--yy > 0) z += 返回月的天数(nn, yy); else { --nn; yy = 13; }
            nn = 返回月的天数(年, 月); yy = 1; z %= 7;
            //Console.WriteLine("{0}", 月历加载());//引用https://www.jb51.net/article/114755.htm
            Console.Write("{0}年" + 补零(月) + "{1}月" + 补零(日) + "{2}日星期{3}  {4}\n天 一 二 三 四 五 六\n", 年, 月, 日, "天一二三四五六"[(z + 日 - 1) % 7], 月历加载(年, 月, 日));
            while (r <= (35 - bu))
                if (yy >= z)
                {
                    if (r <= 返回月的天数(年, 月)) aa += 月历加载(年, 月, r).Substring(8, 2) + ((yy++ % 7) > 0 ? " " : " \n");
                    if (r == 日)
                    {
                        //Console.ForegroundColor = (ConsoleColor)Enum.Parse(typeof(ConsoleColor), ConsoleColor.GetNames(typeof(ConsoleColor))[12]);
                        Console.BackgroundColor = (ConsoleColor)Enum.Parse(typeof(ConsoleColor), ConsoleColor.GetNames(typeof(ConsoleColor))[12]);
                    }
                    else
                    {
                        //Console.ForegroundColor = (ConsoleColor)Enum.Parse(typeof(ConsoleColor), ConsoleColor.GetNames(typeof(ConsoleColor))[7]); 
                        Console.BackgroundColor = (ConsoleColor)Enum.Parse(typeof(ConsoleColor), ConsoleColor.GetNames(typeof(ConsoleColor))[0]);
                    }
                    Console.Write("{0}{1}{2}", 补零(r++), (r - 1) <= nn ? (r - 1).ToString() : "  ", ((yy % 7) > 0 ? " " : " "));
                    if (aa.Contains("\n")) { Console.Write("{0}", aa = aa.Replace("  ", " ")); aa = "  "; }
                }
                else
                {
                    if (r <= 返回月的天数(年, 月)) aa += (r > 1 ? 月历加载(年, 月, r).Substring(8, 2) : "::::") + ((yy % 7) > 0 ? " " : " \n");
                    Console.Write("{0}{1}{2}", (r > 1 ? 补零(r) : ""), (r > 1 ? (r++).ToString() : "::"), ((++yy % 7) > 0 ? " " : " \n")); ++bu;
                    if (aa.Contains("\n")) { Console.Write("{0}", aa = aa.Replace("  ", " ")); aa = "  "; }
                }
            Console.Write("{0}", aa = aa.Replace("  ", " ")); 
        }
#define whiteFont FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_INTENSITY  //对标志位进行组合设置成白字红底
#define 白字红底  BACKGROUND_RED|FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN|BACKGROUND_INTENSITY|FOREGROUND_INTENSITY  //对标志位进行组合设置成红字白底

#using "..\Debug\农历引用.dll"
using namespace 农历引用;

string 返回月历(int 年, int 月, int 日, bool 选 = true)
{
	系统农历^ 农历 = gcnew 系统农历();
	string aa = ((CT2A)(CString)(农历->月历加载(年, 月, 日))), aaa = "";
	aaa.push_back(aa[8]); aaa.push_back(aa[9]); aaa.push_back(aa[10]); aaa.push_back(aa[11]);
	return (选 ? aa : aaa);
}

void 输出万年历(int 年, int 月, int 日)
{
	int r = 0, z = 1, nn = 年, yy = 月; string s = "天一二三四五六", aa = " ", aaa = 返回月历(年, 月, 日); bool k = false;
	while (nn)if (--yy)z += 返回月的天数(nn, yy); else --nn, yy = 13;
	nn = 返回月的天数(年, 月); yy = (z + 日 - 1) % 7 * 2;
	cout << 年 << "年" << (月 > 9 ? "" : "0") << 月 << "月" << (日 > 9 ? "" : "0") << 日 << "日"  << "星期";
	cout.put(s[yy]).put(s[yy + 1]) << endl;
	cout << "天" << ends << "一" << ends << "二" << ends << "三" << ends << "四" << ends << "五" << ends << "六  ";
	cout << "月历:"; cout.put(aaa[0]).put(aaa[1]).put(aaa[2]).put(aaa[3]);
	cout << "年"; cout.put(aaa[4]).put(aaa[5]).put(aaa[6]).put(aaa[7]).put(aaa[8]).put(aaa[9]).put(aaa[10]).put(aaa[11]) << endl;
	z %= 7; if (z)yy = 返回月的天数(年 - (月 == 12 ? 1 : 0), 月 == 12 ? 月 : --月) - z; else yy = 0;
	while (r < 42)
	{
		if (yy + 1 == 1)k = (k ? false : true);
		if (yy + 1 == 日 && k)
		{
			HANDLE outPutHandle = GetStdHandle(STD_OUTPUT_HANDLE);//获得控制台设备描述表的句柄
			SetConsoleTextAttribute(outPutHandle, 白字红底);
		}
		else
		{
			HANDLE outPutHandle = GetStdHandle(STD_OUTPUT_HANDLE);//获得控制台设备描述表的句柄
			SetConsoleTextAttribute(outPutHandle, whiteFont);//设置白字黑背景
		}
		if (++yy>返回月的天数(年, 月))++月, yy = 0;
		else
		{
			cout << (yy > 9 ? "" : "0") << yy << ends, aa += 返回月历(年, 月, yy, false) + " ";
			if (++r % 7 == 0)
			{
				HANDLE outPutHandle = GetStdHandle(STD_OUTPUT_HANDLE);//获得控制台设备描述表的句柄
				SetConsoleTextAttribute(outPutHandle, whiteFont);//设置白字黑背景
				cout << aa << endl, aa = " ";
			}
		}
	}
	cout << endl;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值