Jump to content

Detect a 'button' that only appears as a progress bar object


Lycan
 Share

Recommended Posts

Hi again,

On to my next headache, now that I have the zoom sorted (thanks LarsJ!) I have to find a way to identify if the diagram has completed redrawing with the new ratio.

Unfortunately the code behind it doesn't even change the cursor to busy, the only thing that I can see that identifies if the redraw has completed is a type of progress bar (of type "button") that only shows up in inspect.exe when the redaw is occurring.  SimpleSpy can't capture it as it occurs either too quickly or if it's there for a while it's because the CPU is maxed out and SimpleSpy doesn't capture the Ctrl-W in time.

Honestly, I have no idea where to start.  Any help is appreciated.

AutoIT_magzoom4.PNG

Link to comment
Share on other sites

You can try

$oValue.SetValue( "0.500" & @CR )

 


You can try adding this code to the previous code

; --- Detect "Loading" button ---

  ConsoleWrite( "--- Detect ""Loading"" button ---" & @CRLF )

  $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_ButtonControlTypeId, $pCondition1 )
  If Not $pCondition1 Then Return ConsoleWrite( "$pCondition1 ERR" & @CRLF )
  ConsoleWrite( "$pCondition1 OK" & @CRLF )

  $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "GRTV Values Loading", $pCondition2 )
  If Not $pCondition2 Then Return ConsoleWrite( "$pCondition2 ERR" & @CRLF )
  ConsoleWrite( "$pCondition2 OK" & @CRLF )

  ; And condition
  $oUIAutomation.CreateAndCondition( $pCondition1, $pCondition2, $pCondition )
  If Not $pCondition Then Return ConsoleWrite( "$pCondition ERR" & @CRLF )
  ConsoleWrite( "$pCondition OK" & @CRLF )

  $pButton = 0
  Local $hTimer = TimerInit()
  While Not $pButton And TimerDiff( $hTimer ) < 3000 ; Wait for max 3 seconds
    $oNetworkDisplay.FindFirst( $TreeScope_Descendants, $pCondition, $pButton )
    Sleep( 50 ) ; 20 times per second
  WEnd
  If Not $pButton Then Return ConsoleWrite( "Detect ""Loading"" button ERR" & @CRLF )
  ConsoleWrite( "Detect ""Loading"" button OK" & @CRLF )

  ; --- Detect "Loading" done ---

  ConsoleWrite( "--- Detect ""Loading"" done ---" & @CRLF )

  ; $pButton > 0 means that loading is still going on
  ; $pButton = 0 means that loading is done and button has disappeared
  While $pButton And TimerDiff( $hTimer ) < 6000 ; Wait for max 6 seconds in total
    $oNetworkDisplay.FindFirst( $TreeScope_Descendants, $pCondition, $pButton )
    Sleep( 50 ) ; 20 times per second
  WEnd
  If $pButton Then Return ConsoleWrite( "Detect ""Loading"" done ERR" & @CRLF )
  ConsoleWrite( "Detect ""Loading"" done OK" & @CRLF )

 

Link to comment
Share on other sites

6 hours ago, LarsJ said:

You can try

$oValue.SetValue( "0.500" & @CR )

>>> hmm strange enough, neither that nor @CRLF worked - but when I dropped it back to Send("{ENTER}") it worked fine.  Bizarre?

You can try adding this code to the previous code

; --- Detect "Loading" button ---

  ConsoleWrite( "--- Detect ""Loading"" button ---" & @CRLF )

  $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_ButtonControlTypeId, $pCondition1 )
  If Not $pCondition1 Then Return ConsoleWrite( "$pCondition1 ERR" & @CRLF )
  ConsoleWrite( "$pCondition1 OK" & @CRLF )

  $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "GRTV Values Loading", $pCondition2 )
  If Not $pCondition2 Then Return ConsoleWrite( "$pCondition2 ERR" & @CRLF )
  ConsoleWrite( "$pCondition2 OK" & @CRLF )

  ; And condition
  $oUIAutomation.CreateAndCondition( $pCondition1, $pCondition2, $pCondition )
  If Not $pCondition Then Return ConsoleWrite( "$pCondition ERR" & @CRLF )
  ConsoleWrite( "$pCondition OK" & @CRLF )

  $pButton = 0
  Local $hTimer = TimerInit()
  While Not $pButton And TimerDiff( $hTimer ) < 3000 ; Wait for max 3 seconds
    $oNetworkDisplay.FindFirst( $TreeScope_Descendants, $pCondition, $pButton )
    Sleep( 50 ) ; 20 times per second
  WEnd
  If Not $pButton Then Return ConsoleWrite( "Detect ""Loading"" button ERR" & @CRLF )
  ConsoleWrite( "Detect ""Loading"" button OK" & @CRLF )

  ; --- Detect "Loading" done ---

  ConsoleWrite( "--- Detect ""Loading"" done ---" & @CRLF )

  ; $pButton > 0 means that loading is still going on
  ; $pButton = 0 means that loading is done and button has disappeared
  While $pButton And TimerDiff( $hTimer ) < 6000 ; Wait for max 6 seconds in total
    $oNetworkDisplay.FindFirst( $TreeScope_Descendants, $pCondition, $pButton )
    Sleep( 50 ) ; 20 times per second
  WEnd
  If $pButton Then Return ConsoleWrite( "Detect ""Loading"" done ERR" & @CRLF )
  ConsoleWrite( "Detect ""Loading"" done OK" & @CRLF )

 

Man more beautiful code :-o  Thanks again :-) 

Going through the logic, the first while loop waits for a maximum of 3 seconds whilst looking for the button to appear and then sets the pButton value to > 0

The second while loop waits a maximum of 6 seconds for the load to finish completely and the button to disappear.  ok fair enough, I've tweaked those values to suite.

I also had to add in a little bit of code to increase (and decrease, at the end) the priority of the AutoIT process during this run, otherwise the Application being automated would hog all the CPU cycles and the loops wouldn't get a chance to check within their time limits (so by the time they got CPU cycles, the button had already disappeared).  As I'm using the predefined variable @AutoITPID, I'm curious how that will work when I compile the script into a .exe

Thanks again LarsJ :-)  That's some elegantly brilliant coding there and I'm indebted to you :-)

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