0

My goal is to be able to capture the full area of the screen while another application is in full-screen mode. For example, I ran osu! in full-screen, used my screen-capture application (with keyboard shortcuts) and it came up blank. I've also tested this with CSGO.

I've done a lot of research but can't find what I'm specifically looking for.

The first thing I tried was this (my own idea):

Dim area As Rectangle = Screen.GetBounds(New Point(0, 0)) ' get screen size
Dim bmp As Bitmap = New Bitmap(area.Width, area.Height, Imaging.PixelFormat.Format24bppRgb) ' setup new image from the screen
Dim graphic As Graphics = Graphics.FromImage(bmp) ' store in a graphic
graphic.CopyFromScreen(area.X, area.Y, 0, 0, area.Size, CopyPixelOperation.SourceCopy) ' convert to something useful
Return bmp

However this was the code returning blank images. It works perfectly when taking pictures of windowed applications.

I then took a look at an article on SO (linked at bottom) and am using this. Note, I converted it to VB.NET myself.

<DllImport("User32.dll", SetLastError:=True)> _
    Private Shared Function PrintWindow(ByVal hwnd As IntPtr, ByVal hdc As IntPtr, ByVal nFlags As UInteger) As <MarshalAs(UnmanagedType.Bool)> Boolean
    End Function

<DllImport("user32.dll")> _
    Private Shared Function GetWindowRect(ByVal handle As IntPtr, ByRef rect As Rectangle) As Boolean
    End Function

<DllImport("user32.dll", EntryPoint:="GetDesktopWindow")> _
    Private Shared Function GetDesktopWindow() As IntPtr
    End Function

<DllImport("user32.dll", CharSet:=CharSet.Unicode)> _
    Private Shared Function FindWindowEx(ByVal parentHandle As IntPtr, ByVal childAfter As IntPtr, ByVal lclassName As String, ByVal windowTitle As String) As IntPtr
    End Function

Dim intptrDesktop As IntPtr = FindWindowEx(GetDesktopWindow(), IntPtr.Zero, "Progman", "Program Manager")
Dim area As New Rectangle()
GetWindowRect(intptrDesktop, area)
Dim bmp As Bitmap = New Bitmap(area.Width, area.Height, Imaging.PixelFormat.Format24bppRgb) ' to avoid color issues
Dim graMem As Graphics = Graphics.FromImage(bmp)
Dim dc As IntPtr = graMem.GetHdc()
PrintWindow(intptrDesktop, dc, 0)
graMem.ReleaseHdc(dc) 
Return bmp

This works for capturing the desktop only, but I wonder if I could possibly use this for fullscreen capture by grabbing it's HWND?

I'm trying to find the simplest way of doing it. How should I go about it?

References

Get a screenshot of desktop in full screen 3D-application

Community
  • 1
  • 1
Astrify
  • 51
  • 8
  • 1
    There is no simple way to capture the screen of a full-screen DirectX app. Such a feature invariable dies at the [kind of required code](http://stackoverflow.com/questions/1962142/take-screenshot-of-directx-full-screen-application). Buy, don't build. – Hans Passant Aug 28 '16 at 17:25
  • @HansPassant so I assume services like puush use this? – Astrify Aug 28 '16 at 17:26

0 Answers0