Clear part of the screen

This is a discussion on Clear part of the screen within the C Programming forums, part of the General Programming Boards category; Is there any method in C programming by which i can clear a part of the screen, i.e the last ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    12

    Clear part of the screen

    Is there any method in C programming by which i can clear a part of the screen, i.e the last few lines displayed?

  2. #2
    and the hat of copycat stevesmithx's Avatar
    Join Date
    Sep 2007
    Posts
    498
    Which OS?
    Not everything that can be counted counts, and not everything that counts can be counted
    - Albert Einstein.


    No programming language is perfect. There is not even a single best language; there are only languages well suited or perhaps poorly suited for particular purposes.
    - Herbert Mayer

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    12
    Windows XP is the operating system

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    WriteConsoleOutput perhaps?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    POeT GuY Matus's Avatar
    Join Date
    Feb 2008
    Location
    Bz
    Posts
    235
    Quote Originally Posted by hello View Post
    Is there any method in C programming by which i can clear a part of the screen, i.e the last few lines displayed?
    Though im not sure it is what you want, and most people will agree that it is not the best way. On windows you can use a simple system call

    system("cls");

    and on linux

    system("clear");

    I use them for simple little problems, and yes most people will agree here that it is not the best way either

    or you could use soemthing like what this guy Matt had:

    Code:
    #ifdef WIN32
    # include <windows.h>
    void clearscreen(void)
    {
      DWORD n;                         /* Number of characters written */
      DWORD size;                      /* number of visible characters */
      COORD coord = {0};               /* Top left screen position */
      CONSOLE_SCREEN_BUFFER_INFO csbi;
      HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
      GetConsoleScreenBufferInfo(h, &csbi );
      size = csbi.dwSize.X * csbi.dwSize.Y;
      FillConsoleOutputCharacter(h, TEXT(' '), size, coord, &n);
      GetConsoleScreenBufferInfo(h, &csbi);
      FillConsoleOutputAttribute(h, csbi.wAttributes, size, coord, &n);
      SetConsoleCursorPosition (h, coord);
    }
    #else
    # include <curses.h>
    void clearscreen(void)
    {
      clear(); /* You need curses installed though */
    }
    #endif
    PoEms R InsPiRatiOns of LIfE ExpErienCes!!


  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You can use the windows api "setcursorposition", to set the cursor at the head (left side) of each row you want to start full or partial deletion.

    Then print to the screen, using the foreground and the background colors you want. That will make a text screen be "cleared".

    This was shown a few months back. If you search for "gotoxy", and my name, you should find it fairly easily.

    If not, post back, I do have some code that shows it. I should be able to dig it up. This is for a console "text" window, and does not use the ncurses library.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Clear Screen Again!!!
    By trang in forum C Programming
    Replies: 3
    Last Post: 12-13-2003, 07:36 AM
  2. Yet another clear screen thread :D
    By kermit in forum Linux Programming
    Replies: 2
    Last Post: 11-20-2003, 04:14 AM
  3. How to clear the screen?
    By Zopyrus in forum C++ Programming
    Replies: 8
    Last Post: 11-07-2003, 09:20 PM
  4. Screen section to clear
    By devour89 in forum C++ Programming
    Replies: 1
    Last Post: 12-13-2002, 06:59 AM
  5. How do I clear screen in a C program?
    By DarkboyBlue in forum C Programming
    Replies: 6
    Last Post: 08-21-2002, 11:26 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21