/// <summary> /// In some circumstances, the window manager will draw the window larger than it reports /// its size to be. You can use this function to retrieve the size of this extra border /// padding. /// </summary> /// <param name="window"></param> /// <returns> /// An integer greater than or equal to zero that describes the size of the border padding /// which is not reported via the window's Size or Bounds property. /// </returns> /// <remarks> /// Note to implementors: This method may simply return 0. It is provided for use in Windows /// Vista when DWM+Aero is enabled in which case sizable FloatingToolForm windows do not /// visibly dock to the correct locations. /// </remarks> public static int GetExtendedFrameBounds(Form window) { int returnVal; if (OS.IsVistaOrLater) { unsafe { int *rcVal = stackalloc int[4]; int hr = SafeNativeMethods.DwmGetWindowAttribute( window.Handle, NativeConstants.DWMWA_EXTENDED_FRAME_BOUNDS, (void *)rcVal, 4 * (uint)sizeof(int)); if (hr >= 0) { returnVal = -rcVal[0]; } else { returnVal = 0; } } } else { returnVal = 0; } GC.KeepAlive(window); return(Math.Max(0, returnVal)); }