Capture desktop and use it as a sprite?

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Malte.

Hi!

Is there a way to capture the desktop at the start of a program and copy it into a "normal" Purebasic sprite? It would be very useful for creating screensavers.

Malte
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.

Look here:

viewtopic.php?t=1482

There is a function to capture the desktop.
It creates an Image instead of a Sprite.

There is no CreateSprite command for now.
Maybe you can make an Image get the size of it (maybe with SizeOf) and use CatchSprite.
But I haven't tested it yet so it's up to you to try it...

SizeOf is not documented yet, but maybe Fred could explain here how to use it (can I use it for everything?)

Hope this helps at least a little bit...


Have a nice day...
Franco

Sometimes you have to go a lonely way to accomplish genius things.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Malte.

Thanks, Franco!

That really helped me.
This is what I made from the code (works fine ):

Code: Select all

 
InitKeyboard()
InitMouse()
InitSprite()
DC.l = GetDC_(0)
MemDC.l = CreateCompatibleDC_(DC)
ScreenWidth = GetSystemMetrics_(#SM_CXSCREEN)
ScreenHeight = GetSystemMetrics_(#SM_CYSCREEN)
ColorDepth = GetDeviceCaps_(DC,#BITSPIXEL)
BmpID.l = CreateImage(0,ScreenWidth,ScreenHeight)
SelectObject_(MemDC, BmpID)
BitBlt_(MemDC, 0, 0, ScreenWidth, ScreenHeight,DC, 0, 0, #SRCCOPY)
DeleteDC_(MemDC)
ReleaseDC_(0,DC)
OpenScreen(ScreenWidth,ScreenHeight,ColorDepth,"")
StartDrawing(ScreenOutput())
DrawImage(BmpID,MouseX(),MouseY())
StopDrawing()
GrabSprite(0,0,0,ScreenWidth,ScreenHeight)
Repeat

ExamineKeyboard()
ExamineMouse()
ClearScreen(0,0,0)
DisplaySprite(0,MouseX(),MouseY())
FlipBuffers()

Until KeyboardPushed(#PB_Key_All) Or MouseButton(1)

End
Greetings
Malte
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

Hi Malte... your example is very jerky for me (W2K), but I note that if I add
Sleep_(1) directly after the Repeat command, it becomes smooth as silk.


PB - Registered PureBasic Coder
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Malte.
Hi Malte... your example is very jerky for me (W2K), but I note that if I add
Sleep_(1) directly after the Repeat command, it becomes smooth as silk.


PB - Registered PureBasic Coder
Hmm, I had no problems with it. On both WinME and XP it is smooth with or without that Sleep_(1) command. Very strange...
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> Hmm, I had no problems with it. On both WinME and XP it is smooth with or
> without that Sleep_(1) command. Very strange...

I wonder if screen res/depth is the reason? I have a 1024x768 desktop set to
32-bit colour... what about yours?


PB - Registered PureBasic Coder
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Malte.
> Hmm, I had no problems with it. On both WinME and XP it is smooth with or
> without that Sleep_(1) command. Very strange...

I wonder if screen res/depth is the reason? I have a 1024x768 desktop set to
32-bit colour... what about yours?
I use the same screen resolution and color depth. May be it's W2k's fault or the graphic driver.

Malte



Edited by - Malte on 06 August 2002 08:40:34
Post Reply