Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

GetFileTitle function

Retrieves the name of the specified file.


short WINAPI GetFileTitle(
  _In_  LPCTSTR lpszFile,
  _Out_ LPTSTR  lpszTitle,
  _In_  WORD    cchSize


lpszFile [in]


The name and location of a file.

lpszTitle [out]


The buffer that receives the name of the file.

cchSize [in]

Type: WORD

The length, in characters, of the buffer pointed to by the lpszTitle parameter.

Return value

Type: short

If the function succeeds, the return value is zero.

If the file name is invalid, the return value is unknown. If there is an error, the return value is a negative number.

If the buffer pointed to by the lpszTitle parameter is too small, the return value is a positive integer that specifies the required buffer size, in characters. The required buffer size includes the terminating null character.


GetFileTitle should only be called with legal file names; using an illegal file name has an undefined result.

To get the buffer size needed for the name of a file, call the function with lpszTitle set to NULL and cchSize set to zero. The function returns the required size.

GetFileTitle returns the string that the system would use to display the file name to the user. The display name includes an extension only if that is the user's preference for displaying file names. This means that the returned string may not accurately identify the file if it is used in calls to file system functions.

If the lpszTitle buffer is too small, GetFileTitle returns the size required to hold the display name. However, there is no guaranteed relationship between the required size and the characters originally specified in the lpszFile buffer. For example, do not call GetFileTitle with lpszTitle set to NULL and cchSize set to zero, and then try to use the return value as an index into the lpszFile string. You can usually achieve similar results (and superior performance) with C run-time library functions such as strrchr, wcsrchr, and _mbsrchr.


Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]


Commdlg.h (include Windows.h)





Unicode and ANSI names

GetFileTitleW (Unicode) and GetFileTitleA (ANSI)

See also

Common Dialog Box Library



Community Additions

© 2015 Microsoft