title | description | author | ms.author | ms.topic | keywords | f1_keywords | MS-HAID | MSHAttr | ms.assetid | topic_type | api_name | api_location | api_type | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
SetConsoleTitle function |
See reference information about the SetConsoleTitle function, which sets the title for the current console window. |
miniksa |
miniksa |
article |
console, character mode applications, command line applications, terminal applications, console api |
|
|
|
f1db449b-0dd0-4d61-bb79-b7da9a5168f4 |
|
|
|
|
[!INCLUDE not-recommended-banner]
Sets the title for the current console window.
BOOL WINAPI SetConsoleTitle(
_In_ LPCTSTR lpConsoleTitle
);
lpConsoleTitle [in]
The string to be displayed in the title bar of the console window. The total size must be less than 64K.
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.
When the process terminates, the system restores the original console title.
[!INCLUDE setting-codepage-mode-remarks]
Tip
This API has a virtual terminal equivalent in the window title sequences. Virtual terminal sequences are recommended for all new and ongoing development.
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;
}
Minimum supported client | Windows 2000 Professional [desktop apps only] |
Minimum supported server | Windows 2000 Server [desktop apps only] |
Header | ConsoleApi2.h (via WinCon.h, include Windows.h) |
Library | Kernel32.lib |
DLL | Kernel32.dll |
Unicode and ANSI names | SetConsoleTitleW (Unicode) and SetConsoleTitleA (ANSI) |