/// <summary> /// Get the region for a window /// </summary> /// <param name="interopWindow">InteropWindow</param> public static Region GetRegion(this IInteropWindow interopWindow) { using (var region = Gdi32Api.CreateRectRgn(0, 0, 0, 0)) { if (region.IsInvalid) { return(null); } var result = User32Api.GetWindowRgn(interopWindow.Handle, region); if (result != RegionResults.Error && result != RegionResults.NullRegion) { return(Region.FromHrgn(region.DangerousGetHandle())); } } return(null); }
/// <summary> /// Directly call Gdi32.CreateRectRgn /// </summary> /// <param name="left"></param> /// <param name="top"></param> /// <param name="right"></param> /// <param name="bottom"></param> /// <returns>SafeRegionHandle</returns> public static SafeRegionHandle CreateRectRgn(int left, int top, int right, int bottom) { return(Gdi32Api.CreateRectRgn(left, top, right, bottom)); }