GetClassLongPtr() public static method

The GetClassLongPtr function retrieves the specified value from the WNDCLASSEX structure associated with the specified window. If you are retrieving a pointer or a handle, this function supersedes the GetClassLong function. (Pointers and handles are 32 bits on 32-bit Microsoft Windows and 64 bits on 64-bit Windows.) To write code that is compatible with both 32-bit and 64-bit versions of Windows, use GetClassLongPtr.
public static GetClassLongPtr ( IntPtr hWnd, int nIndex ) : IntPtr
hWnd System.IntPtr Handle to the window and, indirectly, the class to which the window belongs.
nIndex int Specifies the value to retrieve. To retrieve a value from the extra class memory, specify the positive, zero-based byte offset of the value to be retrieved. Valid values are in the range zero through the number of bytes of extra class memory, minus eight; for example, if you specified 24 or more bytes of extra class memory, a value of 16 would be an index to the third integer. To retrieve any other value from the WNDCLASSEX structure, specify one of the following values.
return System.IntPtr
        static ImageSource GetDefaultIcon(IntPtr hwnd)
        {
            if (hwnd != IntPtr.Zero)
            {
                try
                {
                    var zero = NativeMethods.SendMessage(hwnd, 0x7f, new IntPtr(2), IntPtr.Zero);

                    if (zero == IntPtr.Zero)
                    {
                        zero = NativeMethods.GetClassLongPtr(hwnd, -34);
                    }

                    if (zero == IntPtr.Zero)
                    {
                        zero = NativeMethods.LoadImage(IntPtr.Zero, new IntPtr(0x7f00), 1, (int)SystemParameters.SmallIconWidth, (int)SystemParameters.SmallIconHeight, 0x8000);
                    }

                    if (zero != IntPtr.Zero)
                    {
                        return(BitmapFrame.Create(Imaging.CreateBitmapSourceFromHIcon(zero, Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight((int)SystemParameters.SmallIconWidth, (int)SystemParameters.SmallIconHeight))));
                    }
                }
                catch
                {
                    return(null);
                }
            }

            return(null);
        }