Screenshot of a full-screen game?

Just starting out? Need help? Post your questions and find answers here.
registrymechanic22
Enthusiast
Enthusiast
Posts: 176
Joined: Sun Jun 28, 2009 7:07 pm
Location: RUS

Screenshot of a full-screen game?

Post by registrymechanic22 »

Hello
Help please, I can not understand how to do it ....:
How to make a screenshot of a full-screen game (DirectX) on Windows7_x64?

PS: "dm.DEVMODE : CreateDC_ (" DISPLAY "," "," ", dm)" - does not work, make a screenshot under the game (desktop + not full-screen window)
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Screenshot of a full-screen game?

Post by idle »

this should work

Code: Select all

UsePNGImageEncoder()
UseJPEGImageEncoder()
#CAPTUREBLT = $40000000 

Procedure Cap()
  
  Protected width,height,depth,himage,Desthdc,srcDc,bret,sdef.s
  Static scount,ftype.s,fname.s,dfpath.s,gp  
  
  ExamineDesktops()
  
  width = DesktopWidth(0) 
  height = DesktopHeight(0) 
  depth = DesktopDepth(0) 
  himage = CreateImage(#PB_Any,width,height,depth) 

  SrcDc = GetDC_(0)
  DestDc = StartDrawing(ImageOutput(hImage))

  If dfpath = "" 
    dfpath = "C:\" 
  EndIf 
  If ftype = "" 
    ftype = ".bmp"
  EndIf 
  If gp = 0 
    gp=0
  EndIf 

  If SrcDc And DestDc     
  
  bret = BitBlt_(DestDc,0,0,Width,Height,SrcDc,0,0,#SRCCOPY | #CAPTUREBLT)
  StopDrawing()
  If bret 
    sdef = dfpath + "ScreenCap_" + Str(scount) + ftype
    fname = SaveFileRequester("Save Image",sdef,"*.bmp | *.jpg | *.png",gp)
    If fname 
      
      dfpath = GetPathPart(fname)
      scount + 1 
      pos1 = FindString(fname,"bmp",1)
      pos2 = FindString(fname,"jpg",1)
      pos3 = FindString(fname,"png",1)
      If pos1 
        ftype = ".bmp"
        gp=0
        SaveImage(himage,fname,#PB_ImagePlugin_BMP)
      ElseIf pos2 
        ftype = ".jpg"
        gp=1
        SaveImage(himage,fname,#PB_ImagePlugin_JPEG)
      ElseIf pos3 
        ftype = ".png"
        gp=2
        SaveImage(himage,fname,#PB_ImagePlugin_PNG)
      EndIf
    EndIf 
  EndIf   
EndIf   

EndProcedure 

Delay(10000) 
cap()
registrymechanic22
Enthusiast
Enthusiast
Posts: 176
Joined: Sun Jun 28, 2009 7:07 pm
Location: RUS

Re: Screenshot of a full-screen game?

Post by registrymechanic22 »

idle wrote:.
on Windows7_x64 not working....
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Screenshot of a full-screen game?

Post by netmaestro »

If that isn't working, you could try:

Code: Select all

SrcDc = GetDC_( ScreenID() )
and be sure to release it, I didn't see that in the snippet.

Assuming of course, that it's your game code. If not, this won't apply.
BERESHEIT
registrymechanic22
Enthusiast
Enthusiast
Posts: 176
Joined: Sun Jun 28, 2009 7:07 pm
Location: RUS

Re: Screenshot of a full-screen game?

Post by registrymechanic22 »

netmaestro wrote:If that isn't working, you could try:

Code: Select all

SrcDc = GetDC_( ScreenID() )
and be sure to release it, I didn't see that in the snippet.
Assuming of course, that it's your game code. If not, this won't apply.
Games are not mine (Sniper Ghost Warrior, counter-strike source .....). The principle of need by type - TeamViewer or Fraps
for example, try to take a screenshot of this game:

Code: Select all

#B_Num=200 
#B_Size=32 
Procedure.f Dist(X1.f,Y1.f,X2.f,Y2.f);Определяет расстояние между двумя точками! 
  ProcedureReturn Sqr(Pow(X1-X2,2)+Pow(Y1-Y2,2)) 
EndProcedure 
Structure fpoint : X.f : Y.f : EndStructure 
Structure Ball : Pos.fpoint : LastPos.fpoint : Velocity.fpoint : E.f : Weight.f : KEnergy.f : EndStructure 
Dim Ball.ball(#B_Num) 
For C=0 To #B_Num 
  Ball(C)\Pos\X=500+Random(1024)/2 :   Ball(C)\Pos\Y=300+Random(768)/2 
  Ball(C)\E=0.9+Random(100)/1000 : Ball(C)\Weight=1;+Random(5) 
Next 
Ball(0)\Pos\X=#B_Size : Ball(0)\Pos\X=#B_Size 
If InitMouse() = 0 Or InitSprite() = 0 Or InitKeyboard()=0 Or InitSound()=0; Or InitSprite3D() = 0 
  MessageRequester("Fatal Error", "DirectX error!", 0) 
  End 
EndIf 
If OpenScreen(1280, 1024, 32, "") = 0 : MessageRequester("Fatal Error", "Can't open screen!!!",0) : End : EndIf 
CreateSprite(1,#B_Size,#B_Size) : StartDrawing(SpriteOutput(1)) : For C=#B_Size To 1 Step -2 
Circle(#B_Size/2,#B_Size/2,C/2,RGB(0,255-C*196/#B_Size,0)) : Next : StopDrawing() 
Repeat 
  FlipBuffers() : ClearScreen(0) : ExamineKeyboard() : ExamineMouse() 
  Ball(0)\Velocity\X+MouseDeltaX()/10 : Ball(0)\Velocity\Y+MouseDeltaY()/10 : Energy.f=0 
  For C=0 To #B_Num 
    Ball(C)\LastPos\X=Ball(C)\Pos\X : Ball(C)\LastPos\Y=Ball(C)\Pos\Y 
    Ball(C)\Pos\X+Ball(C)\Velocity\X : Ball(C)\Pos\Y+Ball(C)\Velocity\Y 
    Ball(C)\Velocity\Y +0.05 
    If (Ball(C)\Pos\X<=0 And Ball(C)\Velocity\X<0) Or (Ball(C)\Pos\X=>1280 And Ball(C)\Velocity\X>0):Ball(C)\Velocity\X=-Ball(C)\Velocity\X*Ball(C)\E:EndIf 
    If (Ball(C)\Pos\Y<=0 And Ball(C)\Velocity\Y<0) Or (Ball(C)\Pos\Y=>1024 And Ball(C)\Velocity\Y>0):Ball(C)\Velocity\Y=-Ball(C)\Velocity\Y*Ball(C)\E:EndIf 
    Energy=Energy+Ball(C)\Weight*Pow(Dist(0,0,Ball(C)\Velocity\X,Ball(C)\Velocity\Y),2)/2 
  Next 
  For I=0 To #B_Num 
    For J=I To #B_Num 
      If Dist(Ball(I)\Pos\X,Ball(I)\Pos\Y,Ball(J)\Pos\X,Ball(J)\Pos\Y)<=#B_Size And Dist(Ball(I)\Pos\X,Ball(I)\Pos\Y,Ball(J)\Pos\X,Ball(J)\Pos\Y)<Dist(Ball(I)\LastPos\X,Ball(I)\LastPos\Y,Ball(J)\LastPos\X,Ball(J)\LastPos\Y) And I<>J 
        E.f=(Ball(I)\E+Ball(J)\E)/2 : DistX.f=(Ball(I)\Pos\X-Ball(J)\Pos\X) : DistY.f=(Ball(I)\Pos\Y-Ball(J)\Pos\Y) 
        D.f=Sqr(DistX*DistX+DistY*DistY) : DistX=DistX/(D+0.1) : DistY=DistY/(D+0.1)        
        Velocity1.f=(Ball(I)\Velocity\X*DistX + Ball(I)\Velocity\Y*DistY) 
        Velocity2.f=(Ball(J)\Velocity\X*DistX + Ball(J)\Velocity\Y*DistY) 
        FinalVelocity1.f=((Ball(I)\Weight-E*Ball(J)\Weight)*Velocity1+(1+E)*Ball(J)\Weight*Velocity2)/(Ball(I)\Weight+Ball(J)\Weight) 
        FinalVelocity2.f=((Ball(J)\Weight-E*Ball(I)\Weight)*Velocity2+(1+E)*Ball(I)\Weight*Velocity1)/(Ball(I)\Weight+Ball(J)\Weight)  
        Ball(I)\Velocity\X=(FinalVelocity1-Velocity1)*DistX + Ball(I)\Velocity\X 
        Ball(I)\Velocity\Y=(FinalVelocity1-Velocity1)*DistY + Ball(I)\Velocity\Y 
        Ball(J)\Velocity\X=(FinalVelocity2-Velocity2)*DistX + Ball(J)\Velocity\X 
        Ball(J)\Velocity\Y=(FinalVelocity2-Velocity2)*DistY + Ball(J)\Velocity\Y 
      EndIf 
    Next 
  Next 
  For C=0 To #B_Num : DisplayTransparentSprite(1,Ball(C)\Pos\X-#B_Size/2,Ball(C)\Pos\Y-#B_Size/2) : Next 
  StartDrawing(ScreenOutput()) : DrawingMode(1) 
  DrawText(10,10,"Кинетическая энергия:"+Str(Energy),RGB(255,255,255)) : StopDrawing() 
Until KeyboardReleased(#PB_Key_Escape) 
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Screenshot of a full-screen game?

Post by idle »

Maybe you could try turning off desktop composition

Code: Select all

Procedure DWMEnableDisable(onoff.l)

  Protected *pAfunc,Lib = LoadLibrary_("dwmapi.dll")

  If Lib
    
     *pAfunc = GetProcAddress_(Lib, "DwmEnableComposition") 
      If *pAfunc
          CallFunctionFast(*pAfunc, onoff) 
      EndIf 
    FreeLibrary_(Lib) 
    
  EndIf

EndProcedure 
registrymechanic22
Enthusiast
Enthusiast
Posts: 176
Joined: Sun Jun 28, 2009 7:07 pm
Location: RUS

Re: Screenshot of a full-screen game?

Post by registrymechanic22 »

idle wrote:Maybe you could try turning off desktop composition
still does not help :(
rudd68
User
User
Posts: 29
Joined: Wed Jun 09, 2010 2:55 pm

Re: Screenshot of a full-screen game?

Post by rudd68 »

Hello,

this is a code extract from idle's code:

Code: Select all

If gp = 0 
  gp=0
EndIf 
What is the function of this IF: ENDIF block?

Greetings.
registrymechanic22
Enthusiast
Enthusiast
Posts: 176
Joined: Sun Jun 28, 2009 7:07 pm
Location: RUS

Re: Screenshot of a full-screen game?

Post by registrymechanic22 »

rudd68 wrote:Hello,this is a code extract from idle's code:

Code: Select all

If gp = 0 
  gp=0
EndIf 
What is the function of this IF: ENDIF block?Greetings.
Do not pay attention to it, it cut piece of code to test the screenshot ...
Thorium
Addict
Addict
Posts: 1305
Joined: Sat Aug 15, 2009 6:59 pm

Re: Screenshot of a full-screen game?

Post by Thorium »

Fraps works by hooking DirectX.
I think thats the only way for real fullscreen games.
registrymechanic22
Enthusiast
Enthusiast
Posts: 176
Joined: Sun Jun 28, 2009 7:07 pm
Location: RUS

Re: Screenshot of a full-screen game?

Post by registrymechanic22 »

Thorium wrote:Fraps works by hooking DirectX.
I think thats the only way for real fullscreen games.
Yes, I also pay attention to this.
Clearly, thanks for the info ....
... Myself, I do not overpower it.

Best regards.
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Re: Screenshot of a full-screen game?

Post by Num3 »

If you just need the screen area this works in window or full screen:

Code: Select all

Procedure Shot(width.i, height.i)
  Define width.i, height.i, any.i
  any.i = GrabSprite(#PB_Any,0,0,width, height)
  If any
    SaveSprite(any,GetTemporaryDirectory()+"test.bmp")
    FreeSprite(any)
  EndIf    
EndProcedure
registrymechanic22
Enthusiast
Enthusiast
Posts: 176
Joined: Sun Jun 28, 2009 7:07 pm
Location: RUS

Re: Screenshot of a full-screen game?

Post by registrymechanic22 »

Num3 wrote:If you just need the screen area this works in window or full screen:

Code: Select all

Procedure Shot(width.i, height.i)
  Define width.i, height.i, any.i
  any.i = GrabSprite(#PB_Any,0,0,width, height)
  If any
    SaveSprite(any,GetTemporaryDirectory()+"test.bmp")
    FreeSprite(any)
  EndIf    
EndProcedure
.....games are not my..., games from third-party.....
Post Reply