This topic has not yet been rated - Rate this topic

GetConsoleTitle function

Applies to: desktop apps only

Retrieves the title for the current console window.

Syntax

DWORD WINAPI GetConsoleTitle(
  __out  LPTSTR lpConsoleTitle,
  __in   DWORD nSize
);

Parameters

lpConsoleTitle [out]

A pointer to a buffer that receives a null-terminated string containing the title. If the buffer is too small to store the title, the function stores as many characters of the title as will fit in the buffer, ending with a null terminator.

The storage for this buffer is allocated from a shared heap for the process that is 64 KB in size. The maximum size of the buffer will depend on heap usage.

nSize [in]

The size of the buffer pointed to by the lpConsoleTitle parameter, in characters.

Return value

If the function succeeds, the return value is the length of the console window's title, in characters.

If the function fails, the return value is zero and GetLastError returns the error code.

Remarks

To set the title for a console window, use the SetConsoleTitle function. To retrieve the original title string, use the GetConsoleOriginalTitle function.

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

For an example, see SetConsoleTitle.

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Wincon.h (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

Unicode and ANSI names

GetConsoleTitleW (Unicode) and GetConsoleTitleA (ANSI)

See also

Console Functions
GetConsoleOriginalTitle
SetConsoleCP
SetConsoleOutputCP
SetConsoleTitle

 

 

Send comments about this topic to Microsoft

Build date: 2/3/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Please keep your eyes on me for a while!
I am a .NET developer and now I want to learn some Win32API calls to use in .NET interop and native dynamic link libraries constructing..... but
I have some problems.....

I want to know how what is LPTSTR LPSTR and PSTR
What is DWORD, WORD, char* HWND and char
What is __in and what is __out

I know (int, double, float, uint, long, unsigned long and so on but)

I have some common knowledge of (ref, pointer and out but)
I could not call to GetConsoleTitle function.
This is my code.
#include <windows.h>
#include <wincon.h>
#include <winbase.h>

using namespace std;
LPTSTR s;
int main(void)
{
DWORD result = GetConsoleTitle(&s,1000);
}
What is wrong?
Can some body help me to solve my problem..... thanks for advanced.....
C# syntax
[DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]
internal static extern int GetConsoleTitle(StringBuilder sb, int capacity);
vb.net syntax
<DllImport("kernel32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Public Shared Function GetConsoleTitle(ByVal sb As StringBuilder, ByVal capacity As Integer) As Integer End Function