自己用过的API函数

版权声明:吴鹏 https://blog.csdn.net/qq_28311415/article/details/81179982

(1)API中定位光标位置的函数 SetConsoleCursorPosition
举例:
 

#include<iostream>
#include<Windows.h>
using namespace std;


void gotoxy(int x, int y)
{
	COORD pos;
	pos.X = 2 * x;
	pos.Y = y;
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}

void main()
{
     gotoxy(4,5);
     cout<<"."<<endl;
     system("pause->null");
}

(2)设计字体颜色和背景色的函数SetConsoleTextAttribute(),GetStdHandle(STD_OUTPUT_HANDLE)获得句柄。
    

FOREGROUND_INTENSITY  表示设置前景色为高亮显示。

FOREGROUND_RED        表示设置前景色为红色,即字体颜色为红色。

FOREGROUND_GREEN      表示设置前景色为绿色,即字体颜色为绿色。

FOREGROUND_BLUE       表示设置前景色为蓝色,即字体颜色为蓝色。

BACKGROUND_INTENSITY  表示设置背景色为高亮显示。

BACKGROUND_RED        表示设置背景色为红色。

BACKGROUND_GREEN      表示设置背景色为绿色。

BACKGROUND_BLUE       表示设置背景色为蓝色。
 

#include<Windows.h>
#include<iostream>
using namespace std;

void color(int a)
{
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), a);
}
void main()
{
    color(FOREGROUND_RED);

    cout<<"中国人"<<endl;  
}

猜你喜欢

转载自blog.csdn.net/qq_28311415/article/details/81179982