@Kale
Hmm it's true. We can't code a screensaver preview without WinAPI.
We always need a child window to receive some CLOSE messages.
Code: Select all
#WM_CLOSE_OLD_PREVIEW = 2000
#PREVIEW_TITLE = "My Saver Preview"
;-------------------
;-Preview Destructor
;-------------------
Procedure PreviewDestructor(window, message, wParam, lParam)
Result = #PB_ProcessPureBasicEvents
Select message
Case #WM_CLOSE
DestroyWindow_(window)
End
Case #WM_CLOSE_OLD_PREVIEW
GlobalString.l = wParam
GlobalString$ = Space(1204)
GlobalGetAtomName_(GlobalString,GlobalString$,1024)
If GlobalString$=#PREVIEW_TITLE
GlobalDeleteAtom_(GlobalString)
End
EndIf
EndSelect
ProcedureReturn Result
EndProcedure
;-------------------
;-Preview
;-------------------
Procedure Preview(preview)
; ------------------------
; preview image
; ------------------------
UseGadgetList(preview)
GetClientRect_(preview,@rc.rect)
CreateImage(1,rc\right,rc\bottom)
StartDrawing(ImageOutput())
For y=0 To ImageHeight()
Line(0,y,ImageWidth(),1,RGB($FF*y/ImageHeight(),$CC*y/ImageHeight(),0))
Next
StopDrawing()
ImageGadget(1,0,0,0,0,ImageID())
CloseGadgetList()
; ------------------------
; close all old previews
; ------------------------
Sendmessage_(#HWND_BROADCAST,#WM_CLOSE_OLD_PREVIEW,GlobalAddAtom_(#PREVIEW_TITLE),0)
; ------------------------
; wait end of preview (using fake window)
; ------------------------
OpenWindow(0,0,0,0,0,#PB_WINDOW_INVISIBLE,#PREVIEW_TITLE)
SetParent_(WindowID(),preview)
SetWindowCallback(@PreviewDestructor())
Repeat
WaitWindowEvent()
ForEver
EndProcedure
;-------------------
;-Main Program
;-------------------
FirstParam.s =ProgramParameter()
command.s =LCase(Left(ReplaceString(FirstParam,"-","/"),2))
ParentWindow.l =Val(StringField(FirstParam,2,":")) | Val(ProgramParameter())
Select command
Case "/p"
Preview(ParentWindow)
Case "/c"
;Config(ParentWindow)
Default
;Saver()
EndSelect