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;
}