beautiful framework you have developed here, very impressive and a lot of research, thank you...
i'm using it now to create a .scr version of my little app, which displaying realtime data is one of its main purposes so this is well suited... thanks for all the effort, from everyone on the thread as well
i've done a little reworking to maintain your script's functionality but to seperate out the visible screensaver part from the windows interaction part into 2 files... quickly done yields these from your example scr:
ExampleScr.ahkCode:
;===============================================
;=== Simple (Non-)Screensaver framework V3.1 ;=== Simpler format idea
;===============================================
CompName := "ExampleCompany"
ProdName := "ExampleScreenSaver"
RefreshTime = 250
;=== more settable options...
#Include SimpleScr.ahk
Return ;=============== End Auto-Execute section
;===============================================
;====== This is the programm closing subroutine:
;===============================================
SSClose:
Gui, Destroy
Return
;===============================================
;=============== shows the configuration dialog:
;==== use g-label: ButtonOK to save the settings
;===============================================
SSConfig:
Gui, Add, Text,, Backgroundcolor in RGB-Hex (000000 is black) :
Gui, Add, Edit, vconfig1, %CustomColor%
Gui, Add, Text,, Minimum movement the Mouse has to make to quit the saver (in pixel) :
Gui, Add, Edit, vconfig2, %Mouseoffset%
Gui, Add, Button, default, OK ; The label ButtonOK will be run when the button is pressed.
;DllCall( "SetParent", "uint", WinExist(), "uint", ParentHwnd) ; UNCOMMENT IF YOU LIKE: make the preview-Gui a child of the HWND passed through the command-line
Gui, Show, , Simple Saver Configuration
Return
;===============================================
;============ preview inside Display Properties:
;================ use %ssW% and %ssH% for sizing
;===============================================
SSPreview:
Gui, -Caption
Gui, Add, Picture, x0 y0 w%ssW% h%ssH% , test.gif
Gui +LastFound ; prepare for the following DDL-Call
DllCall( "SetParent", "uint", WinExist(), "uint", ParentHwnd) ; make the preview-Gui a child of the HWND passed through the command-line
Gui, Show, w%ssW% h%ssH% x0 y0 ; show the preview-GUI relative to the owning control
Return
SSRefresh:
Return
;===============================================
;=============== this is the actual screensaver:
;===============================================
SSShow:
;this block creates a fullscreen window without any borders in any color set in the var "CustomColor"
Gui, +AlwaysOnTop +LastFound +Owner ; +Owner prevents a taskbar button from appearing.
Gui, Color, %CustomColor%
Gui, -Caption ; Remove the title bar and window borders.
Gui, Show, x0 y0 Maximize
Return
SimpleScr.ahk - modified edited for RefreshSS:Code:
;=== modified version to be #included by another file with
;======= subroutines SSClose, SSConfig, SSPreview, and SSShow and SSRefresh
;======= variables CompName, ProdName, Refreshtime...
; Simple (Non-)Screensaver framework V3.1(can be used to create own Screensavers by compiling and renaming to .scr). This script requires v1.0.44.12 or later
; This script consists of :
; many code-snippets from the AHK-Help File and of certain lines from this forum ;-)
; it was inspired by the input from this Forum, the Scrrensaver tutorial at http://www.wischik.com/scr/howtoscr.html and the MSDN help pages
; so it´s mostly not my code
; the updated version contains contribution from: Murple & majkinetor
;--------------------------------------------------------------------------------------------------------------------------------------
#NoTrayIcon
#SingleInstance force
CoordMode, Mouse, Screen
;--------------------------------------------------------------------------------------------------------------------------------------
;this is the main section, which will run on startup
;as the behaviour expected of the saver depends on the command-line arguments it is given
;first the command-line arguments are checked using the
;build in vars 0,1,2,3,... ,where 0 contains the number of command-line arguments given
;there are several rules for reacting to command-line arguments
;if the command line arguments are invalid, then the saver should terminate immediately without doing anything.
;if argument = /c, /c ####, or no arguments at all - in response to any of these the saver should pop up its configuration dialog.
;if argument = /s - this indicates that the saver should run itself as a full-screen saver.
;if argument = /p ####, or /l #### - here the saver should treat the #### as the decimal representation of an HWND, and pop up a child window to run in preview mode inside that window.
;if argument = /a #### - this argument is only used in '95 and Plus! The saver should pop up a password-configuration dialog.
;the command-line options may appear as lower-case or upper-case, and that there might be either a forward slash or a hyphen prefixing the letter.
; this script does not support all the modes
; it will show no pw-change window under W9x
;--------------------------------------------------------------------------------------------------------------------------------------
if 0 = 0 ; checks if no command-line arguments have been passed
{
runmode = config ; the var runmode is used to decide what action the screensaver shall perform
confparam = false ; confparam will be false if no valid cmd-line arguments have been passed
}
else
{
Loop, %0% ; For each parameter:
{
param := %A_Index% ; Fetch the contents of the variable whose name is contained in A_Index.
if param contains s,S
{
runmode = show
confparam = true
break
}
if param contains c,C
{
runmode = config
confparam = true
nextparam := A_Index + 1
ParentHwnd := %nextparam% ;Decimal representation of optional HWND
SetFormat, integer, hex
ParentHwnd += 0 ;Standard hex HWND
SetFormat, integer, d
break
}
if param contains p,P,l,L
{
runmode = preview
confparam = true
nextparam := A_Index + 1
ParentHwnd := %nextparam% ;Decimal representation of HWND for SSDEMOPARENT1 control of Display Properties window.
SetFormat, integer, hex
ParentHwnd += 0 ;Standard hex HWND for SSDEMOPARENT1
SetFormat, integer, d
break
}
if param contains a,A
{
runmode = pwconfig
confparam = true
break
}
else
{
runmode = undefined
}
}
}
; load the configuration via the getconf subroutine
GoSub, getconf
; decide what mode to start
; right now only show, config and preview (thanks to murple) are supported, all other modes will exit the saver
if runmode = show
{
GoSub, svrshow
return
}
if runmode = config
{
GoSub, svrconfig
return
}
if runmode = preview
{
GoSub, svrpreview
return
}
if runmode = pwconfig
{
GoSub, svrend
return
}
if runmode = undefined
{
GoSub, svrend
return
}
GoSub, svrend
return
;--------------------------------------------------------------------------------------------------------------------------------------
; the getconfig subroutine should contain all the internal and external configuration
; it is called by the startup section prior to all other subroutines
;--------------------------------------------------------------------------------------------------------------------------------------
getconf:
MouseGetPos, MousePosX, MousePosY ; stores original coursor-position to put it back there before stopping the saver
;here the saver configuration is read from the registry and set to default values if no configuration data is present in the registry
; make shure to chose your own values for CompanyName and Product Name
RegRead, CustomColor, HKEY_CURRENT_USER, Software\AHKSaver\MyAHKSaver\, BGColor
if not CustomColor
{
CustomColor = 000000 ; Can be any RGB color (000000 is black)
}
RegRead, Mouseoffset, HKEY_CURRENT_USER, Software\AHKSaver\MyAHKSaver\, MOffset
if not Mouseoffset
{
Mouseoffset = 3 ; Can be any full number
}
return
;--------------------------------------------------------------------------------------------------------------------------------------
; the ButtonOK label is run when the OK Button from scrconfig is pressed
; it stores the configuration in the registry
;.It should be saved in the registry in the standard location: HKEY_CURRENT_USER\Software\MyCompany\MyProduct\.
;--------------------------------------------------------------------------------------------------------------------------------------
ButtonOK:
Gui, Submit
; make shure to chose your own values for CompanyName and Product Name
RegWrite, REG_SZ, HKEY_CURRENT_USER, Software\AHKSaver\MyAHKSaver\, BGColor, %config1%
RegWrite, REG_SZ, HKEY_CURRENT_USER, Software\AHKSaver\MyAHKSaver\, MOffset, %config2%
Gosub, svrend
return
;--------------------------------------------------------------------------------------------------------------------------------------
; WM_ENDAPP is the handler for the incoming Windows Messages
; it will call the svrend subroutine to end the screensaver if any of the Messages above will arrive
;--------------------------------------------------------------------------------------------------------------------------------------
WM_ENDAPP()
{
Gosub, svrend
return
}
;--------------------------------------------------------------------------------------------------------------------------------------
; CHECKENDAPP is the handler for the incoming Windows Message WM_MOUSEMOVE
; it will call the svrend subroutine to end the screensaver if the Mouse has left the parking position
;--------------------------------------------------------------------------------------------------------------------------------------
WM_CHECKEND()
{
MouseGetPos, MouseX, MouseY
; first make the global parking position var accessible in this funktion
global LowerLimitX
global LowerLimitY
global UpperLimitX
global UpperLimitY
; then check if mouse has left the parking position
if MouseX not between %LowerLimitX% and %UpperLimitX%
GoSub, svrend
if MouseY not between %LowerLimitY% and %UpperLimitY%
GoSub, svrend
return
}
;--------------------------------------------------------------------------------------------------------------------------------------
;This is the programm closing subroutine, all other subroutines or funtions will call this to exit the saver
; GuiClose and svrend will both execute the following
;--------------------------------------------------------------------------------------------------------------------------------------
GuiClose: ; in case the gui was aborted
svrend:
;the next line should unblock Ctrl+Alt+Esc and Alt+Tab under Win9x, but it´s not tested and only neccesary with the corresponding DllCall-Line above
;DllCall("SystemParametersInfo", "Str", "SPI_SETSCREENSAVERRUNNING", "UInt", "0", "UInt*", previousstate, "UInt", "0")
;;;;;Gui, Destroy
GoSub, SSClose
if (runmode = "config") ; reenable the underlying window, that was disabled by the svrconfig:-subrutine
{
WinSet, Enable, , ahk_id %ParentHWND%
WinActivate, ahk_id %ParentHWND%
}
if (runmode = "show") ; only reset mouseposition if in show-mode
{
DllCall("SetCursorPos", int, MousePosX, int, MousePosY) ; moves the Cursor back to where it was before screensaver started
}
ExitApp
;--------------------------------------------------------------------------------------------------------------------------------------
; svrconfig shows the configuration dialog of the saver
;the ButtonOK subroutine stores the changes if OK is pressed
; this mode is NOT implemented, as following:
; With /c as an argument, use the ForegroundWindow as its parent.
;With /c #### the saver should treat #### as the decimal representation of an HWND, and use this as its parent.
;If there are no arguments then NULL should be used as the parent.
;Since this behaviour is a little different than other screensavers actually show, it is commented out rigth now, uncomment the marked lines if you like
; instead the underlying window is disabled and reenabled when the server ends.
;--------------------------------------------------------------------------------------------------------------------------------------
svrconfig:
; choose the right parent window
if (ParentHWND = "" OR !WinExist("ahk_id " . ParentHWND))
{
ParentHWND := WinExist("A")
}
if (confparam = "false")
{
ParentHWND := 0
}
; creat config Gui
;;;;;Gui, Add, Text,, Backgroundcolor in RGB-Hex (000000 is black) :
;;;;;Gui, Add, Edit, vconfig1, %CustomColor%
;;;;;Gui, Add, Text,, Minimum movement the Mouse has to make to quit the saver (in pixel) :
;;;;;Gui, Add, Edit, vconfig2, %Mouseoffset%
;;;;;Gui, Add, Button, default, OK ; The label ButtonOK will be run when the button is pressed.
;;;;;?????Gui +Lastfound
GoSub, SSConfig
WinSet, Disable, , ahk_id %ParentHWND%
;DllCall( "SetParent", "uint", WinExist(), "uint", ParentHwnd) ; UNCOMMENT IF YOU LIKE: make the preview-Gui a child of the HWND passed through the command-line
;;;;;Gui, Show, , Simple Saver Configuration
return
;--------------------------------------------------------------------------------------------------------------------------------------
;svrpreview previews the screensaver inside the Display Properties window.
;therefore it should end with an endless Loop
;the saver terminates itself through the GuiClose:-subroutine when the owning window is destroyed by the system,
;the Preview-GUI -as a child-window- is destroyed, too. So the GuiClose:-subroutine is triggered
;
; attention, the preview in this example actually displays a picture not related to the actual screensaver
;--------------------------------------------------------------------------------------------------------------------------------------
svrpreview:
ControlGetPos, , , ssW, ssH, , ahk_id %ParentHwnd% ; get the Size of the window, that´s supposed to be the parent of the preview window
;;;;;Gui, -Caption
;;;;;Gui, Add, Picture, x0 y0 w%ssW% h%ssH% , %windir%\winnt.bmp ; %ssW% and %ssH% are the Size and Width of the preview-window, use them to scale the controls
;;;;;Gui +LastFound ; prepare for the following DDL-Call
;;;;;DllCall( "SetParent", "uint", WinExist(), "uint", ParentHwnd) ; make the preview-Gui a child of the HWND passed through the command-line
;;;;;Gui, Show, w%ssW% h%ssH% x0 y0 ; show the preview-GUI relative to the owning control
GoSub, SSPreview
Loop
{
sleep 5000
}
return
;--------------------------------------------------------------------------------------------------------------------------------------
;--------------------------------------------------------------------------------------------------------------------------------------
;this is the actual screensaver
;the svrshow subroutine will display the fullscreen saver
;therefore it should end with an endless Loop
;the saver terminates itself by incoming Windows Messages, so
;there is no need to continuously check the mouse positon or any keystrokes
;--------------------------------------------------------------------------------------------------------------------------------------
svrshow:
;;;;; this block creates a fullscreen window without any borders in any color set in the var "CustomColor"
;;;;;Gui, +AlwaysOnTop +LastFound +Owner ; +Owner prevents a taskbar button from appearing.
;;;;;Gui, Color, %CustomColor%
;;;;;Gui, -Caption ; Remove the title bar and window borders.
;;;;;Gui, Show, x0 y0 Maximize
GoSub, SSShow
DllCall("SetCursorPos", int, A_ScreenWidth+Mouseoffset, int, A_ScreenHeight+Mouseoffset) ; sets the mouse to a position outside the visible sreen and thus making the cursor unvisible
sleep, 100
; this block checks the actual mouse position and creates defines the parking position of the mouse
MouseGetPos, MouseX, MouseY
LowerLimitY := (MouseY - Mouseoffset)
UpperLimitY := (MouseY + Mouseoffset)
LowerLimitX := (MouseX - Mouseoffset)
UpperLimitX := (MouseX + Mouseoffset)
; the following OnMessage commands make the Screensaver listen to several Window Messages
; to get information if the mouse was moved, a mouse-button pressed or a system key or non-system key on the keybord was pressed
; whenever the system sends one of the messages below , the script will start the WM_ENDAPP() funktion
; this will eventually exit the saver
OnMessage(0x201, "WM_ENDAPP") ; WM_LBUTTONDOWN : indicates that the left mouse button was pressed
OnMessage(0x204, "WM_ENDAPP") ; WM_RBUTTONDOWN : indicates that the right mouse button was pressed
OnMessage(0x207, "WM_ENDAPP") ; WM_MBUTTONDOWN : indicates that the middle mouse button was pressed
OnMessage(0x200, "WM_CHECKEND") ; WM_MOUSEMOVE : indicates that the mouse was moved
OnMessage(0x100, "WM_ENDAPP") ; WM_KEYDOWN : indicates that a non-system key was pressed
OnMessage(0x104, "WM_ENDAPP") ; WM_SYSKEYDOWN : indicates that a system key was pressed
OnMessage(0x1C, "WM_ENDAPP") ; WM_ACTIVATEAPP : indicates that another application needs the focus
OnMessage(0x06, "WM_ENDAPP") ; WM_ACTIVATE : indicates that another application needs the focus
OnMessage(0x10, "WM_ENDAPP") ; WM_CLOSE : indicates that the system wants to close the program
;the next line should block Ctrl+Alt+Esc and Alt+Tab under Win9x, but it´s not tested and only neccesary for pw-protection under Win9x
;DllCall("SystemParametersInfo", "Str", "SPI_SETSCREENSAVERRUNNING", "UInt", "1", "UInt*", previousstate, "UInt", "0")
Loop
{
Sleep, % RefreshTime
GoSub, SSRefresh
}
return
nothing fancy here, but another thread sparked my SS interest and i'm thinking i'll use this a lot, so a simple to edit file is always nice...
Note the ;;;;; lines i removed, and their gosub equiv's... and the #include is IN the autoexecute section of examplescr.ahk
hope this is useful for someone
- gwarble
EDIT: added SSRefresh label and RefreshTime variable
here's an example, a quick hack job of SKAN's beautiful slideshow script to create SlideShow.scr when compiled
lots of work needed but a very impressive framework to say the least, thanks again
Code:
; Written by A.N.Suresh Kumar aka "Goyyah"
; 21-Jun-2006
;===============================================
;=== SlideShow Screen Saver 0.1 - SKAN's slideshow modified into screen saver
;====================================Initialize:
CompName := "AHKSlideShow"
ProdName := "AHKSlideShow"
RefreshTime = 100
;===============================================
SetWorkingDir, %A_ScriptDir%
SplitPath, A_ScriptFullPath,,,,ScriptName
RunDir= %A_ScriptDir%\Pictures
#Include SimpleScr.ahk
Return ;=============== End Auto-Execute section
;===============================================
#Include AniEffect.ahk
SSRefresh:
P_Index++
Gui, %P_Index%:+Owner99
Gui, %P_Index%:-Caption +AlwaysOnTop +ToolWindow -Border
Gui, %P_Index%:+LastFound
GUI_ID:=WinExist()
Gui, %P_Index%:Margin, 0,0
Gui, %P_Index%:Add,Picture, w%ImgWid% h-1 E0x200, %RunDir%\Slide%P_Index%.jpg
Gui, %P_Index%:Show,NA Hide, %ScriptName%.AHK.Slide: %P_Index%
DllCall("AnimateWindow","UInt",GUI_ID,"Int",700 ,"UInt", AniEffect("Zoom_In") )
P_Prev:=P_Index - 1
If P_Index > 1
Gui, %P_Prev%:Destroy
Sleep, 3000 ;=== picture show length
DllCall("AnimateWindow","UInt",GUI_ID,"Int",500,"UInt", AniEffect("Fade_Out") )
If P_Index > 3
P_Index:=0
Return
;===============================================
;====== This is the programm closing subroutine:
;===============================================
SSClose:
DllCall("AnimateWindow","UInt",GUI_99,"Int",700,"UInt", AniEffect("Zoom_Out") )
Gui, 99:Destroy
Return
;===============================================
;=============== shows the configuration dialog:
;==== use g-label: ButtonOK to save the settings
;===============================================
SSConfig:
Gui, Add, Text,, Backgroundcolor in RGB-Hex (000000 is black) :
Gui, Add, Edit, vconfig1, %CustomColor%
Gui, Add, Text,, Minimum movement the Mouse has to make to quit the saver (in pixel) :
Gui, Add, Edit, vconfig2, %Mouseoffset%
Gui, Add, Button, default, OK ; The label ButtonOK will be run when the button is pressed.
;DllCall( "SetParent", "uint", WinExist(), "uint", ParentHwnd) ; UNCOMMENT IF YOU LIKE: make the preview-Gui a child of the HWND passed through the command-line
Gui, Show, , Simple Saver Configuration
Return
;===============================================
;============ preview inside Display Properties:
;================ use %ssW% and %ssH% for sizing
;===============================================
SSPreview:
Gui, -Caption
Gui, Add, Picture, x0 y0 w%ssW% h%ssH% , test.gif
Gui +LastFound ; prepare for the following DDL-Call
DllCall( "SetParent", "uint", WinExist(), "uint", ParentHwnd) ; make the preview-Gui a child of the HWND passed through the command-line
Gui, Show, w%ssW% h%ssH% x0 y0 ; show the preview-GUI relative to the owning control
Return
;===============================================
;=============== this is the actual screensaver:
;===============================================
SSShow:
Gui, 99:-Caption +AlwaysOnTop
Gui, 99:+LastFound
GUI_99 :=WinExist()
Gui, 99:Margin, 0,0
Gui, 99:Add,Picture, w%A_ScreenWidth% h%A_ScreenHeight%, %RunDir%\Gradient.bmp
Gui, 99:Show,NA Hide , %ScriptName%.AHK.SlideShow: 99
DllCall("AnimateWindow","UInt",GUI_99,"Int",700 ,"UInt", AniEffect("Zoom_In") )
ImgWid:= A_ScreenWidth/100*78.2
P_Index:=0
Return