Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 817
  • Last Modified:

Cursor Hiding

I am looking for a solution to hide (and possibly change) the cursor in DOS console application.  I am using WinNT 4 and Vis C++ 6 to compile.  I read an answer by neitod stating:

In DOS use int 10H Sub-function 1
Set AH to 1
CH to the cursor start line 0-15
CL to cursor end line 0-15.  
and execute interupt 10H.
To make cursor dissapear set the start and end lines 0.  To make the a big block cursor set start to 0 and end to 15.

I am ABSOLUTELY confused by all this, but this seems to be the way to go.  If someone could explain how to get this working, and if possible, supply me a simple source code to get this working, I would be very thankful.  Thnx!
0
junkyboy
Asked:
junkyboy
  • 4
1 Solution
 
nietodCommented:
You could use that in a DOS program.  But you aren't writting a DOS program.  VC 6 doesn't produce DOS programs.  What you are producing is a win32 console program.  These usuallu look (to the user) like a DOS program, but thy are VERY different kind of programs--as far as the programmer is concerned.  that method will not work in a win32 console program.  Fortunatly, there are many wonderful windows API functions that will let you do this and more.

continues.
0
 
nietodCommented:
In win32, you can show/hide/resize the cursor using the SetConsoleCursorInfo() function.  Look this up in the help.  I have some examples of this, but currenlty can't seem to find it.  I'll keep looking.  I do have some other examples of related things that will also be of interest to you.
0
 
nietodCommented:
Here are functions for getting/setting the cursor's size.  The size is specified as the percent of the cursor's height compared to the character cell height.   0, means the cursor is invisible, 100 means it fills the cell. 50 means it take up the lower half of the cell etc.

//------------------------------------------------------------------------------------------------//
// TITLE:  Get Cursor Size.                                                                       //
//      This procedure returns the current cursor size.  The size is returned as a value between  //
// 0 and 100 (inclusive) indicating the percent of the character cell height that is filled with  //
// the cursor.  0 will be returned if the cursor is invisible.                                    //
int                                              // Cursor size.                                  //
GetCrsSiz(void)
{
   CONSOLE_CURSOR_INFO CrsInf;
   static HANDLE StdOutHnd = GetStdHandle(STD_OUTPUT_HANDLE); // >> standard output.                 //

   GetConsoleCursorInfo(StdOutHnd,&CrsInf);
   if (CrsInf.bVisible)                          // If the cursor is visible, then                //
      return CrsInf.dwSize;                      // Return the cursor size.                       //
   return 0;                                     // Indicate the cursor is invisible.             //
}
//------------------------------------------------------------------------------------------------//
// TITLE:  Set Cursor Size.                                                                       //
//      This procedure sets the current cursor size.  The size is specified as a value between    //
// 0 and 100 (inclusive) indicating the percent of the character cell height that is filled with  //
// the cursor.  Specify 0 to make the cursor invisible.                                           //
void
QConSetCrsSiz(int Siz)                           // New cursor size.  This value should be from 0 //
                                                 // to 100.                                       //
{
   CONSOLE_CURSOR_INFO CrsInf;
   static HANDLE StdOutHnd = GetStdHandle(STD_OUTPUT_HANDLE); // >> standard output.                 //

   if (Siz <= 0)                                 // If cursor should be made invisible, then      //
   {
      CrsInf.bVisible = FALSE;                   // Indicate cursor is invisible.                 //
      CrsInf.dwSize   = 1;                       // Set cursor size to its minimum.               //
   }
   else                                          // Otherwise, if cursor should be made visible,  //
   {
      CrsInf.bVisible = TRUE;                    // Indicate cursor is visible.                   //
      CrsInf.dwSize   = min(Siz,100);            // Set cursor size to specified size.            //
   }
   SetConsoleCursorInfo(StdOutHnd,&CrsInf);      // Set the cursor size.                          //
}
0
 
nietodCommented:
Here is some more code showing how to move the cursor around and to change the color of the output.

#include <stdio.h>
      #include <string.h>
      #include <stdlib.h>
      #include <windows.h>
      FILE*fp;

enum Color
{
   Red,
   Green,
   Blue,
   Yellow,
   Purple,
   Cyan,  
   White,
   Black
};

void GotoXY(int X,int Y)
{
      HANDLE StdOut = GetStdHandle(STD_OUTPUT_HANDLE);
      COORD Coord = {X,Y};
      SetConsoleCursorPosition(StdOut,Coord);
}
void OutputStr(const char *S)
{
      HANDLE StdOut = GetStdHandle(STD_OUTPUT_HANDLE);
      int StrLen = strlen(S);
      DWORD LenWrt;
      WriteConsole(StdOut,S,StrLen,&LenWrt,NULL);
}
void OutputStr(int X,int Y,const char *S)
{
      GotoXY(X,Y);
      OutputStr(S);
}

void ClearScreen()
{
   HANDLE StdOut = GetStdHandle(STD_OUTPUT_HANDLE);
   CONSOLE_SCREEN_BUFFER_INFO BufInf;
   COORD Origin = {0,0};
   DWORD LenWrt;

   GetConsoleScreenBufferInfo(StdOut,&BufInf); // Get screen rows and columns.
 
   int ChrCnt = BufInf.dwSize.X * BufInf.dwSize.Y; // Number of chars on screen.
   
   FillConsoleOutputAttribute(StdOut,0,ChrCnt,Origin,&LenWrt);
   FillConsoleOutputCharacter(StdOut,' ',ChrCnt,Origin,&LenWrt);
}
void SetColor(Color TxtCol,Color BckCol)
{
   HANDLE StdOut = GetStdHandle(STD_OUTPUT_HANDLE);
   WORD   Col    = 0;

   switch (TxtCol)
   {
   case Red:    Col |= FOREGROUND_RED;   break;
   case Green:  Col |= FOREGROUND_GREEN; break;
   case Blue:   Col |= FOREGROUND_BLUE;  break;
   case Yellow: Col |= FOREGROUND_RED | FOREGROUND_GREEN;   break;
   case Purple: Col |= FOREGROUND_RED | FOREGROUND_BLUE;    break;
   case Cyan:   Col |= FOREGROUND_GREEN | FOREGROUND_BLUE;  break;
   case White:  Col |= FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; break;
   }
   switch (BckCol)
   {
   case Red:    Col |= BACKGROUND_RED;   break;
   case Green:  Col |= BACKGROUND_GREEN; break;
   case Blue:   Col |= BACKGROUND_BLUE;  break;
   case Yellow: Col |= BACKGROUND_RED | BACKGROUND_GREEN;   break;
   case Purple: Col |= BACKGROUND_RED | BACKGROUND_BLUE;    break;
   case Cyan:   Col |= BACKGROUND_GREEN | BACKGROUND_BLUE;  break;
   case White:  Col |= BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE; break;
   }
   SetConsoleTextAttribute(StdOut,Col);
}

      main()
      {

      char buf[1000], garbage[10], filename[15], inChar[1000], text;
      int m, length, choice, count=1, longs=0, x=0, cnt=0, y=0;
      static int n=0;


   while(1)
   {
      ClearScreen();
      longs=0, n=0, x=0, y=0; cnt=0;
      HANDLE StdOut = GetStdHandle(STD_OUTPUT_HANDLE);
           
      SetColor(Red,Black);
      OutputStr(0,1,"********************************************************");
      SetColor(Black,Cyan);
      OutputStr(20,2,"P A R A G R A P H");
      SetColor(Purple,Black);
      OutputStr(0,3,"********************************************************");
      SetColor(Black,Cyan);
      OutputStr(20,4,"C O N V E R T E R");
      SetColor(Blue,Black);
      OutputStr(0,5,"********************************************************");

      SetColor(Yellow,Black);
      OutputStr(0, 7,"Paragraph Converter Menu");
      OutputStr(0, 8,"1.  Enter a paragragh");
      OutputStr(0, 9,"2.  Read from file");
      OutputStr(0,10,"3.  Exit");
      OutputStr(0,11,"#########################");
      SetColor(White,Black);
      OutputStr(0,13,"Enter you choice : ");
      GotoXY(20,13);

      fflush(stdin);
      scanf(" %d", &choice);
      gets(garbage);

      ClearScreen();
      GotoXY(0,0);

      switch(choice)
      {
      case 1:

      printf("\nEnter a sentence : ");
      gets(buf);

      length=strlen(buf);

      printf (" \n\n\nProsessing...\n\n\n");

      for ( m=0; m<length; m++)
      {
      if( buf[m] == ' ')
      count++;
      else if (buf[m] == '.' || buf[m] == '?' || buf[m] == '!')
      {

      if(count>20)
      {
      for(n; n<=m; n++)
      {
      inChar[x] = buf[n];
      x++;
      }

      longs++;
      count=1;
      }
      else{
      count=1;
      n=m+1;}
      }
      }

      if(longs>0)
      {
      printf("\nThe following %d sentence(s) is(are) too long, please reduce the number of words to make it more readable.\n\n",
      longs);
      for(cnt; cnt<=x; cnt++)
      {
      printf("%c",inChar[cnt]);
      if(inChar[cnt]=='.')
      printf("\n\n");
      }

      }
      else
      printf("\nThere are no long sentences.\n\n" );


      break;

      case 2:
      printf("\n\nEnter the filename: ");
      scanf(" %s", &filename);
      fp=fopen(filename, "r");
      printf("\nProcessing...");
      if(fp==NULL)
      {
      printf("\n\nFile %s does not exist\n\n", filename);
      }
      else
      {
      printf("\n\nAssume data in file: %s\n\n", filename);
      printf("---------------------------------------------------------------------------\n");
      rewind(fp);
      while((text = getc(fp)) != EOF)
      {
      printf("%c",text);
      buf[y]=text;
      y++;
      }
      fclose(fp);
      printf("\n----------------------------------------------------------------------\n");


      length=strlen(buf);

      for ( m=0; m<length; m++)
      {
      if( buf[m] == ' ')
      count++;
      else if (buf[m] == '.' || buf[m] == '?' || buf[m] == '!')
      {

      if(count>20)
      {
      for(n; n<=m; n++)
      {
      inChar[x] = buf[n];
      x++;
      }
      longs++;
      count=1;
      }
      else{
      count=1;
      n=m+1;
      }
      }

      }

      if(longs>0)
      {
      printf("\nThe following %d sentence(s) is(are) too long, please reduce the number of words to make it more readable.\n\n",
      longs);
      for(cnt; cnt<=x; cnt++)
      {
      printf("%c",inChar[cnt]);
      if(inChar[cnt]=='.')
      printf("\n\n");
      }
      }
      else
      printf("\nThere are no long sentences.\n\n" );


      }




      break;

      case 3:
      printf("\n\nBYE !!!\n\n");
      exit(0);
      break;
      default :
      printf(" \nInvalid selection made.\n");
      break;
      }

      }
      return 0;
      }
0
 
junkyboyAuthor Commented:
Thanks!  Every time I get perfect answers like this, I really feel Experts Exchange IS THE BEST PLACE on the net!  :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now