以下就來介紹在控制台(命令提示字元)中有關畫面設定的寫法:
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); }
順帶一提清除控制台(命令提示字元)畫面的做法:
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); }有興趣的可以參考看看
沒有留言:
張貼留言