Solved

Cursor Hiding

Posted on 2000-03-24
5
802 Views
Last Modified: 2008-03-17
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
Comment
Question by:junkyboy
  • 4
5 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 25 total points
ID: 2653841
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
 
LVL 22

Expert Comment

by:nietod
ID: 2653852
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
 
LVL 22

Expert Comment

by:nietod
ID: 2653896
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
 
LVL 22

Expert Comment

by:nietod
ID: 2653903
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
 

Author Comment

by:junkyboy
ID: 2656176
Thanks!  Every time I get perfect answers like this, I really feel Experts Exchange IS THE BEST PLACE on the net!  :)
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Lambda for random numbers problem 7 119
best sources to up-to-date in C++? 8 91
I could not build boost code, 10 96
Embarcadero WebBroker REST server endpoint parameters 2 82
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question