screensaver development?

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 Kale.

Has anybody got any links dealing with screensaver development, especially on the preview pane in the screensaver dialog? i have searched the forum and read this but i can't speak german and doesn't seem very well commented:

viewtopic.php?t=2658

i already have a nice screensaver outline template, it only lacks the code to display a mini-version in the little preview pane.

--Kale

In love with PureBasic! :)
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 ricardo.

Hi,

But the code on the snippet that you links actually does what you want.
Its on the procedure Preview(wnd)that is trigger when the application receives a "P" parameter on commandline, then next parameter is the handle of the preview pane.
The preview procedure create and register a Class, then get the dimension of the parent that will handle the preview, create a window there, start the screensaver and make it run.

If you read carefully the example (i dont speak german) i think that you will be able to get how it works.


Best Regards

Ricardo

Dont cry for me Argentina...
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 Kale.

having looked at that code, it seems he opens a window full screen and a mini window for the preview and draws the screensaver to this (which is just random grey boxes) i want to use a Screen (not a window) for nice sprite/3d animation, etc... is there any screensaver dev sites on the net? I just need some info on the preview window now (what its able to do and what it supports)

--Kale

In love with PureBasic! :)
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 Kale.

hmmm having spent a little bit of time looking into this i think you need to use windows (then OpenWindowedScreen), because the screensaver dialog passes the small previews windows handle to be used as a parent. This is quite a good little link: http://www.screensaverz.net/build-vb2.htm

--Kale

In love with PureBasic! :)
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 Kale.

Oh i give up! can anybody help me out with this one, i must admit to never doing this before and i'm sure its pretty easy once you know how it is done:

I am trying to write a screensaver template that i can use and modify to code a few different screensavers. I understand how the screensaver is called from the display properties dialog, but i'm having trouble getting the damn preview to quit so i can start the screensaver by pressing 'preview'. Also when i close the display properties dialog, the screensaver is still running in the background? any ideas, this is driving me nuts. This is what i have cobbled together from examples found on this forum, can you see any problems? things i've missed? because it doesn't work! :cry:

Code: Select all

;===========================================================================
;-INCLUDED FILES
;===========================================================================



;===========================================================================
;-CONSTANTS
;===========================================================================



;===========================================================================
;-GLOBAL FLAGS / VARIABLES / STRUCTURES / ARRAYS
;===========================================================================

Global screenWidth.l
Global screenHeight.l
Global previewFlag.l
Global parameter.s
Global prevWinHndlString.s
Global prevWinHndl.l

screensaverName.s = "PureBasic ScreenSaver"
screenWidth.l = GetSystemMetrics_(#SM_CXSCREEN)
screenHeight.l = GetSystemMetrics_(#SM_CYSCREEN)

parameter = UCase(ProgramParameter())
If Len(parameter) > 2
    prevWinHndlString = RemoveString(parameter, Left(parameter, 3), 1)
    parameter = RemoveString(parameter, Left(parameter, 1), 1)
    parameter = Left(parameter, 1)
Else
    parameter = RemoveString(parameter, Left(parameter, 1), 1)
    prevWinHndlString = ProgramParameter()
    If FindString(prevWinHndlString, "-", 0)  0 : prevWinHndlString = RemoveString(prevWinHndlString, "-", 1) : EndIf
    If FindString(prevWinHndlString, "/", 0)  0 : prevWinHndlString = RemoveString(prevWinHndlString, "/", 1) : EndIf
EndIf
prevWinHndl = Val(prevWinHndlString)

;===========================================================================
;-PROCEDURES
;===========================================================================

;simple error checking
Procedure HandleError (result, text.s)
    If result = 0 : MessageRequester("Error", text, #PB_MessageRequester_Ok) : End : EndIf
EndProcedure

;start only one screensaver
Procedure OnlyOneSCRStart(screensaverName.s)
    Shared OnlyOneStartMutex.l
    OnlyOneStartMutex=CreateMutex_(0,1,screensaverName)
    OnlyOneStartError.l=GetLastError_()
    If OnlyOneStartMutex0 And OnlyOneStartError=0
        ProcedureReturn 1
    Else
        CloseHandle_(OnlyOneStartMutex)
        End
    EndIf
EndProcedure

;close the screensaver
Procedure OnlyOneSCRStop()
    CloseHandle_(OnlyOneStartMutex)
EndProcedure

;run the fullscreen screensaver code
Procedure ExecuteScreenSaver()
    Shared screensaverName
    HandleError(OpenScreen(screenWidth, screenHeight, 32, screensaverName), "A fullscreen screen could not be opened!")
    ShowCursor_(0)

        CatchSprite(0, ?PBLogo, 0)
        XMax = (GetSystemMetrics_(#SM_CXSCREEN)/2)-(SpriteWidth(0)/2)
        YMax = (GetSystemMetrics_(#SM_CYSCREEN)/2)-(SpriteHeight(0)/2)
    
    Repeat

        ClearScreen(0,0,0)
        DisplaySprite(0, XMax+x, YMax+x)
        DisplaySprite(0, XMax-x, YMax-x)
        DisplaySprite(0, XMax+x, YMax-x)
        DisplaySprite(0, XMax-x, YMax+x)
        DisplaySprite(0, XMax+x, YMax)
        DisplaySprite(0, XMax-x, YMax)
        DisplaySprite(0, XMax, YMax+x)
        DisplaySprite(0, XMax, YMax-x)
        If x  0 Or MouseDeltaY()  0 Or MouseWheel()  0 Or MouseButton(1)  0 Or MouseButton(2)  0
    ShowCursor_(1)
    End
EndProcedure

;===========================================================================
;-MEDIA
;===========================================================================



;===========================================================================
;-GEOMETRY
;===========================================================================

;configuration window
Procedure Config()
    Shared screensaverName
    If OpenWindow(0, 0, 0, 320, 240, #PB_Window_SystemMenu | #PB_Window_WindowCentered, screensaverName)
        Repeat
            EventID.l = WaitWindowEvent()
        Until EventID = #PB_EventCloseWindow
    EndIf
EndProcedure

;===========================================================================
;-MAIN
;===========================================================================

OnlyOneSCRStart(screensaverName)

;deal with the parameters passed to this program
Select parameter
    ;double clicked
    Case ""
        Config()
    ;'Settings' button clicked in the screensaver dialog
    Case "C"
        Config()
    ;when the preview is requested in the dialog by selecting this screensaver
    Case "P"
        previewWindowSize.RECT
        GetClientRect_(prevWinHndl, @previewWindowSize)
        CatchImage(1, ?PreviewImage)
        HandleError(CreateGadgetList(prevWinHndl), "Gadget list in preview panel could not be created!")
        ImageGadget(1, 0, 0, previewWindowSize\right, previewWindowSize\bottom, UseImage(1))
        Repeat
            EventID.l = WaitWindowEvent()
        Until EventID = #PB_EventCloseWindow
        End
    ;launch the main screensaver after an interval or by pressing 'Preview' in the dialog
    Case "S"
        HandleError(InitSprite(), "DirectX v7.0 or above can not be found or initialised!")
        HandleError(InitKeyboard(), "DirectX v7.0 or above can not be found or initialised!")
        HandleError(InitMouse(), "DirectX v7.0 or above can not be found or initialised!")
        ExecuteScreenSaver()
EndSelect
End

;===========================================================================
;-BINARY INCLUDES
;===========================================================================

PBLogo:
    IncludeBinary "PureBasic.bmp"
    
PreviewImage:
    IncludeBinary "preview.bmp"
--Kale

In love with PureBasic! :)
Post Reply