Show/Hide Cursor

Can anyone help me with showing/hiding cursor? I tried, but with no success. It would be wonderful if you could help me. P.S. Please, if anyone will be able to help me, write the entire code. Thanks in advance.
Last edited on
@Isengardium

Here's how I turn off the cursor. You'll notice, when I finish the program, I reset the cursor with setcursor(1,10);. Using different numbers instead of 10, will change the thickness of the flashing cursor. Try it out.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Set Cursor.cpp : main project file.

#include <iostream>
#include <windows.h>

using namespace std;

void setcursor(bool, DWORD);

HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);

void setcursor();

int main()
{
    cout << "Cursor ON for 10 seconds." << endl;
	for (int x= 0; x<10;x++)
	{
		Sleep(1000);
	}
	setcursor(0,0);
	cout << "Cursor OFF for 10 seconds." << endl;
	for (int x= 0; x<10;x++)
	{
		Sleep(1000);
	}
	cout << "Cursor is now back ON." << endl;
	setcursor(1,10);


    return 0;
}

void setcursor(bool visible, DWORD size) // set bool visible = 0 - invisible, bool visible = 1 - visible
{
	if(size == 0)
	{
		size = 20;	// default cursor size Changing to numbers from 1 to 20, decreases cursor width
	}
	CONSOLE_CURSOR_INFO lpCursor;	
	lpCursor.bVisible = visible;
	lpCursor.dwSize = size;
	SetConsoleCursorInfo(console,&lpCursor);
}
Hi there,

I'm afraid you will have to be a bit more specific.
I'm assuming you're writing a GUI application (as opposed to console), so the least we'll need to know is which GUI framework you are using.

Thanks!

All the best,
NwN
Topic archived. No new replies allowed.