2

I'm developing an application that has to take screenshots of a fullscreen game. The problem is that I've tried many methods but any of them are able to take the screenshot when the game is in fullscreen mode, it will just take a screenshot of what is under the game and a black rectangle on the top left corner.

Is there any alternative to achieve this goal that doesn't involve hooking? As I'm using C#, which is kind of a bad language to make this kind of things.

This is my code right now:

        Bitmap bmp = null;
        SIZE size;

        size.cx = Screen.PrimaryScreen.Bounds.Width;
        size.cy = Screen.PrimaryScreen.Bounds.Height;

        IntPtr Src = PlatformInvokeUSER32.GetDC(IntPtr.Zero);
        IntPtr Dest = PlatformInvokeGDI32.CreateCompatibleDC(Src);
        IntPtr HBitmap = (IntPtr)null;
        IntPtr hOld = IntPtr.Zero;

        HBitmap = PlatformInvokeGDI32.CreateCompatibleBitmap(Src, size.cx, size.cy);

        hOld = (IntPtr)PlatformInvokeGDI32.SelectObject(Dest, HBitmap);

        PlatformInvokeGDI32.BitBlt(Dest, 0, 0, size.cx, size.cy, Src, 0, 0, (PlatformInvokeGDI32.SRCCOPY|PlatformInvokeGDI32.CAPTUREBLT));

        bmp = System.Drawing.Image.FromHbitmap(HBitmap);

        PlatformInvokeGDI32.DeleteDC(Dest);
        PlatformInvokeUSER32.ReleaseDC(IntPtr.Zero.GetDesktopWindow(), Src);
        PlatformInvokeGDI32.DeleteObject(HBitmap);

This works properly on XP, but when it comes to Vista / 7, I need to disable Aero for this code to work, either it will just take a screenshot of what it's under the game as I said before.

Ivan
  • 1,801
  • 2
  • 23
  • 40
  • possible duplicate of [Take screenshot of DirectX full-screen application](http://stackoverflow.com/questions/1962142/take-screenshot-of-directx-full-screen-application) – Hans Passant Mar 09 '11 at 20:20
  • If you disable DWM(Which you can do with code) Then everything will work. – Kelly Elton Nov 20 '11 at 22:02

0 Answers0