Code archives/Graphics/GetDesktop

This code has been declared by its author to be Public Domain code.

Download source code

GetDesktop by Ziltch
(Posted 24 years ago)
Make a snapshot of users desktop and create/update a texture/image.

eg.

tex = GetDesktop() ; creates a texture
image = GetDesktop(1) ; creates an image
GetDesktop(0,tex) ; updates a texture
GetDesktop(1,image) ; updates an image
Const SRCCOPY = $CC0020
Const CF_BITMAP = 2
Const SW_HIDE = 0
Const SW_SHOW = 5

Function GetDesktop(flag=0,update=0)

; ADAmor ZILTCH 2003
;
; This command must come after your GRAPHICS(3D) x,y command.
;
;  flag 0 = create texture
;       1 = create image
;
; if update is not 0 then it is the tex/image to update.

   DeskHwnd = GetDesktopWindow()

   ; Get screen coordinates
   fwidth  = GetSystemMetrics%(0)  ;RectWin\rightR  - RectWin\leftR
   fheight = GetSystemMetrics%(1)  ;RectWin\bottomR - RectWin\topR

   BlitzHwnd = GetActiveWindow()
   ShowWindow(BlitzHwnd,SW_HIDE)

   ; Get the device context of Desktop and allocate memory
   hdc = GetDC(DeskHwnd)
   Blitzhdc = GetDC(BlitzHwnd)

   ; Copy data
   BitBlt(Blitzhdc, 0, 0, fwidth, fheight, hdc, 0,0, SRCCOPY)

   ; Clean up handles
   ReleaseDC(DeskHwnd, hdc)
   ReleaseDC(BlitzHwnd, Blitzhdc)
   ShowWindow(BlitzHwnd,SW_SHOW)

   ; Create/update texture or image
   Select flag
     Case 0
       If update = 0 Then
         tex=CreateTexture(fwidth,fheight)
       Else
         tex=update
       End If
       CopyRect 0,0,fwidth,fheight,0,0,FrontBuffer(),TextureBuffer(tex)
       Return tex
     Case 1
       If update = 0 Then
         image=CreateImage(fwidth,fheight)
       Else
         image=update
       End If
       CopyRect 0,0,fwidth,fheight,0,0,FrontBuffer(),ImageBuffer(image)
       Return image
   End Select

End Function
;---------------- end code

Lines needed in Userlib: User32.decls

FindWindow%( class$,Text$ ):"FindWindowA"
ShowWindow(hwnd%,nCmdShow%)
GetActiveWindow%()
GetDC%(hWnd% )
ReleaseDC%(hWnd%,hDC%)
GetDesktopWindow%()
GetSystemMetrics%(nIndext%)

Lines needed in Userlib: Gdi32.decls
BitBlt%(hDestDC%,X%,Y%,nWidth%,nHeight%,hSrcDC,XSrc,YSrc,dwRop)

Comments

JoeRetro
(Posted 21 years ago)
Thanks! Works Great!

Ked
(Posted 20 years ago)
Doesn't work.

Buggy
(Posted 19 years ago)
Is this BlitzPlus? It doesn't work in Blitz3D.

Ked
(Posted 19 years ago)
Oops. Just kidding. It works. You need to finish the decls part:
Lines needed in Userlib: User32.decls

FindWindow%( class$,Text$ ):"FindWindowA"
ShowWindow(hwnd%,nCmdShow%):"ShowWindow"
GetActiveWindow%():"GetActiveWindow"
GetDC%(hWnd% ):"GetDC"
ReleaseDC%(hWnd%,hDC%):"ReleaseDC"
GetDesktopWindow%():"GetDesktopWindow"
GetSystemMetrics%(nIndext%):"GetSystemMetrics"

Lines needed in Userlib: Gdi32.decls
BitBlt%(hDestDC%,X%,Y%,nWidth%,nHeight%,hSrcDC,XSrc,YSrc,dwRop):"BitBlt"

The resolution NEEDS to be in fullscreen and the SAME SIZE as the desktop. And Debug off.

Jerome Squalor
(Posted 19 years ago)
It says there needs to be a lib.

Ked
(Posted 19 years ago)
The DECLS file should look like this:
.lib "user32.dll"
FindWindow%(class$,Text$):"FindWindowA"
ShowWindow(hwnd%,nCmdShow%):"ShowWindow"
GetActiveWindow%():"GetActiveWindow"
GetDC%(hWnd% ):"GetDC"
ReleaseDC%(hWnd%,hDC%):"ReleaseDC"
GetDesktopWindow%():"GetDesktopWindow"
GetSystemMetrics%(nIndext%):"GetSystemMetrics"

.lib "gdi32.dll"
BitBlt%(hDestDC%,X%,Y%,nWidth%,nHeight%,hSrcDC,XSrc,YSrc,dwRop):"BitBlt"


schilcote
(Posted 18 years ago)
So this takes a picture of what the user of the computer is seeing on his monitor? If not, is there a way to do that?

Nate the Great
(Posted 18 years ago)
ok so I cant get this to work on vista? anyone else have this problem

Code Archives Forum