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();
}