PrintWindow api works well, I use it to capture thumbnails for hidden windows. Despite the name, it differs from WM_PRINT and WM_PRINTCLIENT, it works with almost all windows except Direct X / WPF windows.
I added the code (C #), but after watching how I used the code, I realized that the window is not really hidden, when I capture its bitmap, it just turned off, so this may not work for your case. Could you show the window from the screen, do a print and then hide it again?
public static Bitmap PrintWindow(IntPtr hwnd) { RECT rc; WinUserApi.GetWindowRect(hwnd, out rc); Bitmap bmp = new Bitmap(rc.Width, rc.Height, PixelFormat.Format32bppArgb); Graphics gfxBmp = Graphics.FromImage(bmp); IntPtr hdcBitmap = gfxBmp.GetHdc(); bool succeeded = WinUserApi.PrintWindow(hwnd, hdcBitmap, 0); gfxBmp.ReleaseHdc(hdcBitmap); if (!succeeded) { gfxBmp.FillRectangle(new SolidBrush(Color.Gray), new Rectangle(Point.Empty, bmp.Size)); } IntPtr hRgn = WinGdiApi.CreateRectRgn(0, 0, 0, 0); WinUserApi.GetWindowRgn(hwnd, hRgn); Region region = Region.FromHrgn(hRgn); if (!region.IsEmpty(gfxBmp)) { gfxBmp.ExcludeClip(region); gfxBmp.Clear(Color.Transparent); } gfxBmp.Dispose(); return bmp; }
Maurice Flanagan
source share