Save Screenshot(Multiply Desktops) to files [Windows only]

Share your advanced PureBasic knowledge/code with the community.
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Save Screenshot(Multiply Desktops) to files [Windows only]

Post by Rings »

saves a screenshot(Hardcopy) from multiply Desktops to a file.
I need that for work, so i will share these usefull lines with you.

Code: Select all

;HardCopy 2 File
;by Siegfried Rings, may 5., 2010

UsePNGImageEncoder()
UseJPEGImageEncoder()

Filename.s=""
For I= 0 To  CountProgramParameters() -1
  Filename + ProgramParameter(I)
Next

Extension.s = LCase(GetExtensionPart(Filename))
Filename1.s= Left(Filename,Len(Filename)-Len(Extension)-1)

CountDesktops=ExamineDesktops()
For I=1 To CountDesktops
  x=DesktopX(I-1)
  y=DesktopY(I-1)
  w=DesktopWidth(I-1)
  h=DesktopHeight(I-1)
  res=CreateImage(1,w,h) 
  hDC = StartDrawing(ImageOutput(1))
   BitBlt_(hDC, 0, 0, w, h, GetDC_(0), x, y, #SRCCOPY)
  StopDrawing() 
  If CountDesktops=1
    tFilename.s=Filename1 + "." + Extension
  Else
    tFilename.s=Filename1 + "_D" + Str(I) + "." + Extension
  EndIf
  If Extension="bmp":SaveImage(1,tFilename,#PB_ImagePlugin_BMP):EndIf
  If Extension="jpg":SaveImage(1,tFilename,#PB_ImagePlugin_JPEG):EndIf 
  If Extension="jpeg":SaveImage(1,tFilename,#PB_ImagePlugin_JPEG):EndIf
  If Extension="png":SaveImage(1,tFilename,#PB_ImagePlugin_PNG):EndIf
Next 
SPAMINATOR NR.1