-1

I am trying to capture a window in win7 without disabling aero and I hear PrintWindow Works.

But I'm not sure how to use it, I found some articles but I can't see any image or bitmap output in any of them

Has anyone ever had experience with this function and knows how to use it?

user779444
  • 1,365
  • 4
  • 21
  • 38

1 Answers1

8

Previous link here.

Code sample from the same link:

Graphics g = form.CreateGraphics();
Bitmap bmp = new Bitmap(form.Size.Width, form.Size.Height, g);
Graphics memoryGraphics = Graphics.FromImage(bmp);
IntPtr dc = memoryGraphics.GetHdc();
bool success = PrintWindow(form.Handle, dc, 0);
memoryGraphics.ReleaseHdc(dc);
// bmp now contains the screenshot

Also as specified in the above link you can use managed Control.DrawToBitamp to achieve the same thing.

Adrian Fâciu
  • 12,414
  • 3
  • 53
  • 68
  • Thanks a lot! Always got black screens. Your answer made me realize, that I had a wrong order. First I saved bmp, afterwards I released DC, although it must be vice versa. – SourceSeeker Apr 03 '22 at 18:03