-
gotoxy console help?
i am currently using c++ to program in a console application, and hoped that someone could help me on a certain matter.
i am trying to draw boxes in positions on screen in the console window, but am not sure how to go about it. if someone could give me a pointer as to how to draw these boxes using the gotoxy command, i would be most grateful.
-
Boxes, I'd assume it would be drawn by characters that are blocks. Find the ASCII value of a block character in dos and print a bunch of them. That should give you a box. However, I do not know the function to print text at a specific location.
-
The ASCII character value for a simple box are:
top left: 201
top right: 187
horizontal bars: 205
vertical bars: 186
bottom right: 188
bottom left: 200
Here's one way to use them (simple program):
Code:
#include <iostream>
#include <conio>
using namespace std;
int main()
{
char TopLeftCorner=201, HorizontalPipes=205, TopRightCorner=187, VerticalPipes=186, BottomRightCorner=188, BottomLeftCorner=200;
gotoxy(2,2);
cout<<TopLeftCorner<<HorizontalPipes<<HorizontalPipes<<HorizontalPipes<<HorizontalPipes<<TopRightCorner;
gotoxy(2,3);
cout<<VerticalPipes<<" "<<VerticalPipes;
gotoxy(2,4);
cout<<VerticalPipes<<" "<<VerticalPipes;
gotoxy(2,5);
cout<<BottomLeftCorner<<HorizontalPipes<<HorizontalPipes<<HorizontalPipes<<HorizontalPipes<<BottomRightCorner;
return 0;
}
Keep in mind that this makes for a lot of extra trouble, plus it's really ugly.
-
or here is another ugly one :)
Code:
void create_box(int start_x,int start_y,int len_x,int len_y)
{
int x,y;
for (y=start_y;y<start_y+len_y+1;y++)
for (x=start_x;x<start_x+len_x+1;x++)
if ((y==start_y)||(y==start_y+len_y))
{
gotoxy(x,y);
cout << char(205);
}
else
{
gotoxy(start_x,y);
cout << char(186);
gotoxy(start_x+len_x,y);
cout << char(186);
}
gotoxy(start_x,start_y);
cout << char(201);
gotoxy(start_x+len_x,start_y);
cout << char(187);
gotoxy(start_x,start_y+len_y);
cout << char(200);
gotoxy(start_x+len_x,start_y+len_y);
cout << char(188);
}//end create_box()