Jump to content

Flexibile Window Catcher


Recommended Posts

Hello all,

I'm working on a major deployment and some packages that their software management system drops have window errors. I want to be able to plan for these errors on the fly so I created the Window Title, Window Text, and Button to press in an INI file as such:

[ERRORWINDOWTITLE]
WINDOW1=ERROR WINDOW TEST 3
WINDOW2=ERROR WINDOW TEST2
WINDOW3=ERROR WINDOW TEST2

[ERRORWINDOWTEXT]
WINDOW1=
WINDOW2=
WINDOW3=THIS IS SOME TEXT

[ERRORWINDOWBUTTON]
WINDOW1=Button1
WINDOW2=Button1
WINDOW3=Button1

I'm going to be adding window titles, text, and buttons to this INI file so that I only have to manage the INI file and NOT the script.

I created a script that I want to launch and constantly look for these windows.

Opt('TrayIconHide', 1)
$windowtitlearray = IniReadSection(@ScriptDir & '\errorcatch.ini', 'ERRORWINDOWTITLE')
    While 1
               For $a = 1 to $windowtitlearray[0][0]
            $windowtitle = $windowtitlearray[$a][1]
            $windowtext = Iniread(@ScriptDir & '\errorcatch.ini', 'ERRORWINDOWTEXT', $windowtitlearray[$a][0], '')
            $windowbutton = Iniread(@ScriptDir & '\errorcatch.ini', 'ERRORWINDOWBUTTON', $windowtitlearray[$a][0], '')
        ;MsgBox(0, 'window info', $windowtitle & ' ' & $windowtext & ' ' & $windowbutton)
            If WinExists($windowtitle) Then
                ControlClick($windowtitle, $windowtext, $windowbutton)
                EndIf
    Next
        
    WEnd

This works but CHEWS up memory. What am I doing all wrong? I think I need to define the windows, text and button to search for before I enter the while loop and then have the while loop call that as a function but I am perplexed on how to do it. Any ideas on how to do that?

Link to comment
Share on other sites

This works but CHEWS up memory. What am I doing all wrong? I think I need to define the windows, text and button to search for before I enter the while loop and then have the while loop call that as a function but I am perplexed on how to do it. Any ideas on how to do that?

The INI file presumably doesn't change while the script is running, so read it ONCE into an array or two and work with the arrays for your loops.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

You're right, the INI file does NOT change. However, I need to run the WinExist and Control click against any one of the windows. I am having a hard time wrapping my head around this one. Any more ideas would be greatly appreciated PsaltyDS!!! Thank you!

-redfive

Link to comment
Share on other sites

You could do a switch - case method also. I've found when you do a bunch of winactives in a loop, it causes processor hunger. THe only way I got around it is to break it down into a tree. Have 3 windows or so that have everything in common, then branch off from those three. It is messy, but it works.

Link to comment
Share on other sites

What I wish I could do is read everything into memory and build If ElseIf statements in a while loop.

Go back and re-read post #2 in this topic! :)

HotKeySet("^q", "_Quit") ; Ctrl-Q to quit

Global $sINI = @ScriptDir & '\errorcatch.ini'
Global $avTitle = IniReadSection($sINI, "ErrorWindowTitle")
Global $avText = IniReadSection($sINI, "ErrorWindowText")
Global $avButton = IniReadSection($sINI, "ErrorWindowButton")

While 1
    _TestWindows()
    Sleep(100)
WEnd

Func _TestWindows()
    For $w = 1 To $avTitle[0][0]
        If WinExists($avTitle[$w][1], $avText[$w][1]) Then
            WinActivate($avTitle[$w][1], $avText[$w][1])
            WinWaitActive($avTitle[$w][1], $avText[$w][1])
            ControlFocus($avTitle[$w][1], $avText[$w][1], $avButton[$w][1])
            ControlClick($avTitle[$w][1], $avText[$w][1], $avButton[$w][1])
        EndIf
    Next
EndFunc   ;==>_TestWindows

Func _Quit()
    Exit
EndFunc   ;==>_Quit

:P

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...