posts - 3, comments - 1, trackbacks - 0, articles - 0
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理
//Visual C++中使用gotoxy() / clrscr()等函数
#include <windows.h>
void clrscr(void);
void clreol(void);
void clreoscr(void);
void gotoxy(int ,int );

void clrscr(void)
{
   
CONSOLE_SCREEN_BUFFER_INFO    csbiInfo;                           
   
HANDLE    hConsoleOut;
   
COORD    Home = {0,0};
   
DWORD    dummy;
   
hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE);
   
GetConsoleScreenBufferInfo(hConsoleOut,&csbiInfo);
   
FillConsoleOutputCharacter(hConsoleOut,' ',csbiInfo.dwSize.X * csbiInfo.dwSize.Y,Home,&dummy);
   
csbiInfo.dwCursorPosition.X = 0;                                   
   
csbiInfo.dwCursorPosition.Y = 0;                                   
   
SetConsoleCursorPosition(hConsoleOut,csbiInfo.dwCursorPosition);  
}

/*********************************************************************************/

void clreol(void
{
   
CONSOLE_SCREEN_BUFFER_INFO    csbiInfo;                           
   
HANDLE    hConsoleOut;
   
COORD    Home,pos;
   
DWORD    dummy;
   
hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE);
   
GetConsoleScreenBufferInfo(hConsoleOut,&csbiInfo);
   
Home = csbiInfo.dwCursorPosition;
   
pos.X = 80 - csbiInfo.dwCursorPosition.X;
   
FillConsoleOutputCharacter(hConsoleOut,' ',pos.X,Home,&dummy);
}

/*********************************************************************************/

void clreoscr(void
{
   
CONSOLE_SCREEN_BUFFER_INFO    csbiInfo;                           
   
HANDLE    hConsoleOut;
   
COORD    Home;
   
DWORD    dummy;
   
hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE);
   
GetConsoleScreenBufferInfo(hConsoleOut,&csbiInfo);
   
Home=csbiInfo.dwCursorPosition;
   
FillConsoleOutputCharacter(hConsoleOut,' ',csbiInfo.dwSize.X * csbiInfo.dwSize.Y,Home,&dummy);
}

/*********************************************************************************/

void gotoxy(int x,int y
{
   
CONSOLE_SCREEN_BUFFER_INFO    csbiInfo;                           
   
HANDLE    hConsoleOut;
   
hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE);
   
GetConsoleScreenBufferInfo(hConsoleOut,&csbiInfo);
   
csbiInfo.dwCursorPosition.X = x;                                   
   
csbiInfo.dwCursorPosition.Y = y;                                   
   
SetConsoleCursorPosition(hConsoleOut,csbiInfo.dwCursorPosition);  
}

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理