How to grab desktop
Blitz3D Forums/Blitz3D Programming/How to grab desktop
| ||
Hi, I remember seeing some code (using api) to grab the desktop, does anyone have it? |
| ||
http://www.blitzbasic.com/codearcs/codearcs.php?code=654 |
| ||
Has anyone actually got this to work? |
| ||
Just tried it and it works perfectly with debug off, but *only* in fullscreen mode. Turn debug on, however, and it drops into the debugger at the line ShowWindow(BlitzHwnd,SW_HIDE) without throwing an error. I think it's got issues. Sorry should have tested before posting (although that guy JoeRetro said it works great). :/ |
| ||
I just don't see anything! Do you have an example bb file? |
| ||
The code pretty much worked as it is in the code archives, except I set a graphics mode and added a While/Wend loop. I grabbed the desktop with image = GetDesktop(1). The code is very "hit and miss" though... there has to be a more reliable solution. You could also try temporarily setting your desktop resolution to 800x600 - I know that on some systems you can get problems with images larger than the current graphics mode. |
| ||
Try this, doesn't work...Graphics3D 800,600,16,1 Global dt quit = False While quit = False dt = GetDesktop(1) DrawImage dt, 0,0 If KeyHit(1) quit = True EndIf Wend 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 |
| ||
It works most of the time. For instance, I have 3 test machines at home and the code works fine, but when a friend try it out on his machine it didn't quite work. The results show some icons missing or half drawn from the desktop. It appears as if the desktop was refreshing at the time of calling GetDesktopWindow. So this leaves me to believe that a) has something to do with the graphics card and/or b) something to do with the graphics card drivers. It worked fine on a Geforce 2MX, Geforce 4MX, Geforce 6600GT and ATI 8500 mobility, but did not work properly on a Geforce FX 5200. @Boiled Sweets, I got your email and once I get home tonight (at work at the moment) I will send you some code that I use to capture/resize the desktop for my screensavers. |
| ||
Hi JoeRetro, ta, please send it to me address I use here (see my profile) as opposed to the one I sent from. Many thanks. I'll see if I can find out how to get it working 100% |