I have a simple C program that represents a loading screen within the console but I can't get the cursor to hide. I tried cranking up the speed of the sleep function so that the cursor timer would be reset and the cursor would be gone but that doesn't work.
我有一个简单的C程序代表控制台内的加载屏幕,但我无法隐藏光标。我尝试启动睡眠功能的速度,以便重置光标计时器,光标将消失,但这不起作用。
Any tips on how to hide the cursor.
有关如何隐藏光标的任何提示。
Code:
#include <stdio.h>
#include <stdlib.h>
const int TIME = 1;
int main(int argc,char *argv[]){
int i;
while (1){
printf("loading");
for (i=0;i<3;i++){
sleep(TIME);
printf(".");
}
sleep(TIME);
printf("\r");
system("Cls");
sleep(TIME);
}
}
3 个解决方案
#1
Add to your program the following function
将以下功能添加到您的程序中
#include <windows.h>
void hidecursor()
{
HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO info;
info.dwSize = 100;
info.bVisible = FALSE;
SetConsoleCursorInfo(consoleHandle, &info);
}
and call it in your main
.
并在你的主要。
And read more in the MSDN
并在MSDN中阅读更多内容
#2
To extend on Bishal's answer:
延伸Bishal的答案:
To hide the cursor: printf("\e[?25l");
隐藏光标:printf(“\ e [?25l”);
To re-enable the cursor: printf("\e[?25h");
要重新启用游标:printf(“\ e [?25h”);
#3
printf("\e[?25l");
This should work ! It is taken from ANSI codesheet where the characters are not just what they are seen. They act like some form of commands.
这应该工作!它取自ANSI代码表,其中的字符不仅仅是它们所看到的。它们就像某种形式的命令。
#1
Add to your program the following function
将以下功能添加到您的程序中
#include <windows.h>
void hidecursor()
{
HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO info;
info.dwSize = 100;
info.bVisible = FALSE;
SetConsoleCursorInfo(consoleHandle, &info);
}
and call it in your main
.
并在你的主要。
And read more in the MSDN
并在MSDN中阅读更多内容
#2
To extend on Bishal's answer:
延伸Bishal的答案:
To hide the cursor: printf("\e[?25l");
隐藏光标:printf(“\ e [?25l”);
To re-enable the cursor: printf("\e[?25h");
要重新启用游标:printf(“\ e [?25h”);
#3
printf("\e[?25l");
This should work ! It is taken from ANSI codesheet where the characters are not just what they are seen. They act like some form of commands.
这应该工作!它取自ANSI代码表,其中的字符不仅仅是它们所看到的。它们就像某种形式的命令。