GrabDesktop

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

GrabDesktop

Post by eddy »

just an idea

Code: Select all

GrabDesktop(#Desktop, x,y ,width,height)
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: GrabDesktop

Post 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. ;)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

sounds good...

I think some GrabWindow(WindowID(#), x,y ,width,height) would be a consequent completion..
oh... and have a nice day.
#NULL
Addict
Addict
Posts: 1497
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Post 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.
Matt
Enthusiast
Enthusiast
Posts: 447
Joined: Sat May 21, 2005 1:08 am
Location: USA

Re: GrabDesktop

Post 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
User avatar
TazNormand
User
User
Posts: 27
Joined: Tue May 26, 2009 3:17 pm
Location: France

Post 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
Matt
Enthusiast
Enthusiast
Posts: 447
Joined: Sat May 21, 2005 1:08 am
Location: USA

Post 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 ;)
User avatar
TazNormand
User
User
Posts: 27
Joined: Tue May 26, 2009 3:17 pm
Location: France

Post 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:
Post Reply