GetClassName function
Applies to: desktop apps only
Retrieves the name of the class to which the specified window belongs.
Syntax
int WINAPI GetClassName( __in HWND hWnd, __out LPTSTR lpClassName, __in int nMaxCount );
Parameters
- hWnd [in]
-
Type: HWND
A handle to the window and, indirectly, the class to which the window belongs.
- lpClassName [out]
-
Type: LPTSTR
The class name string.
- nMaxCount [in]
-
Type: int
The length of the lpClassName buffer, in characters. The buffer must be large enough to include the terminating null character; otherwise, the class name string is truncated to
nMaxCount-1characters.
Return value
Type:
Type: int
If the function succeeds, the return value is the number of characters copied to the buffer, not including the terminating null character.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Requirements
|
Minimum supported client | Windows 2000 Professional |
|---|---|
|
Minimum supported server | Windows 2000 Server |
|
Header |
|
|
Library |
|
|
DLL |
|
|
Unicode and ANSI names | GetClassNameW (Unicode) and GetClassNameA (ANSI) |
See also
- Reference
- FindWindow
- GetClassInfo
- GetClassLong
- GetClassWord
- Conceptual
- Window Classes
Send comments about this topic to Microsoft
Build date: 2/3/2012
- 2/9/2012
- TheRealBekenn
The difference between RealGetWindowClass and GetClassName is that RealGetWindowClass retrieves the name of the base class for superclassed windows. See http://blogs.msdn.com/b/oldnewthing/archive/2010/12/31/10110524.aspx for more information.
- 12/31/2010
- stickboy
Public Declare Auto Function GetClassName Lib "User32.dll" (ByVal hwnd As IntPtr, <Out()> ByVal lpClassName As System.Text.StringBuilder, ByVal nMaxCount As Integer) As Integer
- 6/16/2010
- Đonny
i.e. If the return value is non-zero then it will be the same number that _tcslen(lpClassName) returns if called afterwards.
- 10/20/2009
- Leo Davidson
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int GetClassName(IntPtr hWnd,
StringBuilder lpClassName,
int nMaxCount
);public static string GetWindowClassName(IntPtr hWnd)
{
StringBuilder buffer = new StringBuilder(128);
GetClassName(hWnd, buffer, buffer.Capacity);
return buffer.ToString();
}
- 9/30/2008
- deodorant