Page 1 of 1

GrabDesktop

Posted: Sun Jul 05, 2009 3:14 pm
by eddy
just an idea

Code: Select all

GrabDesktop(#Desktop, x,y ,width,height)

Re: GrabDesktop

Posted: Sun Jul 05, 2009 11:41 pm
by PB
+1

There is lots of code in these forums to do it, but a small command like that
is just so nice-looking. It turns me on. ;)

Posted: Mon Jul 06, 2009 8:12 am
by Kaeru Gaman
sounds good...

I think some GrabWindow(WindowID(#), x,y ,width,height) would be a consequent completion..

Posted: Tue Jul 07, 2009 6:08 pm
by #NULL
just in case it will be implemented: please make each parameters for the dimension optional to grab the hole area, or allow -1 or such.

Re: GrabDesktop

Posted: Tue Jul 07, 2009 10:09 pm
by Matt
eddy wrote:just an idea

Code: Select all

GrabDesktop(#Desktop, x,y ,width,height)
+1
#NULL wrote:just in case it will be implemented: please make each parameters for the dimension optional to grab the hole area, or allow -1 or such.
+1

:D

Posted: Sat Aug 01, 2009 5:43 pm
by TazNormand
is this answer what you want :

Code: Select all

Procedure GrabDesktop(PosX,PosY,Width,Height)  
  Protected Result,Depth,MyImage,hc,GetDC
  Result=ExamineDesktops()  ; How Many desktops
  If Result
    If PosX=-1:posX=0:EndIf
    If PosY=-1:PosY=0:EndIf
    If Width=-1:Width=DesktopWidth(0):EndIf
    If Height=-1:Height=DesktopHeight(0):EndIf
    Depth=DesktopDepth(0) ; Desktop color Depth in bpp
    If Depth>0
      MyImage=CreateImage(#PB_Any,Width,Height,Depth)
      hc=StartDrawing(ImageOutput(MyImage))
      If hc
        GetDC=GetDC_(GetDesktopWindow_())
        BitBlt_(hc,0,0,Width,Height,GetDC,PosX,PosY,#SRCCOPY)      
        StopDrawing()        
        ReleaseDC_(GetDesktopWindow_(),GetDC)
      EndIf
    EndIf
  EndIf  
  ProcedureReturn ImageID(MyImage)
EndProcedure
Create the Image "MyImage", so you can use it like this :

Code: Select all

startX=150
StartY=200
w=300
h=450
spr=CreateSprite(0,w,h)
Img=GrabDesktop(StartX,StartY,w,h)
StartDrawing(SpriteOutput(0))
  DrawImage(Img,0,0,w,h)
StopDrawing()
Note that my function only work on desktop 0 (default), but you can change it to use any desktop number you want

EDIT : i've added the test of -1 value to take default desktop dimensions

Posted: Sat Aug 01, 2009 6:11 pm
by Matt
Yes, but for all platforms. And straight integration into PureBasic would be nice.
#NULL wrote:just in case it will be implemented: please make each parameters for the dimension optional to grab the hole area, or allow -1 or such.
better yet, #PB_Ignore ;)

Posted: Sat Aug 01, 2009 8:29 pm
by TazNormand
Matt wrote:Yes, but for all platforms. And straight integration into PureBasic would be nice.
#NULL wrote:just in case it will be implemented: please make each parameters for the dimension optional to grab the hole area, or allow -1 or such.
better yet, #PB_Ignore ;)
right Matt, but you know, i'm a PB beginner, i do my best to help other beginners.

i write #PB_Ignore to my unerasable brain memory :wink: