Console output

i'm trying to output an ansi graphic in cosole. But there're two problems. How can i set console borders wider and how can i manipulate with text/background colour? Sorry if i missed smth in search results, i just hurry. Thanks
search this

SetConsoleCursorPosition

SetConsoleTextAttribute

hmm.. I guess you need example.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void CGraphics::posShape(int x1, int y1, int color, char blk)
{
	COORD Position;
	CONSOLE_CURSOR_INFO info;
	HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
        //if you want to hide the cursor in console add these two lines
	info.bVisible = false; //make the cursor invisible
	info.dwSize = 1;//length of the cursor

	SetConsoleTextAttribute(hOut,color);//sets the color of the printed output
        //color range from 0 - 15
	Position.X = x1; //set the position of x
	Position.Y = y1; //set the position of y
	SetConsoleCursorPosition(hOut, Position);
	cout<<blk;//outputs a character at position (x1,y1)
}


Hope this helps... be sure to include windows.h library
Last edited on
interesting.. i'll try it, but COORD Position is something like.. cursor position? Sorry for bad english. Well, i don't think this helps me to get a wider console though. I mean that console width by default is 80, and need another number. Is it possible from project? I mean, i can change width in propeties of runnig console, but that's not so right, is it?
P.S.: thanks
Last edited on
and is there a simple way to include a text file to application? I mean, is there a way to make output not from outer file with FILE *f=fopen, but to save data within application?

Will try to make an array of c-strings
Last edited on
SetConsoleScreenBufferSize isn't working. It runs, but still console size is by default. What's wrong?

COORD pos;
pos.X=130;
pos.Y=60;
SetConsoleScreenBufferSize(hStdout, pos);

Width is 80...
This isn't a limitation of your program this is part of the Command Line shell. The size of which is 80 by default through Windows OS's.

Here: http://ss64.com/nt/mode.html

Pass this command to the console using your prefered method. I would experiment with system() to get the fine tuneing right because it is easy, but swap it out for one of the others later.
how am i should use system() in this case? It seems the mos convenient way, but i don't know enough about it. Where to look?
You look here under the search box. Type system() click search and it's the first one to pop up. You'll catch some flak for using system() so only use it to prototype.

system("MODE CON: COLS=130");
thanks, it was what i needed exactly
Topic archived. No new replies allowed.