SetConsoleTitle function

Sets the title for the current console window.

Syntax


BOOL WINAPI SetConsoleTitle(
  _In_  LPCTSTR lpConsoleTitle
);

Parameters

lpConsoleTitle [in]

The string to be displayed in the title bar of the console window. The total size must be less than 64K.

Return value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

When the process terminates, the system restores the original console title.

This function uses either Unicode characters or 8-bit characters from the console's current code page. The console's code page defaults initially to the system's OEM code page. To change the console's code page, use the SetConsoleCP or SetConsoleOutputCP functions, or use the chcp or mode con cp select= commands.

Examples

The following example shows how to retrieve and modify the console title.


#include <windows.h>
#include <tchar.h>
#include <conio.h>
#include <strsafe.h>

int main( void )
{
   TCHAR szOldTitle[MAX_PATH];
   TCHAR szNewTitle[MAX_PATH];

   // Save current console title.

   if( GetConsoleTitle(szOldTitle, MAX_PATH) )
   {
      // Build new console title string.

      StringCchPrintf(szNewTitle, MAX_PATH, TEXT("TEST: %s"), szOldTitle);

      // Set console title to new title
      if( !SetConsoleTitle(szNewTitle) )
      {
         _tprintf(TEXT("SetConsoleTitle failed (%d)\n"), GetLastError());
         return 1;
      }
      else
      {
         _tprintf(TEXT("SetConsoleTitle succeeded.\n"));
      }
   }
   return 0;
}


Requirements

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Wincon.h (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

Unicode and ANSI names

SetConsoleTitleW (Unicode) and SetConsoleTitleA (ANSI)

See also

Console Functions
GetConsoleOriginalTitle
GetConsoleTitle
SetConsoleCP
SetConsoleOutputCP

 

 

Community Additions

ADD
Show:
© 2014 Microsoft