Jump to content

Help with using arrays


Recommended Posts

I'm trying to make a program to add the current window's title to an array on a hot key, and then on another hotkey hide all the windows in that array (toggle).

This is what I have, it runs and compiles but for some reason it doesn't work. I havn't worked with arrays in AutoIt v3, so I don't know the exact syntax and all that good stuff.

HotKeySet("{END}","go")
HotKeySet("{HOME}","add")
HotKeySet("{PAUSE}","hotExit")
Opt("WinTitleMatchMode","2")
Opt("TrayIconHide",1)
$state = "active"
Dim $windows[10];max of 10

While 1
WEnd

Func add()
   Assign($windows[UBound("windows")],WinGetTitle("",""))
EndFunc

Func go()
   Local $dim = UBound("windows")
   Assign("dim","dim" - 1)
   If $state = "active" Then
      Assign("state","hiden")
      For $i = 0 to $dim Step 1
         WinSetState($windows[$i],"",@SW_HIDE)
      Next
   Else
      Assign("state","active")
      For $i = 0 to $dim Step 1
         WinSetState($windows[$i],"",@SW_SHOW)
      Next
   EndIf
EndFunc

Func hotExit()
   If $state = "hiden" Then
      go()
   EndIf
   Exit
EndFunc

Any help would be grand! :(

Link to comment
Share on other sites

something for you to look at:

Edit: I didn't debug real good, so might be some logic problems with hitting hotkeys etc...

HotKeySet("{END}","go")
HotKeySet("{HOME}","add")
HotKeySet("{PAUSE}","hotExit")
Opt("WinTitleMatchMode","2")
Opt("TrayIconHide",1)
$state = "active"
Dim $windows
Dim $hidden

While 1
WEnd

Func add()
    $windows = WinList()
EndFunc

Func go()
   If $state = "active" Then
      Assign("state","hidden")
      For $i = 1 to $windows[0][0] Step 1
            If $windows[$i][0] <> "" And $windows[$i][0] <> "Program Manager"  And BitAND(WinGetState($windows[$i][0]), 2) Then
                If IsArray($hidden) Then
                    ReDim $hidden[UBound($hidden) + 1]
                Else
                    Dim $hidden[1]
                EndIf
                $hidden[UBound($hidden) - 1] = $windows[$i][0]
                WinSetState($windows[$i][0],"",@SW_HIDE)
            EndIf
      Next
   Else
      Assign("state","active")
      For $i = 0 to UBound($hidden) - 1 Step 1
            WinSetState($hidden[$i],"",@SW_SHOW)
      Next
   EndIf
EndFunc

Func hotExit()
   If $state = "hidden" Then
      go()
   EndIf
   Exit
EndFunc
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Well...I'm trying to work with that. The code you gave me hides and unhides ALL windows. I want the user to select them. Here is an update on my code...I'm having problems working the matrix to make it add the window title to the matrix...What I need is an ArrayList like in Java :(.

#include <Array.au3>
HotKeySet("{END}","go")
HotKeySet("{HOME}","add")
HotKeySet("{PAUSE}","hotExit")
Opt("WinTitleMatchMode","2")
Opt("TrayIconHide",1)

Dim $windows[10][1]

While 1
WEnd

Func add()
   For $i = 0 to 11 Step 1
      If $windows[$i] = "" Then
      _ArrayInsert($windows,$i,WinGetTitle("",""))
      _ArrayInsert($windows[$i],0,"active")
      EndIf
   Next
EndFunc

Func go()
   For $i = 1 to UBound($windows,0) Step 1
      If $windows[$i][1] = "active" Then
         Assign($windows[$i][1],"hidden")
         WinSetState($windows[$i][0],"",@SW_HIDE)
      Else
         Assign($windows[$i][1],"active")
         WinSetState($windows[$i][0],"",@SW_SHOW)
      EndIf
   Next
EndFunc

Func showAll()
   For $i = 1 to UBound($windows,0) Step 1
      WinSetState($windows[$i][0],"",@SW_SHOW)
      Assign($windows[$i][1],"active")
   Next
EndFunc

Func hotExit()
   showAll()
   Exit
EndFunc
Edited by ending
Link to comment
Share on other sites

look at #74823 topic

It does transparency but lets the user select the window, probably adapt to what your trying to do, don't need a matrix

how is the user going to select an item from an array? Need to build a gui with a listbox.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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...