/// <summary>Registers a thumbnail to be drawn on a window.</summary> /// <remarks>The thumbnail will not be drawn until you update the thumbnail's properties calling Update().</remarks> /// <param name="destination">The handle (HWND) of the window on which the thumbnail will be drawn.</param> /// <param name="source">The handle (HWND) of the window that has to be drawn.</param> /// <returns>A Thumbnail instance, needed to unregister and to update properties.</returns> public static Thumbnail Register(IntPtr destination, IntPtr source) { if (!OsSupport.IsVistaOrBetter) throw new DwmCompositionException(Resources.ExceptionMessages.DWMOsNotSupported); if (!OsSupport.IsCompositionEnabled) throw new DwmCompositionException(Resources.ExceptionMessages.DWMNotEnabled); if (destination == source) throw new DwmCompositionException(Resources.ExceptionMessages.DWMWindowMatch); Thumbnail ret = new Thumbnail(); if (NativeMethods.DwmRegisterThumbnail(destination, source, out ret) == 0) { return ret; } else { throw new DwmCompositionException(String.Format(Resources.ExceptionMessages.NativeCallFailure, "DwmRegisterThumbnail")); } }
public static extern int DwmQueryThumbnailSourceSize(Thumbnail hThumbnail, out DwmSize pSize);
public static extern int DwmUpdateThumbnailProperties(Thumbnail hThumbnailId, ref DwmThumbnailProperties ptnProperties);
public static extern int DwmRegisterThumbnail(IntPtr hwndDestination, IntPtr hwndSource, out Thumbnail phThumbnailId);
private void RecomputeParentForm() { //Get the owning form Form nextParent = this.TopLevelControl as Form; if (nextParent == null) { //No owning form found (!) _topLevelForm = null; if (_thumbnail != null) { _thumbnail.Dispose(); _thumbnail = null; } return; } if (_thumbnail != null && _topLevelForm != nextParent) { //Parent changed from last time _thumbnail.Dispose(); _thumbnail = null; } _topLevelForm = nextParent; }
void originForm_FormClosed(object sender, FormClosedEventArgs e) { if (_thumbnail != null) { _thumbnail.Dispose(); _thumbnail = null; } }
public void SetThumbnail(IntPtr originHandle) { RecomputeParentForm(); if (_topLevelForm != null) { _thumbnail = DwmManager.Register(_topLevelForm, originHandle); UpdateThumbnail(Visible); } else throw new Exception("Control must have an owner."); }
public static void Unregister(Thumbnail handle) { if (handle != null) { handle.Close(); } }