hi.
can anyone tell me how to disable blinkin cursor from my WIN32 console Application.

i have created a console app.. using vc++ but i see the cursor blinkin all the time which is not what i want.

please help

thanks in advance.

Recommended Answers

All 4 Replies

use console functions such as SetConsoleCursorInfo(). see MSDN for details

hey

thanks so much

but could you please give me an example..

please take a look at this code..

switch (prev_dir)
        {
        case 1:
        cout << "L";
        Sleep(2000);
        break;
        case 2:
        cout << "R";
        Sleep(2000);

        break;
        case 3:
        cout << "U";
        Sleep(2000);

        break;
        case 4:
        cout << "D";
        Sleep(2000);

        break;   
        }    
SetConsoleCursorPosition(hOutput, CursorPosition);
cout<<"W";
Sleep(2000);
SetConsoleCursorPosition(hOutput, CursorPosition);

suppose i wanted to print al of this on screen and everytime the key is L it moves to the left side and the cursor blinks with it..
please tell me as to how to disable the cursor or set the cursor background to black

cheers

Below is a quick example -- you can get more console functions and a console class here

I compiled and tested this with Dev-C++ compiler on XP os.

#define _WIN32_WINNT 0x0500
#include <Windows.h>
#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    
    CONSOLE_CURSOR_INFO info;
	HANDLE hOutput = GetStdHandle (STD_OUTPUT_HANDLE);

	// turn the cursor off
	info.bVisible = FALSE;
	info.dwSize = 1;
    if( SetConsoleCursorInfo(hOutput,&info) == 0 )
    {
       cout << endl << "SetConsoleCurInfo failed" << endl;
       DWORD dwError = GetLastError();
       char buf[255];
       FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, dwError,
           0,buf,sizeof(buf),0);
       cout << buf << endl;
    }

    cout << "Press <Enter> when ready";
    cin.ignore();

	return 0;
}

Below is a quick example -- you can get more console functions and a console class here

I compiled and tested this with Dev-C++ compiler on XP os.

#define _WIN32_WINNT 0x0500
#include <Windows.h>
#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    
    CONSOLE_CURSOR_INFO info;
	HANDLE hOutput = GetStdHandle (STD_OUTPUT_HANDLE);

	// turn the cursor off
	info.bVisible = FALSE;
	info.dwSize = 1;
    if( SetConsoleCursorInfo(hOutput,&info) == 0 )
    {
       cout << endl << "SetConsoleCurInfo failed" << endl;
       DWORD dwError = GetLastError();
       char buf[255];
       FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, dwError,
           0,buf,sizeof(buf),0);
       cout << buf << endl;
    }

    cout << "Press <Enter> when ready";
    cin.ignore();

	return 0;
}

thanks a lot!

i appreciate it!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.