Hello, I am creating app like Micro. Off. Excel in console ...
This is where I am currently : http://prntscr.com/9jtmts
So I wonder Is it possible to color specific location in console app just like I colored one of the cells But without recreating the whole table(in my case) ?
In windows console apps, you can use the function SetConsoleCursorPosition to set the current position of the cursor. This way, you can overwrite just 2 or 3 characters (one cell) instead of rewriting the entire table. You can use colors in the console using SetConsoleTextAttribute (seeing you already managed to color a cell, I think you already know this).
Thank you very much Shadowwolf, I already knew how to use a SetConsoleCursorPosition function but I didn't know It can replace text if you type text at position where the text is already written. So here is my Solution if anyone doesn't know how to achieve this :
void getCursorXY(int &x, int&y) {
CONSOLE_SCREEN_BUFFER_INFO csbi;
if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi)) {
x = csbi.dwCursorPosition.X;
y = csbi.dwCursorPosition.Y;
}
}
void gotoxy(int x, int y)
{
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
int CreateTable() {
//IN FOR LOOP I GET THIS POINTS :
getCursorXY(X1, Y1); //AT THE BEGINING OF TABLE I GET X1 Y1 Pos
getCursorXY(X2, Y2); //AT THE END OF TABLE I GET X2 Y2 Pos
//
//Coloring :
HANDLE hConsole;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, 68);
gotoxy(X1, Y1+1); // JUST EXAMPLE
cout << " ";
gotoxy(X1, Y2 + 1);
SetConsoleTextAttribute(hConsole, 15);
return 0;
}