windowscarettext-cursor

change carret's shape on windows terminal


I want to set the text cursor (caret) of my console app from BLOCK (the default) to _ or |.

I Remove blinking underscore on console / cmd prompt - but it does not mention how to modify the cursor. Documentation on https://learn.microsoft.com/en-us/windows/console/setconsolecursorinfo?redirectedfrom=MSDN is not directly trivial to me.


Solution

  • As recommended by Raymond Chen (for those who don't know who he is: https://devblogs.microsoft.com/oldnewthing/)

    This is what I used for block cursor:

            HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
    
            CONSOLE_CURSOR_INFO cursorInfo;
    
            GetConsoleCursorInfo(out, &cursorInfo);
            cursorInfo.bVisible = true;
            cursorInfo.dwSize = 100;
            SetConsoleCursorInfo(out, &cursorInfo);
    

    And for underscore cursor:

            HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
    
            CONSOLE_CURSOR_INFO cursorInfo;
    
            GetConsoleCursorInfo(out, &cursorInfo);
            cursorInfo.bVisible = true;
            cursorInfo.dwSize = 10;
            SetConsoleCursorInfo(out, &cursorInfo);