Permalink
Fetching contributors…
Cannot retrieve contributors at this time
178 lines (140 sloc) 3.96 KB
title description author ms.author ms.topic ms.prod keywords MS-HAID MSHAttr ms.assetid topic_type api_name api_location api_type
SetConsoleTitle function
Sets the title for the current console window.
bitcrazed
richturn
article
console
console, character mode applications, command line applications, terminal applications, console api
\_win32\_setconsoletitle
base.setconsoletitle
consoles.setconsoletitle
PreferredSiteName:MSDN
PreferredLib:/library/windows/desktop
f1db449b-0dd0-4d61-bb79-b7da9a5168f4
apiref
SetConsoleTitle
SetConsoleTitleA
SetConsoleTitleW
Kernel32.dll
API-MS-Win-Core-Kernel32-Legacy-l1-1-0.dll
kernel32legacy.dll
API-MS-Win-Core-Kernel32-Legacy-l1-1-1.dll
API-MS-Win-Core-Kernel32-Legacy-l1-1-2.dll
API-MS-Win-DownLevel-Kernel32-l2-1-0.dll
API-MS-Win-Core-Console-l2-1-0.dll
KernelBase.dll
API-MS-Win-DownLevel-Kernel32-l1-1-0.dll
API-MS-Win-Core-Kernel32-Legacy-L1-1-3.dll
API-MS-Win-Core-Kernel32-Legacy-L1-1-4.dll
API-MS-Win-Core-Kernel32-Legacy-L1-1-5.dll
DllExport

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