Thread: print onto screen only in a designated area?

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    42

    print onto screen only in a designated area?

    I've seen the command before but I can't remember what it is. I would like to be able to print onto the screen data but only in a certain area. For example, on a window console that has 25 lines, I want to only print on lines 15 through 25 (since whenever you do a printf, it prints at the bottom and scroll things up) and leave 1 through 14 blank. So I would like to see that when the lines reach 15, the next printf prints and the words on line 15 would disappear when everything scrolls up.

    The catch is, I would like to be able to switch the printing area at any given time. Sort of like a toggle between top half and bottom half.

    What I'm trying to do is designate the bottom half of the screen as an informational display that scrolls up with any new information. The top half would be sort of like a map.

    If I can generate a function that changes the printing area at any time while leaving the other printing area untouched, that would be great.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You have to use a compiler specific function or library. Something like ncurses, or some of the printxy functions if you have one of the Borland compilers.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    If you're on Windows, you can use it's API, for things like SetConsoleCursorPosition(). The Borland compiler has more sophisticated tools you can use for this, and I would recommend them. This is an example of the Turbo C (Borland) window() function:

    Code:
    /*
      window   Defines active text-mode window.
    
     Syntax:
       void window(int left, int top, int right, int bottom);
    
    The top left corner of the screen is (1,1).
    
     Prototype in:
     conio.h
    
     Remarks:
    window defines a text window onscreen. If the
    coordinates are in any way invalid, the call
    to window is ignored.
    
       left and top are the screen coordinates
       of the upper left corner of the window.
    
       right and bottom are the screen
       coordinates of the lower right corner.
    
       The minimum size of the text window is one
       column by one line. The default window is
       full screen, with these coordinates:
    
       80-column mode:    1,1,80,25
       40-column mode:    1,1,40,25
    
     Return Value: None.
    
     Portability:
    window works with IBM PCs and compatibles only.
    
    A corresponding function exists in Turbo
    Pascal.
    
     See Also:
      clreol    delline        gotoxy     puttext
      clrscr    gettextinfo    insline   textmode
    */
     Example:
     #include <conio.h>
    
     int main(void)
     {
    
        window(10,10,40,11);
        textcolor(BLACK);
        textbackground(WHITE);
        cprintf("This is a test\r\n");
    
        return 0;
     }
    Turbo C is free, but somewhat limited by it's 16 bit DOS roots. Works great in WindowsXP, but won't work at all in Windows 7 without a virtual software install like VMWare, to give it the 16 bit environment it needs. Google Borland legacy languages for d/l sites.

    As you can see, I still use turbo C, precisely for functions like this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 12:13 AM
  2. Scope And Parameter Passing
    By djwicks in forum C Programming
    Replies: 6
    Last Post: 03-28-2005, 08:26 PM
  3. What kind of programs should I start writing?
    By Macabre in forum C++ Programming
    Replies: 23
    Last Post: 04-12-2003, 08:13 PM
  4. Print Screen
    By /\/\ E /\/ @ in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 08-11-2002, 05:37 PM