Jump to content

Automated Windows Switcher


Chipper
 Share

Recommended Posts

Hi,

I was asked at work to see if I could write a simple program that would run through all of the running programs at a set cycle (say 15 seconds). There is a few workstations that are used to monitor network items and people wanted an easy method to scroll through them.

I have attempted the following, but am a little stuck. When the program is visible, I want it to stop scrolling through the applications. This way the person could change the setting without having to find it again.

Thanks for any guidance you can suggest.

#include <GUIConstantsEx.au3>

$time = 15
$var = WinList()

Opt("GUIOnEventMode", 1)
$msg = GUICreate("Program Switcher", 225, 100)
GUICtrlCreateLabel("Enter the time in seconds:",10,20)
$Seconds = GUICtrlCreateInput("15", 140, 16,25)
$Apply = GUICtrlCreateButton("Apply", 60, 50, 60)
GUICtrlSetOnEvent($Apply, "ApplyButton")
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
WinMinimizeAll()
GUISetState(@SW_SHOW)

While 1
    $msg = GuiGetMsg()
    $state = WinGetState("Program Switcher", "")
    
    If BitAND($state, 16) Then
        For $i = 1 to $var[0][0]
            
            If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then
                If $var[$i][0] <> "Program Manager" Then
                    WinSetState($var[$i][0],"",@SW_MAXIMIZE)
                    $totaltime = $time * 1000
                    Sleep ($totaltime)
                    WinSetState($var[$i][0],"",@SW_MINIMIZE)
                EndIf
            EndIf
        Next
    EndIf
    
WEnd

Func CLOSEClicked()
    Exit
EndFunc

Func ApplyButton()
    $time = GUICtrlRead($Seconds)
EndFunc

Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then 
    Return 1
  Else
    Return 0
  EndIf
EndFunc
Link to comment
Share on other sites

I added some more checking to the nested loop and I think I have it fixed. It may not be elegant, but it seems to work.

I didn't know if an exitloop would work, so I set the loop to the last value.

#include <GUIConstantsEx.au3>
;Version 1.0 - 12/03/08

$time = 15
$var = WinList()

Opt("GUIOnEventMode", 1)
$msg = GUICreate("Program Switcher", 225, 100)
GUICtrlCreateLabel("Enter the time in seconds:",10,20)
$Seconds = GUICtrlCreateInput("15", 140, 16,25)
$Apply = GUICtrlCreateButton("Apply", 60, 50, 60)
GUICtrlSetOnEvent($Apply, "ApplyButton")
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
WinMinimizeAll()
GUISetState(@SW_SHOW)

While 1
    $msg = GuiGetMsg()
    $state = WinGetState("Program Switcher", "")
    
    If BitAND($state, 16) Then
        WinMinimizeAll()

        For $i = 1 to $var[0][0]
            If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then
                If $var[$i][0] <> "Program Manager" Then
                    
                    $state = WinGetState("Program Switcher", "")
                    If BitAND($state, 8) Then
                        $i = $var[0][0]
                    Else
                        WinSetState($var[$i][0],"",@SW_MAXIMIZE)
                    EndIf
                    
                    $totaltime = $time * 1000
                    
                    $state = WinGetState("Program Switcher", "")
                    If BitAND($state, 8) Then
                        $i = $var[0][0]
                    Else
                        Sleep ($Totaltime)
                    EndIf
                    
                    $state = WinGetState("Program Switcher", "")
                    If BitAND($state, 8) Then
                        $i = $var[0][0]
                    Else
                        WinSetState($var[$i][0],"",@SW_MINIMIZE)
                    EndIf
                    
                EndIf
            EndIf
        Next
    EndIf
    
WEnd

Func CLOSEClicked()
    Exit
EndFunc

Func ApplyButton()
    $time = GUICtrlRead($Seconds)
EndFunc

Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then 
    Return 1
  Else
    Return 0
  EndIf
EndFunc
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...