public void UnregisterThumbnail() { if (_thumbnailHandle != IntPtr.Zero) { DwmApi.DwmUnregisterThumbnail(_thumbnailHandle); } }
public void RegisterThumbnail(IntPtr baseWindow, ref System.Windows.Controls.Image image, Point location, Size size) { if (_thumbnailHandle != IntPtr.Zero) { DwmApi.DwmUnregisterThumbnail(_thumbnailHandle); } DwmApi.DwmRegisterThumbnail(baseWindow, _windowHandle, out _thumbnailHandle); if (_thumbnailHandle == IntPtr.Zero) { return; } var thumbnailProperties = new DwmApi.ThumbnailProperties { dwFlags = DwmApi.ThumbnailProperties.DWM_TNP_VISIBLE + DwmApi.ThumbnailProperties.DWM_TNP_OPACITY + DwmApi.ThumbnailProperties.DWM_TNP_RECTDESTINATION, opacity = 255, fVisible = true, rcDestination = new WUser32.Rectangle { Left = (int)location.X, Top = (int)location.Y, Right = (int)size.Width, Bottom = (int)size.Height } }; DwmApi.DwmUpdateThumbnailProperties(_thumbnailHandle, ref thumbnailProperties); }
/// <summary> /// Uses DwmApi to render the entire window in Aero glass /// </summary> void InitializeGlass() { var bb = new DwmApi.DwmBlurbehind { dwFlags = (int)DwmApi.DwmBlurBehindDwFlags.DwmBbEnable, fEnable = true }; Background = Brushes.Transparent; ResizeMode = ResizeMode.NoResize; WindowStyle = WindowStyle.None; var hwnd = new WindowInteropHelper(this).Handle; var hwndSource = HwndSource.FromHwnd(hwnd); if (hwndSource != null) { if (hwndSource.CompositionTarget != null) { hwndSource.CompositionTarget.BackgroundColor = Colors.Transparent; } } DwmApi.DwmEnableBlurBehindWindow(hwnd, ref bb); var dwmncrpDisabled = 2; DwmApi.DwmSetWindowAttribute(hwnd, DwmApi.DwmWindowAttribute.DWMWA_NCRENDERING_POLICY, ref dwmncrpDisabled, sizeof(int)); Topmost = true; Focus(); }
/// <summary> /// Glass is enabled in when the souce window is initialized /// </summary> /// <param name="e"></param> protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); var canRenderInGlass = false; DwmApi.DwmIsCompositionEnabled(ref canRenderInGlass); if (canRenderInGlass) { InitializeGlass(); } }