Ooops
January 26, 2021, 05:55:24 AM

Author Topic: [bb] GetDesktop by Ziltch [ 1+ years ago ]  (Read 500 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] GetDesktop by Ziltch [ 1+ years ago ]
« on: June 29, 2017, 12:28:38 AM »
Title : GetDesktop
Author : Ziltch
Posted : 1+ years ago

Description : 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


Code :
Code: BlitzBasic
  1. Const SRCCOPY = $CC0020
  2. Const CF_BITMAP = 2
  3. Const SW_HIDE = 0
  4. Const SW_SHOW = 5
  5.  
  6. Function GetDesktop(flag=0,update=0)
  7.  
  8. ; ADAmor ZILTCH 2003
  9. ;
  10. ; This command must come after your GRAPHICS(3D) x,y command.
  11. ;
  12. ;  flag 0 = create texture
  13. ;       1 = create image
  14. ;
  15. ; if update is not 0 then it is the tex/image to update.
  16.  
  17.    DeskHwnd = GetDesktopWindow()
  18.  
  19.    ; Get screen coordinates
  20.    fwidth  = GetSystemMetrics%(0)  ;RectWin
  21. ightR  - RectWinleftR
  22.    fheight = GetSystemMetrics%(1)  ;RectWinottomR - RectWin    opR
  23.  
  24.    BlitzHwnd = GetActiveWindow()
  25.    ShowWindow(BlitzHwnd,SW_HIDE)
  26.  
  27.    ; Get the device context of Desktop and allocate memory
  28.    hdc = GetDC(DeskHwnd)
  29.    Blitzhdc = GetDC(BlitzHwnd)
  30.  
  31.    ; Copy data
  32.    BitBlt(Blitzhdc, 0, 0, fwidth, fheight, hdc, 0,0, SRCCOPY)
  33.  
  34.    ; Clean up handles
  35.    ReleaseDC(DeskHwnd, hdc)
  36.    ReleaseDC(BlitzHwnd, Blitzhdc)
  37.    ShowWindow(BlitzHwnd,SW_SHOW)
  38.  
  39.    ; Create/update texture or image
  40.    Select flag
  41.      Case 0
  42.        If update = 0 Then
  43.          tex=CreateTexture(fwidth,fheight)
  44.        Else
  45.          tex=update
  46.        End If
  47.        CopyRect 0,0,fwidth,fheight,0,0,FrontBuffer(),TextureBuffer(tex)
  48.        Return tex
  49.      Case 1
  50.        If update = 0 Then
  51.          image=CreateImage(fwidth,fheight)
  52.        Else
  53.          image=update
  54.        End If
  55.        CopyRect 0,0,fwidth,fheight,0,0,FrontBuffer(),ImageBuffer(image)
  56.        Return image
  57.    End Select
  58.  
  59. End Function
  60. ;---------------- end code
  61.  
  62. Lines needed in Userlib: User32.decls
  63.  
  64. FindWindow%( class$,Text$ ):"FindWindowA"
  65. ShowWindow(hwnd%,nCmdShow%)
  66. GetActiveWindow%()
  67. GetDC%(hWnd% )
  68. ReleaseDC%(hWnd%,hDC%)
  69. GetDesktopWindow%()
  70. GetSystemMetrics%(nIndext%)
  71.  
  72. Lines needed in Userlib: Gdi32.decls
  73. BitBlt%(hDestDC%,X%,Y%,nWidth%,nHeight%,hSrcDC,XSrc,YSrc,dwRop)


Comments :


JoeRetro(Posted 1+ years ago)

 Thanks!  Works Great!


Ked(Posted 1+ years ago)

 Doesn't work.


Buggy(Posted 1+ years ago)

 Is this BlitzPlus?  It doesn't work in Blitz3D.


Ked(Posted 1+ years ago)

 Oops. Just kidding. It works. You need to finish the decls part:
Code: [Select]
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 1+ years ago)

 It says there needs to be a lib.


Ked(Posted 1+ years ago)

 The DECLS file should look like this:
Code: [Select]
.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 1+ 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 1+ years ago)

 ok so I cant get this to work on vista? anyone else have this problem


n8r2k(Posted 1+ years ago)

 i cant get it to work either. maybe the user32.dll is different? [/i]

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal