User Tools

Site Tools

blog:2022-08-07_ansi-c_clrscr_gotoxy



2022-08-07 ANSI-C ClrScr & GotoXY

  • We need the clrscr() & gotoxy(x,y) function in MsDos mode.
  • Her is the tested code.

Code

  • void gotoxy(int x, int y) {
        // printf("\033[%d;%dH", y, x);
        COORD V={x, y};
        SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), V);
    }
    
    void clrscr() 
    { 
    	//Clear Screen
    	// Refer:
    	//   https://zhuanlan.zhihu.com/p/415237147
        HANDLE hdout = GetStdHandle(STD_OUTPUT_HANDLE);  // Get standard output handler
        CONSOLE_SCREEN_BUFFER_INFO csbi;    // Define screen buffer attribute variable
        GetConsoleScreenBufferInfo(hdout, &csbi);  // Get screen buffer attribute variable
        DWORD size = csbi.dwSize.X * csbi.dwSize.Y, num = 0; // Define screen size
        COORD pos = {0, 0}; // initial left-top (0,0) coordinate
        // Fill the window as ' ' space to clear the buffer
        FillConsoleOutputCharacter(hdout, ' ', size, pos, &num);
        FillConsoleOutputAttribute (hdout, csbi.wAttributes, size, pos, &num );
        SetConsoleCursorPosition(hdout, pos); // Set cursor to (0,0)
    }

TAGS

  • ANSI-C
  • ClrScr
  • GoroXY

References

  • 97 person(s) visited this page until now.

Permalink blog/2022-08-07_ansi-c_clrscr_gotoxy.txt · Last modified: 2022/08/07 11:12 by jethro

oeffentlich