 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Murp|e
Joined: 12 Jan 2007 Posts: 474 Location: Norway
|
Posted: Wed Dec 17, 2008 1:28 am Post subject: |
|
|
Z_Gecko: Thanks for the speedy reply and for the code! It was surprisingly easy to position the gui like this:
| Code: | #persistent
#singleinstance force
WinGetPos, winX, winY, , ,Display Properties
ControlGetPos, conX, conY, Width, Height, SSDemoParent1, Display Properties
guiX := winX + conX
guiY := winY + conY
Gui, +AlwaysOnTop +LastFound +Owner ; +Owner prevents a taskbar button from appearing.
Gui, Color, FFFC00
Gui, -Caption ; Remove the title bar and window borders.
Gui, Show, x%guiX% y%guiY% w%Width% h%Height%
return |
"Display Properties" will have to be replaced by ahk_id %ControlHwnd%.
I'm not very familiar controlling the child/parent relationship of guis and windows, but perhaps using majkinetor's Dock would be a good idea? It could be used to ensure the screensaver preview gui is always in the correct position. The above code works fine until you move the display properties window at which point the gui remains fixed in the previous position, looking rather out-of-place you might say. The Dock also handles the child/parent thing by default.
I re-read your post now, did you mean that it might not be necessary to position the gui if you make it a child of the Display Properties window? If so, that would simplify this a great deal. |
|
| Back to top |
|
 |
Murp|e
Joined: 12 Jan 2007 Posts: 474 Location: Norway
|
Posted: Wed Dec 17, 2008 1:08 pm Post subject: |
|
|
I found the setparent DllCall in the forums and after commenting out part of this line:
| Quote: | | Gui, +AlwaysOnTop ;+LastFound +Owner prevents a taskbar button from appearing. |
the dllcall now returns 0 which I suppose means the dllcall was successful. The gui appears in the correct position and the size looks more or less okay, but when the Display Properties window is moved around the gui still remains fixed in the original position, seemingly despite the fact that it has been set as a child. Also, how should the script know when to terminate this preview? Are there any command line arguments or any messages/events it should be listening for?
Here is the script I'm using to test:
| Code: | #persistent
#singleinstance force
;Get /p #### from Display Properties window
Loop, %0%
{
param := %A_Index%
if ParamIsHwnd
{
DisplayPropertiesHandle = %param%
gosub, PreviewInWindow
ParamIsHwnd = false
}
if param = /p
ParamIsHwnd = true
}
return
PreviewInWindow:
WinGetPos, winX, winY, , ,Display Properties
ControlGetPos, conX, conY, Width, Height, SSDemoParent1, Display Properties
guiX := winX + conX
guiY := winY + conY
Gui, +AlwaysOnTop ;+LastFound +Owner prevents a taskbar button from appearing.
Gui, Color, FFFC00
Gui, -Caption ; Remove the title bar and window borders.
Gui, Show, x%guiX% y%guiY% w%Width% h%Height%
result := DllCall( "SetParent", "uint", WinExist(), "uint",DisplayPropertiesHandle)
msgbox, %result%
return |
|
|
| Back to top |
|
 |
Murp|e
Joined: 12 Jan 2007 Posts: 474 Location: Norway
|
Posted: Tue Jan 06, 2009 1:49 pm Post subject: |
|
|
With some help from majkinetor I managed to write something that will display a picture in the preview area of the Display Properties window and correctly use the setparent dllcall. I don't understand why, but I had to hardcode the width, height, X and y of the control to get the correct position. It's still a little buggy when the window is moved around, minimized and restored and so on, but I think it's a step in the right direction.
| Code: | g := WinExist("Display Properties")
Gui, +LastFound -sysmenu -caption +owner
Gui, Add, Picture, w160 h120 x120 y60 Icon44 HWNDhPic, %A_WinDir%\system32\SHELL32.dll
gui, show, w0 h0
DllCall( "SetParent", "uint", hPic, "uint", g) |
|
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 4055 Location: Belgrade
|
Posted: Tue Jan 06, 2009 2:07 pm Post subject: |
|
|
| Quote: | | I don't understand why, but I had to hardcode the width, height, X and y of the control to get the correct position. |
Because coordinates of the child become relative to the new parent.
You can either do what you did, or move control after you set its parent. To position the injected control dynamically, you will have to obtain the list of child controls of system's window, find the control that holds the screensaver preview (its some child of the static displaying monitor image) and take its coordinates and apply it to your control. Control will dissapear or blink on refresh if its not top level on children list, which it will be if you set its parrent right. Its parent should be static, not entire window. _________________
 |
|
| Back to top |
|
 |
Murp|e
Joined: 12 Jan 2007 Posts: 474 Location: Norway
|
Posted: Thu Jan 08, 2009 5:02 am Post subject: |
|
|
Thanks again majkinetor! After hours of working on this I think I've finally got the preview to behave as it should. It took only three lines of code to get the correct size and position (0,0) of the gui, add a picture preview and use the setparent dllcall. The final result hasn't shown any bugs on my system which I'm very pleased with!
I've tried to incorporate the preview functionality into the rest of Z_Gecko's screensaver framework, hopefully he will test and look over the code and update his original post for others to benefit from.
Updated Screensaver framework including preview functionality:
| Code: | ; Simple (Non-)Screensaver framework (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
;--------------------------------------------------------------------------------------------------------------------------------------
#NoTrayIcon
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 preview window and no pw-change window under W9x and
; the config window has probably not the right owner
;--------------------------------------------------------------------------------------------------------------------------------------
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
}
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
break
}
if param contains c,C
{
runmode = config
break
}
if param contains p,P,l,L
{
runmode = preview
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
break
}
else
{
runmode = undefined
}
}
}
; load the configuration via the getconf subroutine
GoSub, getconf
; decide what mode to start
; right now only show and config are supported, all other modes will exit the saver
if runmode = show
{
GoSub, svrshow
}
if runmode = config
{
GoSub, svrconfig
}
if runmode = preview
{
GoSub, svrpreview
}
if runmode = pwconfig
{
GoSub, svrend
}
if runmode = undefined
{
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
;--------------------------------------------------------------------------------------------------------------------------------------
; svrconfig shows the configuration dialog of the saver
;the ButtonOK subroutine stores the changes if OK is pressed
; this mode is not fully implemented, as it SHOULD really:
; 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.
;BUT it DOES show only a very general configuration dialog without regarding any of these options
;--------------------------------------------------------------------------------------------------------------------------------------
svrconfig:
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, Show,, Simple Saver Configuration
return
;--------------------------------------------------------------------------------------------------------------------------------------
; svrpreview previews the screensaver inside the Display Properties window.
;
;--------------------------------------------------------------------------------------------------------------------------------------
svrpreview:
ControlGetPos, , , ssW, ssH, , ahk_id %ParentHwnd%
Gui, Add, Picture, x0 y0 w%ssW% h%ssH% HWNDChildHwnd, %windir%\winnt.bmp
DllCall( "SetParent", "uint", ChildHwnd, "uint", ParentHwnd)
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
;--------------------------------------------------------------------------------------------------------------------------------------
;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
DllCall("SetCursorPos", int, A_ScreenWidth, int, A_ScreenHight) ; 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)
sleep, 1000
; 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
{
}
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 config 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
DllCall("SetCursorPos", int, MousePosX, int, MousePosY) ; moves the Cursor back to where it was before screensaver started
ExitApp
;-------------------------------------------------------------------------------------------------------------------------------------- |
I have one question. If the configuration/preview GUIs are shown while a user browses through the available screensavers, but without actually starting the screensaver -when will these GUIs be destroyed and the .SCR exited? Did I miss this in the code or isn't that currently being handled? I'm asking because while testing I had to frequently kill the screensaver process in Task Manager after I was finished testing.
Also, is there any reason the "gui, +lastfound" and "gui, show" commands should be used? A static image might suffice for many purposes in which case these gui commands don't seem to be necessary?
Here is a screenshot from WinSpy++ which shows the hierarchy (child/parent relation) of the controls of the Display Properties window:
This was partly what I had a hard time figuring out. |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 4055 Location: Belgrade
|
Posted: Thu Jan 08, 2009 2:00 pm Post subject: |
|
|
C code
| Quote: | // Quit if dialog is dismissed. Check this periodically.
if (!IsWindowVisible(parentHwnd))
Application.Exit(); |
I don't know if system kills scr when user switches to another screensaver preview, but I guess it does that.
BTW, your new code for positioning is OK. _________________
 |
|
| Back to top |
|
 |
Murp|e
Joined: 12 Jan 2007 Posts: 474 Location: Norway
|
Posted: Thu Jan 08, 2009 2:31 pm Post subject: |
|
|
majkinetor: Not sure which ParentHwnd this is refering to but I'll try to look into it.
Any thoughts on my other question:
| Quote: | | ...is there any reason the "gui, +lastfound" and "gui, show" commands should be used?... |
|
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 4055 Location: Belgrade
|
Posted: Thu Jan 08, 2009 2:53 pm Post subject: |
|
|
parentHwnd := WinExist("Display Properties")
You could even detect tabs but it seems overkill. U usualy set up screensaver and exit the dialog, certanly you don't go from there to tweak video options...
| Quote: | | ...is there any reason the "gui, +lastfound" and "gui, show" commands should be used?... |
I didn't check the code, but I don't see a reason for gui to be shown while doing preview. Gui, show must be used for Full Screen operation. _________________
 |
|
| Back to top |
|
 |
Zed Gecko
Joined: 23 Sep 2006 Posts: 120
|
Posted: Thu Jan 08, 2009 4:12 pm Post subject: |
|
|
iīve updated the code in the first post.
itīs a little different from the script, murple posted.
it displays a a GUI and not just a Control in preview mode,
now choosing another saver in the Display Properties will exit the saver correctly.
i tried to make the config-GUI of the saver a child of the "Display Properties"-window.
but the effect looked totally different from the behaviour of other screensavers, so commented it out and disabled the "Display Properties"-window instead.
i added a SingleInstance force just for security. _________________ 1) All my code can be reused in ANY way. 2) Please check the help and the forum-search, before posting questions; the answer is out there... |
|
| Back to top |
|
 |
Murp|e
Joined: 12 Jan 2007 Posts: 474 Location: Norway
|
Posted: Thu Jan 08, 2009 10:14 pm Post subject: |
|
|
majkinetor: Ok, thanks.
Zed Gecko: With the current script the Display Properties window looses focus when svrpreview is run.
| Code: | 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 |
Possibly because of the +lastfound above? Why is that necessary to make the dllcall work?
Also, perhaps it's a good idea to make one of the GUI controls a child of the ssdemoparent1 control since all standard screensavers seem to have a child control this way?
| Quote: | i tried to make the config-GUI of the saver a child of the "Display Properties"-window.
but the effect looked totally different from the behaviour of other screensavers |
I found a post by Chris where he makes a standard "Font-Picker" dialog modal to his GUI, meaning the GUI cannot be interacted with until a font has been selected and the font-picker window has been closed. Isn't this very close to our needs for the screensaver configuration window? I can't make heads or tails of the code though.
Lastly, if a configuration window for one of the standard screensavers is open and you click on the Display Properties window, the configuration window for the screensaver flashes. I'm not sure how, but perhaps that should be incorporated as well. I found gui flash in the documentation. |
|
| Back to top |
|
 |
gwarble
Joined: 23 May 2009 Posts: 125 Location: north bay, california
|
Posted: Fri Sep 25, 2009 8:48 am Post subject: |
|
|
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.ahk | Code: |
;===============================================
;=== 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
|
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|