I am trying to recreate the Flip3D feature from Windows Vista (pictured below), but now I need to get the DWM thumbnails from each program. I already have each program's process handle, but now I need to grab their thumbnails and convert them into a BitmapImage so I can use them as Image sources.
I did some digging, and found this thread that helped a little, but it uses "WindowInfo" to grab the thumbnail, which doesn't exist. I need to use the process handle. If anyone could help that would be nice.
[DllImport("dwmapi.dll", PreserveSig = false)]
private static extern bool DwmIsCompositionEnabled();
[DllImport("dwmapi.dll")]
private static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMargins);
[StructLayout(LayoutKind.Sequential)]
struct MARGINS
{
public int Left;
public int Right;
public int Top;
public int Bottom;
public void ExtendToWholeClientArea()
{
this.Left = -1;
this.Right = -1;
this.Top = -1;
this.Bottom = -1;
}
}
[DllImport("dwmapi.dll")]
private static extern int DwmRegisterThumbnail(IntPtr dest, IntPtr src, out IntPtr thumb);
[DllImport("dwmapi.dll")]
private static extern int DwmUnregisterThumbnail(IntPtr thumb);
[DllImport("dwmapi.dll")]
private static extern int DwmQueryThumbnailSourceSize(IntPtr thumb, out PSIZE size);
[StructLayout(LayoutKind.Sequential)]
private struct PSIZE
{
public int x;
public int y;
}
[DllImport("dwmapi.dll")]
private static extern int DwmUpdateThumbnailProperties(IntPtr hThumb, ref DWM_THUMBNAIL_PROPERTIES props);
[StructLayout(LayoutKind.Sequential)]
private struct DWM_THUMBNAIL_PROPERTIES
{
public int dwFlags;
public RECT rcDestination;
public RECT rcSource;
public byte opacity;
public bool fVisible;
public bool fSourceClientAreaOnly;
}
[StructLayout(LayoutKind.Sequential)]
private struct RECT
{
public RECT(int left, int top, int right, int bottom)
{
Left = left;
Top = top;
Right = right;
Bottom = bottom;
}
public int Left;
public int Top;
public int Right;
public int Bottom;
}
private static readonly int DWM_TNP_VISIBLE = 0x8;
private static readonly int DWM_TNP_RECTDESTINATION = 0x1;
private static readonly int DWM_TNP_SOURCECLIENTAREAONLY = 0x00000010;