Jump to content

Rename subsequent windows


Recommended Posts

Please help me how of doing..

Eg :

I open up multiple notepad the default title would be "Untitled - Notepad", instead the first notepad TITLE should be started with 1 then subsequent notepad should be 2, 3 and so on...

I tried using while loop and winsettitle. But the program was not efficient.

!!!AUTOIT Rocks!!!^^^^^^^^^^^^

Link to comment
Share on other sites

Hi,

I use a loop and it seems to be pretty quick for me.

What's not efficient (Apart from the code I post)

Dim $pID[5]
For $i = 0 To 4
    $pID[$i] = Run("notepad.exe")
    Sleep(40)
Next    

Dim $WL = WinList("[REGEXPTITLE:(?i)Untitled - Notepad]")
For $i = 1 To $WL[0][0]
    WinSetTitle($WL[$i][1], "", $i & ": Untitled - Notepad")
Next    

MsgBox(0, "Click OK to exit.", $WL[0][0] & " x Notepads opened and numbered. " & @LF & "Click Ok to close the Notepads and Exit")
For $i = 0 To 4
    ProcessClose($pID[$i])
Next

Cheers

Link to comment
Share on other sites

maybe something like this:

Global $CurNo = 0
While 1
    $var = WinList()
    For $i = 1 to $var[0][0]
      If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then
        for $j = 1 to $var[0][0]
            If $var[$j][0] <> "" AND IsVisible($var[$j][1]) Then
                if $var[$j][0] = $var[$i][0] AND $var[$j][1] <> $var[$i][1] then
                    $CurNo += 1
                    WinSetTitle($var[$i][0], "", $var[$i][0] & " #" & $CurNo/2+1)
                    TrayTip("Window Name Changed", "Window [" & $var[$i][0] & "] allready exists," & @CRLF _
                    & "so it will be changed into:" & @CRLF _
                    & "[" & $var[$i][0] & " #" & $CurNo/2+1 & "]", 10, 1)
                EndIf
            EndIf
        Next
    EndIf
    Next
    Sleep(250)
WEnd
Func IsVisible($handle)
    If BitAnd( WinGetState($handle), 2 ) Then 
        Return 1
    Else
        Return 0
    EndIf
EndFunc

though it has a flaw... if you close notepad and open a new one you still get one No. bigger than the last opened notepad, I'll lave you to fix this flaw :) :)

p.s. No. is displayed at the end of the win title, but you can change this to be at the start of win title.

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