private void Form1_Resize(object sender, EventArgs e) { if (m_hThumbnail != IntPtr.Zero) { DwmApi.DWM_THUMBNAIL_PROPERTIES m_ThumbnailProperties = new DwmApi.DWM_THUMBNAIL_PROPERTIES(); m_ThumbnailProperties.dwFlags = DwmApi.DWM_THUMBNAIL_PROPERTIES.DWM_TNP_VISIBLE + DwmApi.DWM_THUMBNAIL_PROPERTIES.DWM_TNP_OPACITY + DwmApi.DWM_THUMBNAIL_PROPERTIES.DWM_TNP_RECTDESTINATION + DwmApi.DWM_THUMBNAIL_PROPERTIES. DWM_TNP_SOURCECLIENTAREAONLY; m_ThumbnailProperties.opacity = 255; m_ThumbnailProperties.fVisible = true; m_ThumbnailProperties.rcSource = m_ThumbnailProperties.rcDestination = new DwmApi.RECT(0, 0, ClientRectangle.Right, ClientRectangle.Bottom); m_ThumbnailProperties.fSourceClientAreaOnly = true; DwmApi.DwmUpdateThumbnailProperties( m_hThumbnail, m_ThumbnailProperties); ClientSize = new Size(ClientSize.Width, (int)(heightRatio * (double)ClientSize.Width / (double)widthRatio)); } }
/// <summary> /// Get thumbnail size /// </summary> public void GetThumbnailSize(IntPtr thumbnail, out Size size) { DwmApi.DWM_THUMBNAIL_PROPERTIES dskThumbProps = new DwmApi.DWM_THUMBNAIL_PROPERTIES(); dskThumbProps.dwFlags = DwmApi.DWM_THUMBNAIL_FLAGS.DWM_TNP_SOURCECLIENTAREAONLY; dskThumbProps.fSourceClientAreaOnly = true; dskThumbProps.fVisible = false; dskThumbProps.opacity = 255; DwmApi.DwmUpdateThumbnailProperties(thumbnail, ref dskThumbProps); DwmApi.DwmQueryThumbnailSourceSize(thumbnail, out size); }
public void CreateAndShow(IntPtr sourceWindow) { try { m_hThumbnail = DwmApi.DwmRegisterThumbnail( Handle, sourceWindow); DwmApi.DWM_THUMBNAIL_PROPERTIES m_ThumbnailProperties = new DwmApi.DWM_THUMBNAIL_PROPERTIES(); m_ThumbnailProperties.dwFlags = DwmApi.DWM_THUMBNAIL_PROPERTIES.DWM_TNP_VISIBLE + DwmApi.DWM_THUMBNAIL_PROPERTIES.DWM_TNP_OPACITY + DwmApi.DWM_THUMBNAIL_PROPERTIES.DWM_TNP_RECTDESTINATION + DwmApi.DWM_THUMBNAIL_PROPERTIES. DWM_TNP_SOURCECLIENTAREAONLY; m_ThumbnailProperties.opacity = 255; m_ThumbnailProperties.fVisible = true; m_ThumbnailProperties.rcSource = m_ThumbnailProperties.rcDestination = new DwmApi.RECT(0, 0, ClientRectangle.Right, ClientRectangle.Bottom); m_ThumbnailProperties.fSourceClientAreaOnly = true; DwmApi.DwmUpdateThumbnailProperties( m_hThumbnail, m_ThumbnailProperties); Size sz; DwmApi.DwmQueryThumbnailSourceSize(m_hThumbnail, out sz); widthRatio = sz.Width; heightRatio = sz.Height; this.Width = 400; this.Height = 400; Show(); } catch (Exception ex) { // label1.Text = ex.Message; } }
/// <summary> /// Make thumbnail visible /// </summary> public void DrawThumbnail(Rectangle r, IntPtr thumbnail) { Native.RECT dest = new Native.RECT() { left = r.Left, top = r.Top, right = r.Right, bottom = r.Bottom }; DwmApi.DWM_THUMBNAIL_PROPERTIES dskThumbProps = new DwmApi.DWM_THUMBNAIL_PROPERTIES(); dskThumbProps.dwFlags = DwmApi.DWM_THUMBNAIL_FLAGS.DWM_TNP_SOURCECLIENTAREAONLY | DwmApi.DWM_THUMBNAIL_FLAGS.DWM_TNP_VISIBLE | DwmApi.DWM_THUMBNAIL_FLAGS.DWM_TNP_RECTDESTINATION; dskThumbProps.fSourceClientAreaOnly = true; dskThumbProps.fVisible = true; dskThumbProps.opacity = 255; dskThumbProps.rcDestination = dest; DwmApi.DwmUpdateThumbnailProperties(thumbnail, ref dskThumbProps); }
public void CreateAndShow(IntPtr sourceWindow) { try { m_hThumbnail = DwmApi.DwmRegisterThumbnail( Handle, sourceWindow); DwmApi.DWM_THUMBNAIL_PROPERTIES m_ThumbnailProperties = new DwmApi.DWM_THUMBNAIL_PROPERTIES(); m_ThumbnailProperties.dwFlags = DwmApi.DWM_THUMBNAIL_PROPERTIES.DWM_TNP_VISIBLE + DwmApi.DWM_THUMBNAIL_PROPERTIES.DWM_TNP_OPACITY + DwmApi.DWM_THUMBNAIL_PROPERTIES.DWM_TNP_RECTDESTINATION + DwmApi.DWM_THUMBNAIL_PROPERTIES. DWM_TNP_SOURCECLIENTAREAONLY; m_ThumbnailProperties.opacity = 255; m_ThumbnailProperties.fVisible = true; m_ThumbnailProperties.rcSource = m_ThumbnailProperties.rcDestination = new DwmApi.RECT(0, 0, ClientRectangle.Right, ClientRectangle.Bottom); m_ThumbnailProperties.fSourceClientAreaOnly = true; DwmApi.DwmUpdateThumbnailProperties( m_hThumbnail, m_ThumbnailProperties); Size sz; DwmApi.DwmQueryThumbnailSourceSize(m_hThumbnail, out sz); widthRatio = sz.Width; heightRatio = sz.Height; this.Width = 400; this.Height = 400; Show(); } catch (Exception ex) { // label1.Text = ex.Message; } }
private void Form1_Resize(object sender, EventArgs e) { if (m_hThumbnail != IntPtr.Zero) { DwmApi.DWM_THUMBNAIL_PROPERTIES m_ThumbnailProperties = new DwmApi.DWM_THUMBNAIL_PROPERTIES(); m_ThumbnailProperties.dwFlags = DwmApi.DWM_THUMBNAIL_PROPERTIES.DWM_TNP_VISIBLE + DwmApi.DWM_THUMBNAIL_PROPERTIES.DWM_TNP_OPACITY + DwmApi.DWM_THUMBNAIL_PROPERTIES.DWM_TNP_RECTDESTINATION + DwmApi.DWM_THUMBNAIL_PROPERTIES. DWM_TNP_SOURCECLIENTAREAONLY; m_ThumbnailProperties.opacity = 255; m_ThumbnailProperties.fVisible = true; m_ThumbnailProperties.rcSource = m_ThumbnailProperties.rcDestination = new DwmApi.RECT(0, 0, ClientRectangle.Right, ClientRectangle.Bottom); m_ThumbnailProperties.fSourceClientAreaOnly = true; DwmApi.DwmUpdateThumbnailProperties( m_hThumbnail, m_ThumbnailProperties); ClientSize = new Size(ClientSize.Width , (int)(heightRatio * (double)ClientSize.Width / (double)widthRatio)); } }
public void UpdateThumbs(bool isTaskBar = false) { int screenWidth = Options.ScreenWidth; int screenHeight = Options.ScreenHeight; int parallaxDecal = 2 * this.OffsetLevel * Options.ParallaxEffect; bool modeSbS = Options.ModeSbS; double dX = modeSbS ? 2 : 1; double dY = modeSbS ? 1 : 2; int decalX = modeSbS ? screenWidth / 2 : 0; int decalY = modeSbS ? 0 : screenHeight / 2; if (!isTaskBar && !this.SourceRect.IsMaximized() && this.SourceRect.Top < screenHeight - Options.TaskBarHeight) { screenHeight -= Options.TaskBarHeight; } DwmApi.DWM_THUMBNAIL_PROPERTIES props = new DwmApi.DWM_THUMBNAIL_PROPERTIES(); props.fVisible = true; props.dwFlags = DwmApi.DWM_TNP_VISIBLE | DwmApi.DWM_TNP_RECTDESTINATION | DwmApi.DWM_TNP_RECTSOURCE; // Left RECT parallaxSourceRectLeft = new RECT( this.SourceRect.Left + parallaxDecal, this.SourceRect.Top, this.SourceRect.Right + parallaxDecal, this.SourceRect.Bottom); props.rcSource = new RECT { Left = Math.Max(0, -parallaxSourceRectLeft.Left), Top = Math.Max(0, -parallaxSourceRectLeft.Top), Right = Math.Min(screenWidth, parallaxSourceRectLeft.Right) - parallaxSourceRectLeft.Left, Bottom = Math.Min(screenHeight, parallaxSourceRectLeft.Bottom) - parallaxSourceRectLeft.Top }; props.rcDestination = new RECT { Left = 0, Top = 0, Right = (int)Math.Ceiling((props.rcSource.Right - props.rcSource.Left) / dX), Bottom = (int)Math.Ceiling((props.rcSource.Bottom - props.rcSource.Top) / dY) }; User32.SetWindowPos(this.ThumbLeft.Handle, this.Owner?.ThumbLeft.Handle ?? IntPtr.Zero, (int)Math.Floor(Math.Max(0, parallaxSourceRectLeft.Left) / dX), (int)Math.Floor(Math.Max(0, parallaxSourceRectLeft.Top) / dY), props.rcDestination.Right, props.rcDestination.Bottom, SWP.SWP_ASYNCWINDOWPOS); DwmApi.DwmUpdateThumbnailProperties(this.ThumbLeft.Thumb, ref props); // Right RECT parallaxSourceRectRight = new RECT( this.SourceRect.Left - parallaxDecal, this.SourceRect.Top, this.SourceRect.Right - parallaxDecal, this.SourceRect.Bottom); props.rcSource = new RECT { Left = Math.Max(0, -parallaxSourceRectRight.Left), Top = Math.Max(0, -parallaxSourceRectRight.Top), Right = Math.Min(screenWidth, parallaxSourceRectRight.Right) - parallaxSourceRectRight.Left, Bottom = Math.Min(screenHeight, parallaxSourceRectRight.Bottom) - parallaxSourceRectRight.Top }; props.rcDestination = new RECT { Left = 0, Top = 0, Right = (int)Math.Ceiling((props.rcSource.Right - props.rcSource.Left) / dX), Bottom = (int)Math.Ceiling((props.rcSource.Bottom - props.rcSource.Top) / dY) }; User32.SetWindowPos(this.ThumbRight.Handle, this.Owner?.ThumbRight.Handle ?? IntPtr.Zero, decalX + (int)Math.Floor(Math.Max(0, parallaxSourceRectRight.Left) / dX), decalY + (int)Math.Floor(Math.Max(0, parallaxSourceRectRight.Top) / dY), props.rcDestination.Right, props.rcDestination.Bottom, SWP.SWP_ASYNCWINDOWPOS); DwmApi.DwmUpdateThumbnailProperties(this.ThumbRight.Thumb, ref props); if (isTaskBar) { this.ThumbLeft.Background = Brushes.Black; this.ThumbRight.Background = Brushes.Black; } #if DEBUG //if (this.Title.Contains("About")) //{ // DebugWindow.Instance.UpdateMessage($"Source Win {this.SourceRect}{Environment.NewLine}Src Thumb {props.rcSource}{Environment.NewLine}Dst Thumb {props.rcDestination}{Environment.NewLine}Dst Pos Left: {Math.Max(0, this.SourceRect.Left) / 2} Top: {Math.Max(0, this.SourceRect.Top)}"); //} #endif }
public void UpdateThumbs(bool isTaskBar = false) { int x, y, cx, cy; SbSComputedVariables scv = Options.ComputedVariables; int screenBottom = Options.ScreenSrcBounds.Bottom; int parallaxDecal = 2 * this.OffsetLevel * Options.ParallaxEffect; if (!isTaskBar && !this.SourceRect.IsMaximized() && this.SourceRect.Top < Options.ScreenSrcWorkspace.Bottom) { screenBottom = Options.ScreenSrcWorkspace.Bottom; } DwmApi.DWM_THUMBNAIL_PROPERTIES props = new DwmApi.DWM_THUMBNAIL_PROPERTIES(); props.fVisible = true; props.dwFlags = DwmApi.DWM_TNP_VISIBLE | DwmApi.DWM_TNP_RECTDESTINATION | DwmApi.DWM_TNP_RECTSOURCE; // Left RECT parallaxSourceRectLeft = new RECT( this.SourceRect.Left + parallaxDecal, this.SourceRect.Top, this.SourceRect.Right + parallaxDecal, this.SourceRect.Bottom); props.rcSource = new RECT { Left = Math.Max(0, -parallaxSourceRectLeft.Left + Options.AreaSrcBounds.Left), Top = Math.Max(0, -parallaxSourceRectLeft.Top + Options.AreaSrcBounds.Top), Right = Math.Min(Options.AreaSrcBounds.Right, parallaxSourceRectLeft.Right) - parallaxSourceRectLeft.Left, Bottom = Math.Min(screenBottom, parallaxSourceRectLeft.Bottom) - parallaxSourceRectLeft.Top }; props.rcDestination = new RECT { Left = 0, Top = 0, Right = (int)Math.Ceiling((props.rcSource.Right - props.rcSource.Left) / scv.RatioX), Bottom = (int)Math.Ceiling((props.rcSource.Bottom - props.rcSource.Top) / scv.RatioY) }; x = scv.DestPositionX + (int)Math.Floor(Math.Max(0, parallaxSourceRectLeft.Left - Options.AreaSrcBounds.Left) / scv.RatioX); y = scv.DestPositionY + (int)Math.Floor(Math.Max(0, parallaxSourceRectLeft.Top - Options.AreaSrcBounds.Top) / scv.RatioY); cx = props.rcDestination.Right; cy = props.rcDestination.Bottom; User32.SetWindowPos(this.ThumbLeft.Handle, this.Owner?.ThumbLeft.Handle ?? IntPtr.Zero, x, y, cx, cy, SWP.SWP_ASYNCWINDOWPOS); DwmApi.DwmUpdateThumbnailProperties(this.ThumbLeft.Thumb, ref props); // Right RECT parallaxSourceRectRight = new RECT( this.SourceRect.Left - parallaxDecal, this.SourceRect.Top, this.SourceRect.Right - parallaxDecal, this.SourceRect.Bottom); props.rcSource = new RECT { Left = Math.Max(0, -parallaxSourceRectRight.Left + Options.AreaSrcBounds.Left), Top = Math.Max(0, -parallaxSourceRectRight.Top + Options.AreaSrcBounds.Top), Right = Math.Min(Options.AreaSrcBounds.Right, parallaxSourceRectRight.Right) - parallaxSourceRectRight.Left, Bottom = Math.Min(screenBottom, parallaxSourceRectRight.Bottom) - parallaxSourceRectRight.Top }; props.rcDestination = new RECT { Left = 0, Top = 0, Right = (int)Math.Ceiling((props.rcSource.Right - props.rcSource.Left) / scv.RatioX), Bottom = (int)Math.Ceiling((props.rcSource.Bottom - props.rcSource.Top) / scv.RatioY) }; x = scv.DestPositionX + scv.DecalSbSX + (int)Math.Floor(Math.Max(0, parallaxSourceRectRight.Left - Options.AreaSrcBounds.Left) / scv.RatioX); y = scv.DestPositionY + scv.DecalSbSY + (int)Math.Floor(Math.Max(0, parallaxSourceRectRight.Top - Options.AreaSrcBounds.Top) / scv.RatioY); cx = props.rcDestination.Right; cy = props.rcDestination.Bottom; User32.SetWindowPos(this.ThumbRight.Handle, this.Owner?.ThumbRight.Handle ?? IntPtr.Zero, x, y, cx, cy, SWP.SWP_ASYNCWINDOWPOS); DwmApi.DwmUpdateThumbnailProperties(this.ThumbRight.Thumb, ref props); #if DEBUG //if (this.Title.Contains("About")) //{ // App.Current.Dispatcher.Invoke(() => // { // DebugWindow.Instance.UpdateMessage($"Source Win {this.SourceRect}{Environment.NewLine}Src Thumb {props.rcSource}{Environment.NewLine}Dst Thumb {props.rcDestination}{Environment.NewLine}Dst Pos Left: {Math.Max(0, this.SourceRect.Left) / 2} Top: {Math.Max(0, this.SourceRect.Top)}"); // }); //} #endif }