VC如何刷屏(不要system("cls");)
来源:百度知道 编辑:UC知道 时间:2024/05/20 21:24:48
要VC能编译的
gotoxy(0,0)和clrscr();
在VC里都不能编译,为什么?有什么解决办法吗?
除了这3种还有什么高效率的刷屏方法吗?
我写的是C,不是C++
感谢...
控制台:清屏, gotoxy
#include <windows.h>
#include <stdio.h>
#include <string.h>
void Cls(HANDLE hConsole);
int main()
{
DWORD state = 0, res;
COORD pos = {0, 0};
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
Cls(hOut);
pos.X = 5; pos.Y = 5;
SetConsoleCursorPosition(hOut, pos); /* 设置光标位置 */
printf("position: 5, 5\n");
CloseHandle(hOut);
}
void Cls(HANDLE hConsole)
{
COORD coordScreen = {0, 0};
BOOL bSuccess;
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
bSuccess = GetConsoleScreenBufferInfo(hConsole, &csbi);
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
bSuccess = FillConsoleOutputCharacter(hConsole, (TCHAR) ' ', dwConSize, coordScreen, &cCharsWritten);
bSuccess = GetConsoleScreenBufferInfo(hConsole, &csbi);