Date: 02-16-2022
Return to Index
created by gbSnippets
'This is a version of the screensaver template at http://gbl_00466 which
'draws on the dialog rather than a graphic control.
'Compilable Example: (Jose Includes)
'After compilation of this snippet to an EXE, you must manually change the
'extension to SCR and place the file in the \windows\system32 folder. It will
'then be visible from the Windows Display Properties application.
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Debug Error On 'catch array/pointer errors - OFF in production
#Debug Display On 'display untrapped errors - OFF in production
#Include "win32api.inc"
''========================================================================
''Change these as needed - specific to the screensaver
''========================================================================
$Main_Title = "SCRNSAVE: Screensaver:"
$Setting_Title = "Screensaver Settings"
$INIFileName = "screensaver.ini"
''========================================================================
''End of change section
''========================================================================
Global hDlg As DWord, hSettings as DWord, hDC as DWord
Global w,h,TimerInterval, OldProc As Long
%ID_Timer = 700
Function PBMain() As Long
Settings_INI "get"
Select Case Left$(LCase$(Command$(1)),2)
Case "/p" : DisplayInPreviewWindow 'preview window, then quit
Case "/a" : DisplayPassWordDialog 'password, then quit
Case "/c" : DisplaySettingsDialog 'settings, then quit
Case "/s" : DisplayScreenSaver 'start normally
Case Else : DisplayScreenSaver 'start normally
End Select
End Function
Sub DisplayScreenSaver
Desktop Get Size To w,h
Dialog New Pixels, 0, $Main_Title,0,0,w,h, %WS_Popup To hDlg
Dialog Set Color hDlg, %Rgb_DarkGreen, %Rgb_Darkgreen
Dialog Show Modal hDlg Call DlgProc
End Sub
CallBack Function DlgProc() As Long
Select Case CB.Msg
Case %WM_InitDialog
SetWindowPos(hDlg, %HWND_TOPMOST, 0, 0, 0, 0, %SWP_NoMove Or %SWP_NoSize) 'on Top
OldProc = SetWindowLong(hDlg, %GWL_WndProc, CodePTR(NewDialogProc)) 'subclass
InitializeGraphics
ShowCursor(%False)
SetTimer(CB.Hndl, %ID_Timer, TimerInterval, ByVal %NULL) 'uses callback messages
Dialog Post CB.Hndl, %WM_Timer, %ID_TIMER, 0 ' optional - forces an initial %WM_TIMER "event"
Case %WM_Char
? "main"
Case %WM_SetCursor
Static iCount as Long
Incr iCount
If iCount > 10 Then Dialog End hDlg
Case %WM_Timer
Exit Function
Local PS AS Paintstruct
hDC = BeginPaint(hDlg, PS)
DisplayGraphics
EndPaint hDlg, PS
Case %WM_Destroy
SetWindowLong hDlg, %GWL_WNDPROC, OldProc 'un-subclass
ShowCursor(%True)
KillTimer CB.Hndl, %ID_Timer
Settings_INI "save"
End Select
End Function
Function NewDialogProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case Msg
Case %WM_Char
Static i as long
Incr i
If i = 1 Then MsgBox "proc"
Dialog End hDlg
End Select
Function = CallWindowProc(OldProc, hWnd, Msg, wParam, lParam)
End Function
Sub DisplayInPreviewWindow
'not supported as this time
End Sub
''================================================================================
''Change below this line as needed - specific to the screensaver
''================================================================================
Sub Settings_INI(Task$)
'This sub saves settings to an INI file wherever the SCR file is placed.
'Each setting corresponds to a Global variable
'To call, use one of these: Settings_INI("get") or Setting_INI("save")
'Examples of saving Numeric and String variable are shown
Local temp As Asciiz*%Max_Path, INIFileName As Asciiz*%Max_Path
'defines file name (any file name will work)
INIFileName = Exe.Path$ + $INIFileName
If Task$ = "get" Then
'get value for numeric variable
Getprivateprofilestring "Settings", "TimerInterval", "20", temp, %Max_Path, INIFileName
TimerInterval = Val(temp)
'get value for string variable
' Getprivateprofilestring "Settings", "UnusedString", "20", temp, %Max_Path, INIFileName
' UnsedString = temp
End If
If Task$ = "save" Then
'save numeric variable
temp = Str$(TimerInterval)
WritePrivateProfileString "Settings", "TimerInterval", temp, INIFileName
'save string variable
' temp = Str$(UnusedString)
' WritePrivateProfileString "Settings", "UnusedString", temp, INIFileName
End If
End Sub
Sub InitializeGraphics
'as required
End Sub
Sub DisplayGraphics
'draw on dialog
Local SzText As AsciiZ * 84
SetBkMode hDC, %TRUE
szText = "This is my screen saver Clic Mouse to Exit."
textOut HDC, 5, 60, szText, Len(szText)
End Sub
Sub DisplayPasswordDialog()
'not supported
End Sub
Sub DisplaySettingsDialog()
Dialog New Pixels, hDlg, $Setting_Title, (w-200)/2,(h-200)/2,200,200, %WS_SysMenu Or %WS_Caption Or %WS_ClipChildren To hSettings
Dialog Set Icon hSettings, "aainfo"
Control Add Label, hSettings, 800, "Timer Interval (ms):", 50, 60, 100, 20
Control Add TextBox, hSettings, 900, "20", 50, 80, 100, 20
Control Set Text hSettings, 900, Str$(TimerInterval)
Dialog Show Modal hSettings Call SettingsProc
End Sub
CallBack Function SettingsProc() As Long
Local temp$
Select Case CB.Msg
Case %WM_Command
If CB.Ctl = %IDOK Then Dialog End hSettings
If CB.Ctl = %IDCANCEL Then Dialog End hSettings
Case %WM_Destroy
Control Get Text hSettings, 900 To temp$
TimerInterval = Val(temp$)
If TimerInterval <=0 Then TimerInterval = 1
Settings_INI "save"
End Select
End Function
'gbs_00501
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm