AyrA icon

Console cursor positioning for windows

AyrA | PRO | 12/26/17 10:21:27 PM UTC | 0 ⭐ | 434 👁️ | Never ⏰ | []
C |

1.07 KB

|

None

|

0 👍

/

0 👎

#include <stdio.h>
#include <windows.h>
#include <conio.h>
 
int moveTo(int x, int y){
    COORD coord;
    coord.X = x;
    coord.Y = y;
    HANDLE hConsole=GetStdHandle(STD_OUTPUT_HANDLE);
    return SetConsoleCursorPosition(hConsole, coord);
}
 
void getCursorPosition(int* x, int* y){
    HANDLE hConsole=GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    GetConsoleScreenBufferInfo(hConsole,&csbi);
    *x=csbi.dwCursorPosition.X;
    *y=csbi.dwCursorPosition.Y;
}
 
 
void moveToStart()
{
    int x;
    int y;
    //Get Position
    getCursorPosition(&x,&y);
    //Move to Start
    moveTo(0,y);
}
 
void fillLine(){
    int width;
    int i=0;
    HANDLE hConsole=GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    GetConsoleScreenBufferInfo(hConsole,&csbi);
    width=csbi.dwSize.X;
    moveToStart();
    for(i=0;i<width;i++){
        putchar(' ');
    }
    moveTo(0,csbi.dwCursorPosition.Y);
}
 
int ask(const char* Frage){
    int i=0;
    printf("%s [y/n]:", Frage);
    while(i!='y' && i!='n' && i!='Y' && i!='N'){
        i=getch();
    }
    putchar('\n');
    return i=='y' || i=='Y';
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎