一、隐藏光标
1、引入头文件window.h
2、 定义光标信息结构体变量 CONSOLE_CURSOR_INFO cursor info={1,0};
typedef struct _CONSOLE_CURSOR_INFO
{
DWORD dwSize; // 光标百分比大小
BOOL bVisible; // 是否可见
} CONSOLE_CURSOR_INFO, *PCONSOLE_CURSOR_INFO;
3、 获取控制台句柄
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
4、 调用设置控制台光标信息函数
SetConsoleCursorInfo(handle,&cursor info);
其中:BOOL SetConsoleCursorInfo // 设置光标信息
{
HANDLE hConsoleOutput, // 句柄
CONST CONSOLE_CURSOR_INFO *lpConsoleCursorInfo // 光标信息
};
二、设置光标位置
1、 引入头文件window.h
2、 获取控制台句柄
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
3、设置光标位置
其中:BOOL SetConsoleCursorPosition
{
HANDLE hConsoleOutput, // handle to console screen buffer
COORD dwCursorPosition // new cursor position coordinates
};
typedef struct COORD
{ // coord.
SHORT X; // horizontal coordinate
SHORT Y; // vertical coordinate
} COORD;
以上是理论只是咯。
下面是我用在显示日历系统的应用例子,毫不吝啬的分享给你们咯~~嘻嘻!!!!
!!!无比重要的一段!!!
void ConPos(int x,int y) //
{ //
COORD pos; //
pos.X = x; //
pos.Y = y; //
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); //
SetConsoleCursorPosition(handle,pos); //
}
void ShowFace(Date *d,Time *t,int *flag)
{
int i,j;
for(i = 1;i<15;i++)
{
ConPos(5,i);/应用///
cout<<"||";
}
for(i = 1;i<15;i++)
{
ConPos(35,i);
cout<<"||";
}
for(j = 7;j<35;j++)
{
ConPos(j,1);//
cout<<"=";
}
for(j = 7;j<35;j++)
{
ConPos(j,4);
cout<<"=";
}
for(j = 7;j<35;j++)
{
ConPos(j,14);
cout<<"=";
}
ConPos(9,3);/
GetCurDate(d,flag);
ShowDate(d);
char title1[15] = {"Welcome to..."};
char title2[18] = {"Anna Calendar^-^"};
ConPos(10,8);///
for(i = 0;i<15;i++)
{
printf("%c",title1[i]);
Sleep(100);
}
ConPos(15,10);/
for(i = 0;i<18;i++)
{
printf("%c",title2[i]);
Sleep(100);
}
ConPos(0,15);/
}