Thread: gotoxy console help?

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    84

    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.

  2. #2
    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.
    -Mike
    {InFeStEd-ArCh0n}

  3. #3
    Unregistered
    Guest
    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.

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    139
    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()
    "The most common form of insanity is a combination of disordered passions and disordered intellect with gradations and variations almost infinite."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Tic Tac Toe movement
    By $l4xklynx in forum Game Programming
    Replies: 4
    Last Post: 11-06-2008, 07:22 PM
  2. Full Screen Console
    By St0rmTroop3er in forum C++ Programming
    Replies: 1
    Last Post: 09-26-2005, 09:59 PM
  3. Console Functions Help
    By Artist_of_dream in forum C++ Programming
    Replies: 9
    Last Post: 12-04-2004, 03:44 AM
  4. Linux console window questions
    By GaPe in forum Linux Programming
    Replies: 1
    Last Post: 12-28-2002, 12:18 PM
  5. Just one Question?
    By Irish-Slasher in forum C++ Programming
    Replies: 6
    Last Post: 02-12-2002, 10:19 AM