PrintWindow in .Net-applications in non-active desktop
I'm trying to make a window screenshot from a non-active desktop (created with CreateDesktop). I use the following code:
public partial class Form1 : Form
[DllImport("User32.dll", SetLastError = true)]
static extern bool PrintWindow(IntPtr hwnd, IntPtr hDC, uint nFlags);
timer1.Interval = 3000;
timer1.Tick += new System.EventHandler(TimerProc);
private void TimerProc(object sender, EventArgs e)
private void UsePrintWindow()
Graphics g = CreateGraphics();
Bitmap bmp = new Bitmap(Size.Width, Size.Height, g);
Graphics memoryGraphics = Graphics.FromImage(bmp);
IntPtr dc = memoryGraphics.GetHdc();
bool success = PrintWindow(Handle, dc, 0);
If I executed this code in non-active desktop on Win7 I receive the following picture:
If I executed this code in non-active desktop on Win2003 I receive the following picture:
Can anybody please advise how to fix it?
P.S. I created MFC-application with the same functionality.
It works fine on Win7 and Win2003.