Can’t change console application window title with virtual terminal sequences

  ansi, c++, console, title, window

I read this article by Microsoft about using of console virtual terminal sequences.

I followed this sequence to change the window title:

ESC ] 2 ; <string> BEL  

I also tried:

ESC ] 0 ; <string> BEL  

But it doesn’t change the title.

This is my code:

#include <stdio.h>
#include <wchar.h>
#include <windows.h>

int main()
{
    // https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences

    // Set output mode to handle virtual terminal sequences
    HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    if (hOut == INVALID_HANDLE_VALUE)
    {
        return GetLastError();
    }

    DWORD dwMode = 0;
    if (!GetConsoleMode(hOut, &dwMode))
    {
        return GetLastError();
    }

    dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
    if (!SetConsoleMode(hOut, dwMode))
    {
        return GetLastError();
    }

    // Try some Set Graphics Rendition (SGR) terminal escape sequences
    wprintf(L"hello");
    wprintf(L"x1b]2;titelx07");
    return 0;
}

It doesn’t change the console window title.

Source: Windows Questions C++

LEAVE A COMMENT