What is wrong with my source code (HANDLE)

Okay, I made a program which hides the annoying blinking cursor, but it's not working correctly... the cursor is still there.

I tried with Visual Studio and Dev-C++, but the cursor does not hide from the console. Thank you, here's the code:

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
#ifndef _UTILITIES_H_
#define _UTILITIES_H_

#endif

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

using namespace std;

void CursorOff();

void InitProgram()
{
     system("color f2");
     CursorOff();
     cout << "Welcome";
     _getch(); 
}

void CursorOff() 
{
     HANDLE Handle = GetStdHandle(STD_OUTPUT_HANDLE);
     CONSOLE_CURSOR_INFO lpCursor;	
     lpCursor.bVisible = false;
     SetConsoleCursorInfo(Handle, &lpCursor);
}


1
2
3
4
5
6
7
8

#include <utilities.h>

int main()
{
     InitProgram();
     return 0;
}
Last edited on
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
#include <iostream> 
#include <conio.h>
#include <windows.h>

using namespace std;

void CursorOff();

void InitProgram()
{
    system("color f2");
    CursorOff();
    cout << "Welcome";
    _getch();
}

void CursorOff()
{
    HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);

    CONSOLE_CURSOR_INFO info;
    GetConsoleCursorInfo(h, &info);
    
    info.bVisible = FALSE;
    SetConsoleCursorInfo(h, &info);
}

int main()
{
    InitProgram();
}


Don't leave struct members uninitialized.
So, that's what was missing GetConsoleCursorInfo.

Thank you.
Topic archived. No new replies allowed.