C++完善界面的几个函数,隐藏、显示光标,输出彩色字符

1.光标的隐藏与显示
2.输出彩色字符
3.播放声音文件
1.光标的隐藏与显示
#include
#include <windows.h>
#include <conio.h>
using namespace std;
void gotoxy(int x,int y)
{
HANDLE h;
COORD c;
c.X=x;
c.Y=y;
h=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(h,c);
}
void hide_cursor()//隐藏光标
{
HANDLE h_GAME =GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cursor_info;
GetConsoleCursorInfo(h_GAME,&cursor_info);
cursor_info.bVisible=false;
SetConsoleCursorInfo(h_GAME,&cursor_info);
}
void show_cursor()//显示光标
{
HANDLE h_GAME =GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cursor_info;
GetConsoleCursorInfo(h_GAME,&cursor_info);
cursor_info.bVisible=true;
SetConsoleCursorInfo(h_GAME,&cursor_info);
}
void move(int x0,int y0)
{
char c1,c2;
int x=x0,y=y0;
while(true)
{
gotoxy(x,y);//绘制图形
cout<<“●”;
c1=getch();//接收键盘码
if(c127)break;//如果是esc键的话,跳出循环
if(c1
-32)//如果是方向键的键盘码
{
gotoxy(x,y);
cout<<" ";//清除图形
c2=getch();
switch(c2)
{
case 72:–y;break;//向上
case 80:++y;break;//向下
case 75:–x;break;//向左
case 77:++x;break;//向右 坐标原点在左上角
}

    }
}

}
int main()
{
hide_cursor();
move(10,10);
show_cursor();
return 0;
}
2.输出彩色字符
#include
#include <windows.h>
#include <conio.h>
using namespace std;
void color(int a)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
}
int main()
{
int i;
for(i=0;i<128;i++)//显示出所有的颜色所对应的数字
{
color(i);//调用函数
cout<<i<<"-hello"<<endl;//使字符变色
}
return 0;
}

  • 6
    点赞
  • 35
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值