Binarysharp.MemoryManagement.Windows.WindowCore.GetClassName C# (CSharp) Method

GetClassName() public static method

Retrieves the name of the class to which the specified window belongs.
public static GetClassName ( IntPtr windowHandle ) : string
windowHandle System.IntPtr A handle to the window and, indirectly, the class to which the window belongs.
return string
        public static string GetClassName(IntPtr windowHandle)
        {
            // Check if the handle is valid
            HandleManipulator.ValidateAsArgument(windowHandle, "windowHandle");

            // Get the window class name
            var stringBuilder = new StringBuilder(char.MaxValue);
            if (NativeMethods.GetClassName(windowHandle, stringBuilder, stringBuilder.Capacity) == 0)
                throw new Win32Exception("Couldn't get the class name of the window or the window has no class name.");

            return stringBuilder.ToString();
        }

Usage Example

Example #1
0
 /// <summary>
 /// Gets all the windows that have the specified class name.
 /// </summary>
 /// <param name="className">The class name string.</param>
 /// <returns>A collection of <see cref="RemoteWindow"/>.</returns>
 public IEnumerable <RemoteWindow> GetWindowsByClassName(string className)
 {
     return(WindowHandles
            .Where(handle => WindowCore.GetClassName(handle) == className)
            .Select(handle => new RemoteWindow(_memorySharp, handle)));
 }