Display thumbnails even when Aero is disabled

This commit is contained in:
Anton Kasyanov
2019-04-29 19:51:47 +03:00
parent cfcc5d085c
commit 687520d2eb
18 changed files with 519 additions and 105 deletions

View File

@@ -1,14 +1,19 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using EveOPreview.Services.Interop;
namespace EveOPreview.Services.Implementation
{
class WindowManager : IWindowManager
sealed class WindowManager : IWindowManager
{
#region Private constants
private const int WINDOW_SIZE_THRESHOLD = 300;
#endregion
public WindowManager()
{
this.IsCompositionEnabled = DwmApiNativeMethods.DwmIsCompositionEnabled();
this.IsCompositionEnabled = DwmNativeMethods.DwmIsCompositionEnabled();
}
public bool IsCompositionEnabled { get; }
@@ -63,12 +68,42 @@ namespace EveOPreview.Services.Implementation
return User32NativeMethods.IsIconic(handle);
}
public IDwmThumbnail RegisterThumbnail(IntPtr destination, IntPtr source)
public IDwmThumbnail GetLiveThumbnail(IntPtr destination, IntPtr source)
{
IDwmThumbnail thumbnail = new DwmThumbnail(this);
thumbnail.Register(destination, source);
return thumbnail;
}
public Image GetStaticThumbnail(IntPtr source)
{
var sourceContext = User32NativeMethods.GetDC(source);
User32NativeMethods.GetClientRect(source, out RECT windowRect);
var width = windowRect.Right - windowRect.Left;
var height = windowRect.Bottom - windowRect.Top;
// Check if there is anything to make thumbnail of
if ((width < WINDOW_SIZE_THRESHOLD) || (height < WINDOW_SIZE_THRESHOLD))
{
return null;
}
var destContext = Gdi32NativeMethods.CreateCompatibleDC(sourceContext);
var bitmap = Gdi32NativeMethods.CreateCompatibleBitmap(sourceContext, width, height);
var oldBitmap = Gdi32NativeMethods.SelectObject(destContext, bitmap);
Gdi32NativeMethods.BitBlt(destContext, 0, 0, width, height, sourceContext, 0, 0, Gdi32NativeMethods.SRCCOPY);
Gdi32NativeMethods.SelectObject(destContext, oldBitmap);
Gdi32NativeMethods.DeleteDC(destContext);
User32NativeMethods.ReleaseDC(source, sourceContext);
Image image = Image.FromHbitmap(bitmap);
Gdi32NativeMethods.DeleteObject(bitmap);
return image;
}
}
}