As you (may or may not) know screensavers just pass different command line parameters to the .exe to do different things '/s' for screensaver, '/c' for config and also '/p' for preview. Along with the '/p' there is also the handle to the preview window passed like this '/p:2165', i have no trouble parsing this and getting the handle, BUT when i try to display anything in this window i run into problems, i think its my inexperience with child windows. This is my code:
Code: Select all
;===========================================================================
;-GLOBAL FLAGS / VARIABLES / STRUCTURES / ARRAYS
;===========================================================================
Global screenWidth.l
Global screenHeight.l
Global previewFlag.l
Global parameter.s
Global prevWinHndlString.s
Global prevWinHndl.l
Global prevThreadID.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)
*MutexName = @screensaverName
Shared OnlyOneStartMutex.l
OnlyOneStartMutex = CreateMutex_(0, 1, *MutexName)
OnlyOneStartError.l = GetLastError_()
If OnlyOneStartMutex <> 0 And OnlyOneStartError = 0
ProcedureReturn 1
Else
CloseHandle_(OnlyOneStartMutex)
End
EndIf
EndProcedure
;close the screensaver
Procedure OnlyOneSCRStop()
CloseHandle_(OnlyOneStartMutex)
EndProcedure
;execute the preview in the little mini monitor in 'Display Properties'
Procedure ExecutePreview()
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
EndProcedure
;run the fullscreen screensaver code
Procedure ExecuteScreenSaver()
Shared screensaverName
SystemParametersInfo_(#SPI_SCREENSAVERRUNNING, 1, @oldval, 0)
ShowCursor_(0)
HandleError(OpenScreen(screenWidth, screenHeight, 32, screensaverName), "A fullscreen screen could not be opened!")
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 < XMax And Pos = 0 : x+1 : Pos = 0 : EndIf
If x = XMax And Pos = 0 : x-1 : Pos = 1 : EndIf
If x < XMax And Pos = 1 : x-1 : Pos = 1 : EndIf
If x = 0 And Pos = 1 : x+1 : Pos = 0 : EndIf
FlipBuffers()
Delay(1)
ExamineKeyboard()
ExamineMouse()
Until KeyboardPushed(#PB_Key_All) Or MouseDeltaX() <> 0 Or MouseDeltaY() <> 0 Or MouseWheel() <> 0 Or MouseButton(1) <> 0 Or MouseButton(2) <> 0
ShowCursor_(1)
SystemParametersInfo_(#SPI_SCREENSAVERRUNNING, 0, @oldval, 0)
End
EndProcedure
;===========================================================================
;-CONFIG 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
End
EndProcedure
;===========================================================================
;-MAIN
;===========================================================================
OnlyOneSCRStart(screensaverName)
;deal with the parameters passed to this program
Select parameter
Case "" ;double clicked
Config()
Case "A" ;check password
End
Case "C" ;'Settings' button clicked in the screensaver dialog
Config()
Case "P" ;when the preview is requested in the screensaver dialog by selecting this screensaver
ExecutePreview()
Case "S" ;launch the main screensaver after an interval or by pressing 'Preview' in the dialog
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
OnlyOneSCRStop()
End
;===========================================================================
;-BINARY INCLUDES
;===========================================================================
PBLogo:
IncludeBinary "PureBasic.bmp"
PreviewImage:
IncludeBinary "preview.bmp"
I have tried an API approach using this as a guide:
viewtopic.php?t=2658
but that piece of code confuses the hell out of me and its not very generic. I'm trying to write a screensaver template to use a PB screen using OpenScreen() for nice graphics and to be reuseable for lots of savers, etc... I'm nearly there i just need this .bmp in the preview window sorting.
Big thanks to anyone who can help.



