Fast clrscr function

This is a discussion on Fast clrscr function within the C Programming forums, part of the General Programming Boards category; >>I want to create a fast clear screen code. This code clears only >>one row and I don't know why. ...

  1. #16
    Unregistered
    Guest
    >>I want to create a fast clear screen code. This code clears only >>one row and I don't know why. PLEASE HELP!!!

    Theese are your words...Point where exactly you are saying you want to clear a window of the screen...
    you should read your thread more carefuly

  2. #17
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    Code:
    void cls(short x, short y, short EraseLength, short NoOfLines)
    {
            union REGS i, o;
    
            i.h.ah = 6;                   /*   Function Number   */
            i.h.al = 0;                   /*   Clear Screen      */
            i.h.bh = 7;                   /*   Color             */
            i.h.ch = y - 1;               /*   Y - coordinate    */
            i.h.cl = x - 1;               /*   X - coordinate    */
            i.h.dh = NoOfLines   - 1;     /*   No. of rows       */
            i.h.dl = EraseLength - 1;     /*   No. of cols       */
    
            int86(16, &i, &o);            /*  Issue interrupt 16 */
    
            gotoxy(x, y);                 /*  Position Cursor    */
    }
    I hope this solves all your doubts.

  3. #18
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    Unregistered:
    This are my words too: "I want that printf will be used only once and that the program will clear the selected rows and cells in one shot." - you see SELECTED rows and cells.

    I think you should read the thread more carefully.

    shaik786:
    Your code is for DOS. C'mon people, READ MY INSTRUCTIONS!!!!!!!!!!!!

    I'm programming in VC++.NET (win32 console program) and VC++.NET does not support direct access to the video memory.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  4. #19
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    I don't understand why you are using printf() to clear the screen of all functions! Anyway, I hope the following code satisfies you:

    Code:
    void mclrscr (short x, short y, short EraseLength, short NoOfLines)
    {
            int i, j, k, pos;
            char scr[2500];
    
            pos = 0;
    	for(j = y; j < y + NoOfLines; j ++) {
                    k = 0;
    		while(k ++ < (x - 1))
    			scr[pos ++] = ' ';
    
    		for(i = x; i < x + EraseLength; i ++) {
    			scr[pos ++] = ' ';
                    }
    
                    scr[pos ++] = '\n';
            }
            scr[pos ++] = '\0';
    
    	gotoxy(1, y);
    
            printf("%s", scr);
    	fflush(stdout);
    
    	gotoxy(x, y);
    }

  5. #20
    Registered User
    Join Date
    Jun 2002
    Posts
    14

    I'M AGAIN WITH THE SOLUTION!

    here you have to pass the size & position of your block which you want to be cleared...

    this is what you want!

    /*

    here
    sr = starting row
    er = ending row
    sc = starting coloumn
    ec = ending coloumn

    */

    #include<stdio.h>
    #include<conio.h>
    #include<dos.h>

    void cls(void);

    int main()
    {

    gotoxy(5,5);

    printf("please write anything on the screen anywhere & pass parameter to this function cls() according to your need!");

    getch(5,5,7,7,10);
    cls();
    printf("you're done!");

    getch();
    return 0;
    }

    void cls()
    {
    union REGS i,o;

    i.h.ah = 6;
    i.h.bh = attb;
    i.h.ch = sr;
    i.h.dh = er;
    i.h.al = 0;
    i.h.cl = sc;
    i.h.dl = ec;

    int86(16,&i,&o);
    gotoxy(1,1);

    //gotoxy(sr,sc);

    }
    Ruchit,
    think big,think ahead,
    go big,go ahead,

    ISN'T IT TOO FUNNY ABOUT MICROSOFT WINDOWS,THAT
    WHENEVER YOU WANT TO DO SOMETHING YOU CLICK ON "START" BUTTON AND THE FIRST OPTION YOU ARE HAVING IS
    "SHUT DOWN"...

  6. #21
    Registered User
    Join Date
    Jun 2002
    Posts
    14

    Smile

    sorry there was an error!


    #include<stdio.h>
    #include<conio.h>
    #include<dos.h>

    void cls(void);

    int main()
    {

    gotoxy(5,5);
    printf("please write anything on the screen anywhere & pass parameter to this function cls() according to your need!");
    getch(5,5,7,7,10);
    cls();
    printf("you're done!");

    getch();
    return 0;
    }

    void cls(int sr,int sc,int er,int ec,int attb)
    {
    union REGS i,o;

    i.h.ah = 6;
    i.h.bh = attb;
    i.h.ch = sr;
    i.h.dh = er;
    i.h.al = 0;
    i.h.cl = sc;
    i.h.dl = ec;

    int86(16,&i,&o);
    gotoxy(1,1);
    }
    Ruchit,
    think big,think ahead,
    go big,go ahead,

    ISN'T IT TOO FUNNY ABOUT MICROSOFT WINDOWS,THAT
    WHENEVER YOU WANT TO DO SOMETHING YOU CLICK ON "START" BUTTON AND THE FIRST OPTION YOU ARE HAVING IS
    "SHUT DOWN"...

  7. #22
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    s_ruchit:
    You are not helping me. I don't understand you. I wrote that your code is for DOS. READ the whole thread.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  8. #23
    Registered User
    Join Date
    Aug 2001
    Posts
    247
    Here are a couple of functions I constructed for a small user interface within a program. The functions make full use of the <conio.h> library and was compiled on borlands tcwin4.5C++.

    This function set up the user screen display...which was then filled with an appropriate message

    Code:
    void user_grid (void)
    {
      int i;
      /* the user grid */
      clrscr();
      for(i = 0; i < 77; i++)
      {
               gotoxy(2 + i, 2);putchar('*');
               gotoxy(2 + i, 5);putchar('*');
               gotoxy(2 + i, 24);putchar('*');
      }
      for(i = 0; i < 21; i++)
      {
               gotoxy(2, 3 + i);putchar('*');
               gotoxy(78, 3 + i);putchar('*');
      }
    }   /* end user_grid function */
    during the process of the program user messages were printed to the center of the grid. Each set of messages were cleared from the center grid by the following function..

    Code:
    void clrgrid (void)
    {
       int i;
       /* Clear previous user messages */
       for(i = 0; i < 16; i++)
      {
    	gotoxy(3, 7 + i);
    	printf("%75c", ' ');
       }
    } /* end clrgrid function */
    you could attempt this program to see it work
    Code:
    int main (void)
    {
    	int i = 0;
    
    	user_grid();
    	for(i = 0; i < 10; i++)
    	{
    		gotoxy(8, 8 + i);
    		printf("FIRST USER MESSAGES");
    	}
    	gotoxy(10, 20);puts("Hit return to continue :");
    	gotoxy(34, 20);getch();
    	clrgrid();
    	for(i = 0; i < 10; i++)
    	{
    		gotoxy(8, 8 + i);
    		printf("SECOND USER MESSAGES");
    	}
    
    	return 0;
    }
    hoping to be certified (programming in c)
    here's the news - I'm officially certified.

  9. #24
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    I'm not sure how it compares with speed, but have you considered System("CLS") from stdlib.h?

  10. #25
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    Sean and bigtamscot:

    You're not helping me. BEFORE YOU POST ANYTHING, PLEASE, READ THE THREAD!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  3. Bisection Method function value at root incorrect
    By mr_glass in forum C Programming
    Replies: 3
    Last Post: 11-10-2005, 08:10 AM
  4. Replies: 4
    Last Post: 11-23-2003, 06:15 AM
  5. Replies: 5
    Last Post: 02-08-2003, 06:42 PM

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