C語言SetConsoleCursorPosition函數(shù)使用方法
更新時間:2021年12月06日 16:48:47 作者:流浪孤兒
這篇文章介紹了C語言SetConsoleCursorPosition函數(shù)的使用方法,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
函數(shù)接口
BOOL WINAPI SetConsoleCursorPosition(
_In_ HANDLE hConsoleOutput,
_In_ COORD dwCursorPosition
);
作用:
實現(xiàn)控制臺光標定位
測試代碼1
#include<stdio.h>
#include<windows.h>
int main()
{
COORD pos = { 15,5 };
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut, pos);
SetConsoleTextAttribute(hOut, 0x01 | 0x05);
printf("HelloWorld!\n");
return 0;
}
測試結(jié)果1

測試代碼2
#include<stdio.h>
#include<windows.h>
int main(){
COORD pos = { 0,0 };
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hOut, 0x01 | 0x05);
for (int i = 0; i < 20; i++){
pos.X = i;
pos.Y = i;
SetConsoleCursorPosition(hOut, pos);
printf("%d%d:HelloWorld!\n", pos.X, pos.Y);
Sleep(1000);
}
return 0;
}
測試結(jié)果2

到此這篇關(guān)于C語言SetConsoleCursorPosition函數(shù)使用方法的文章就介紹到這了。希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
C++ 中malloc()和free()函數(shù)的理解
這篇文章主要介紹了C++ 中malloc()和free()函數(shù)的理解的相關(guān)資料,這里提供用法示例幫助大家理解這部分知識,需要的朋友可以參考下2017-08-08
C語言中經(jīng)socket接收數(shù)據(jù)的相關(guān)函數(shù)詳解
這篇文章主要介紹了C語言中經(jīng)socket接收數(shù)據(jù)的相關(guān)函數(shù)詳解,分別為recv()函數(shù)和recvfrom()函數(shù)以及recvmsg()函數(shù)的使用,需要的朋友可以參考下2015-09-09

