Solved

console cursor shape

Posted on 1998-05-22
23
591 Views
Last Modified: 2008-02-01
How do I change the shape of the console cursor?  Mainly I just want to turn it off, make it blank.  
0
Comment
Question by:Booth882
  • 11
  • 7
  • 5
23 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1164607
In DOS or in a win32 console app?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1164608
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.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1164609
Is this what you need?
0
 
LVL 11

Expert Comment

by:alexo
ID: 1164610
Win32: SetConsoleCursorInfo()
Set the bVisible member of the CONSOLE_CURSOR_INFO structure to FALSE.

Docs say:

The SetConsoleCursorInfo function sets the size and visibility of the cursor for the specified console screen buffer.

BOOL SetConsoleCursorInfo(
    HANDLE hConsoleOutput,      // handle of console screen buffer  
    CONST CONSOLE_CURSOR_INFO *lpConsoleCursorInfo       // address of cursor information
   );      
 
hConsoleOutput - Identifies a console screen buffer. The handle must have GENERIC_WRITE access.

lpConsoleCursorInfo - Points to a CONSOLE_CURSOR_INFO structure containing the new specifications for the screen buffer's cursor.
 
If the function succeeds, the return value is TRUE.
If the function fails, the return value is FALSE. To get extended error information, call GetLastError.

When a screen buffer's cursor is visible, its appearance can vary, ranging from completely filling a character cell to showing up as a horizontal line at the bottom of the cell. The dwSize member of the CONSOLE_CURSOR_INFO structure specifies the percentage of a character cell that is filled by the cursor. If this member is less than 1 or greater than 100, SetConsoleCursorInfo fails.

The CONSOLE_CURSOR_INFO structure contains information about the console cursor.
typedef struct _CONSOLE_CURSOR_INFO { // cci  
    DWORD  dwSize;
    BOOL   bVisible;
} CONSOLE_CURSOR_INFO, *PCONSOLE_CURSOR_INFO;
 
dwSize - Specifies a number between 1 and 100, indicating the percentage of the character cell that is filled by the cursor. The cursor appearance varies, ranging from completely filling the cell to showing up as a horizontal line at the bottom of the cell.

bVisible - Specifies the visibility of the cursor. If the cursor is visible, this member is TRUE.

Is that it?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1164611
Probably not, Alex.  If I remember correctly, from a different question he is programming in DOS.  But now we got both bases covered.
0
 
LVL 11

Expert Comment

by:alexo
ID: 1164612
I dunno.  He may have switched over to the dark side.
0
 
LVL 1

Author Comment

by:Booth882
ID: 1164613
the dark side?
I tried the SetConsoleCursorInfo, heres the code

HANDLE hand;

hand = CreateConsoleScreenBuffer(GENERIC_READ |      GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_             BUFFER, NULL);
if(hand == INVALID_HANDLE_VALUE)
     //exception output, exit(1);

if(!SetConsoleCurrentScreenBuffer(hand))
     //exception output, exit(1);

CONSOLE_CURSOR_INFO * cursor;
cursor->bVisible = FALSE;

if(!SetConsoleCursorInfo(hand, cursor))
     //exception output, exit(1);

it compiles, but when I run it it says it performed an illegal operation and will be shut down.  When I go to the debugger it says

"unhandled exception in file.exe:0xC0000005(or something):Access Violation"

and points at the line

cursor->bVisible = FALSE;

Can you tell me what this means?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1164614
answer coming.
0
 
LVL 1

Author Comment

by:Booth882
ID: 1164615
the dark side?
I used the SetConsoleCursorInfo.  heres my code:

HANDLE hand;
CONSOLE_CURSOR_INFO * cursor;

//hand initialization

cursor->bVisible = FALSE;

if(!SetConsoleCursorInfo(hand, cursor)
    //exception output, exit(1);

it compiles but when I run it it says that it has performed an illegal operation and will be shut down.  When I go to the debugger it says, and I quote:

"unhandled exception in file.exe : 0xC000005 : Access Violation"

Can you tell me what this means?

0
 
LVL 22

Expert Comment

by:nietod
ID: 1164616
Am I remembering wrong, or weren't you working in DOS just a few months ago.

Anyway the problem is that the second parameter to SetConsoleCursorInfo() is a pointer to a CONSOLE_CURSOR_INFO structure that you use to pass information about the cursor you want.  You are passing a pointer that has not been initalized, that is, it doesn't really point to a CONSOLE_CURSOR_INFO structure.  That is bad.

Instead declare a CONSOLE_CURSOR_INFO structure.  Fill it in and pass a pointer to it.   Make sense?
0
 
LVL 1

Author Comment

by:Booth882
ID: 1164617
See I thought thats what I was making
what did

CONSOLE_CURSOR_INFO * cursor;

do?
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Author Comment

by:Booth882
ID: 1164618
I was working with console programs.  Still am.
0
 
LVL 1

Author Comment

by:Booth882
ID: 1164619
Then what did

CONSOLE_CURSOR_INFO * cursor;

do?

 And why did it compile if its not pointing to a CONSOLE_CURSOR_INFO structure?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1164620
This is a little hard to explain.  I take it you are not too familiar with pointers. the statement

CONSOLE_CURSOR_INFO * cursor;

declares a pointer that CAN point to a CONSOLE_CURSOR_INFO.  That doesn't mean it does.  You have to make it point to the the thing you want it to point to like  In the following code cursor starts out uninitialized so it points somewhere random.  Then I change its value 3 times.  Twice it points to two different cursor info structures.

CONSOLE_CURSOR_INFO CursorInfo1;
CONSOLE_CURSOR_INFO CursorInfo2;
CONSOLE_CURSOR_INFO * cursor; // cursor points randomly at memory.

cursor = NULL;  // Cursor now points "nowehere".
cursor = &CursorInfo1; // Cursor now points at CursorInfo 1;
cursor = &CursorInfo2; // Cursor now points at CursorInfo2;

In your case you can drop the cursor variable completely.  just declare a structure of type CONSOLE_CURSOR_INFO.  Then pass a pointer to it using

CONSOLE_CURSOR_INFO &CursorInfo;  
// Initialize CursorInfo.
SetConsoleCursorInfo(hand, &CursorInfo)

You probably had better get an introductory C++ book and look at the chapters on pointers.  They are essential!
0
 
LVL 11

Expert Comment

by:alexo
ID: 1164621
That was poor sportsmanship, Todd.

Booth882, The dark side == Microsoft (reference taken from the StarWars trilogy).
0
 
LVL 22

Expert Comment

by:nietod
ID: 1164622
Poor sportsmanship?  for what?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1164623
Oh, you've got a point.  Didn't really think of it. Booth the original answer was Alex's. and he deserves the points.  I guess I was thinking about the new question and the fact that I really wanted to go to bed and had like 20 E-mails come in!
0
 
LVL 11

Expert Comment

by:alexo
ID: 1164624
>> Didn't really think of it
Well, we're only human.  I see it was not intentional so apology accepted, points waved, lat's continue with our business.

>> and the fact that I really wanted to go to bed and had like 20 E-mails come in!
He he.  1:30 AM I went to sleep only to get up 20 minutes later because her royal majesty (4 months old) decided that my shoulder is more comfortable than her bed...

0
 
LVL 1

Author Comment

by:Booth882
ID: 1164625
thats true.  I love you, nietod, but I dont approve of your tactics.  You always answer questions before you actually answer them just so no one will beat you to it.  I know you want the points, but you should be fair to the other experts.  Also it blocks them out in case they had something useful to say.  They can still comment, but there is nothing in it for them, so they usually dont.  But as for this question I think alex is right.  Although you were helpful with the pointer I think he really does deserve the points.  So if alex would please post an answer I can award him his points.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1164626
I agree that alex deserves the points.  This morning I didn't even know why he was "complaining" because I didn't remember answering the question.  Iniitially it hadn't been my intention to answer the question--at least not until I knew what type of program you were writing.   Then I guess in the "heat of the moment" I answered it without really thinking about it.

As far as "my tactic"  Its not mine.  I learned it from someone else and more experts are using it all the time.  I believe it is the fairest way to handle it.  It prevents two experts from typing long answers at the same time and only one getting the points.  It allows experts to provide complete, detailed, and well-thought out answers, rather than rushing out an incomplete answer.
0
 
LVL 11

Accepted Solution

by:
alexo earned 60 total points
ID: 1164627
I'll answer it, since it is Booth882's wish.

Booth882, Todd's "tactic" is actually the best compromise possible.  I use it myself and that's why:

Assume that I see a question that I can provide with a good, complete, detailed and comprehensible answer.  However, writing a code example, compiling and testing it, writing a page of text to go with it and posting the whole thing can take half an hour or more.  During that time, another expert can lock the question with a mediocre two line answer.  Shall I bother "wasting" the time knowing that a newbie customer is not likely to reject a given answer and ask me to resubmit mine?

If the answer is short then I take my chances and if somebody beats me to it, c'est la vie.  I just resubmit it as a comment.

If you check Todd's answering history, almost all his "answer coming..." answers were followed by comments containing detailed and helpful answers.  If you check the time that passed between the lock and the following comment it almost never exceeds 30 minutes.  It is not as if he locks a question and goes to a movie...

I've been answering questions on EE since 10/97 (my "first login" is shown as 2/98 due to a bug).  I saw all kinds of "experts".  Todd is one I highly respect.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1164628
You shouldn't say stuff like that.  It goes to my head.  

thanks,
0
 
LVL 1

Author Comment

by:Booth882
ID: 1164629
I understand, forgive me nietod.  Thank you for all of your help, both of you.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now