Jump to content
Tuts 4 You

PureBasic Adventures - PW_RENDERFULLCONTENT


Teddy Rogers

Recommended Posts

Teddy Rogers
Posted

This is a repost from the "PureBasic Adventures" blog...

Apparently... Windows 8.1 came with a new flag for PrintWindow called, PW_RENDERFULLCONTENT. This allows PrintWindow to properly capture window content that is displaying DirectX through DWM.

Below are some screenshots taken of Unreal Tournament. The first is how PrintWindow normally captures a window with DirectX content being rendered inside it, notice the window border is missing and there is corrupted graphics on the right. The second screenshot is taken with PW_RENDERFULLCONTENT...blogentry-1.png.75e6f73488877c399885baabf4b11159.png

blogentry-2.png.cf678e04e2676172f36997f950efe008.png

Below is an example using PureBasic code, there isn't much information about PW_RENDERFULLCONTENT and it is currently undocumented on MSDN. I am sure if I had a bit more spare time I could find a more worthy example to show you than the above images. You get the idea though...

UsePNGImageEncoder()

Declare PrintScreen(hWnd)

Prototype.i PrintWindow(hWnd, hdcBlt, nFlags)Global PrintWindow.PrintWindow

If OpenWindow(1, #Null, #Null, #Null, #Null, "Capture Window", #PB_Window_Invisible)
  Repeat
    MyEvent = WaitWindowEvent()
    
    If GetAsyncKeyState_(#VK_SNAPSHOT) & $8000
      PrintScreen(FindWindow_(#Null, "Unreal Tournament"))
    EndIf
    
    If GetAsyncKeyState_(#VK_ESCAPE) & $8000
      MyEvent = #PB_Event_CloseWindow
    EndIf
    
  Until MyEvent = #PB_Event_CloseWindow
EndIf

Procedure PrintScreen(hWnd)
  Protected r.RECT
  
  #PW_RENDERFULLCONTENT = $00000002
  
  If OpenLibrary(User32, "User32.dll")
    PrintWindow = GetFunction(User32, "PrintWindow")
    
    If GetWindowRect_(hWnd, r.RECT)
      If CreateImage(CapImage, r\right-r\left, r\bottom-r\top, 32)
        hdc = StartDrawing(ImageOutput(CapImage))
        
        ; PW_RENDERFULLCONTENT -> new in Windows 8.1, can capture DirectX screens through DWM
        
        Okay = PrintWindow(hWnd, hdc, #PW_RENDERFULLCONTENT)
        StopDrawing()
        
        If Okay
          SaveImage(CapImage, "C:\Users\Teddy\Downloads\" + FormatDate("%yyyy.%mm.%DD-%hh.%ii.%ss", Date()) + ".png", #PB_ImagePlugin_PNG)
          CloseLibrary(User32)
          ProcedureReturn
        EndIf
        
      EndIf
    EndIf
    CloseLibrary(User32)
  EndIf
  
EndProcedure

If you have more information or details on PW_RENDERFULLCONTENT please tell me about it...

Ted.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...