Jump to content
Sign in to follow this  
amanda089

Window Class & Instance help

Recommended Posts

amanda089

I'm trying to automate some things utilizing both firefox and chrome and a flash website. I would like to know the best and fastest way to correctly identify the flash control (and instance) for both browsers.

Here is the code that I use now. I had to remove the instance checking because it wasn't identifying anything.

Called in every loop of the main program:

Func CheckHWnd($HWnd, $Call)
Local $size = WinGetPos($HWnd)
Select
  Case (Not IsArray($size) Or Not IsDeclared($size[3])) Or $HWnd = ""
   Call($Call)
   Return
  Case Else
   If ($size[2] <> 1024 Or $size[3] <> 820) Then Call($Call)
EndSelect
EndFunc   ;==>CheckHWnd

The above function will call either of these functions:

Func GetFireFox()
Local $classlist = StringSplit(WinGetClassList($Title_Firefox, ""), @LF, 2)
Local $PluginWindows = _ArrayFindAll($classlist, "GeckoPluginWindow")
For $flash = 0 To (UBound($PluginWindows) - 1)
  Local $str = "[CLASS:GeckoPluginWindow]"
  Local $FFC = ControlGetHandle($Title_Firefox, "", $str)
  Local $posi = WinGetPos($FFC, "")
  If ($posi[2] = 1024) Then
   $FF_Pos = $posi
   $FireFoxCtrl = $FFC
   Return $FFC
  EndIf
Next
Return $FireFoxCtrl
EndFunc   ;==>GetFireFox
 
Func GetChrome()
Local $classlist = StringSplit(WinGetClassList($Title_Chrome, ""), @LF, 2)
Local $PluginWindows = _ArrayFindAll($classlist, "NativeWindowClass")
For $flash = 0 To (UBound($PluginWindows) - 1)
  Local $str = "[CLASS:NativeWindowClass]"
  Local $CHC = ControlGetHandle($Title_Chrome, "", $str)
  Local $posi = WinGetPos($CHC, "")
  If ($posi[2] = 1024) Then
   $CH_Pos = $posi
   $ChromeCtrl = $CHC
   Return $CHC
  EndIf
Next
Return $ChromeCtrl
EndFunc   ;==>GetChrome

I use the returned HWnd pointer in both direct drawing and in these functions:

Func FirefoxClick($x, $y)
ControlClick("", "", $FireFoxCtrl, "primary", 1, $x, $y)
EndFunc   ;==>FirefoxClick

Func ChromeClick($x, $y)
ControlClick("", "", $ChromeCtrl, "primary", 1, $x, $y)
EndFunc   ;==>ChromeClick

The direct drawing (a cross and text, found in these forums) and the clicking work correctly, when the pointer is valid. But, say, when the window in chrome is refreshed and the flash plugin instance is incremented. It doesn't return the correct pointer at all.

If you know of any ways to optimize this code, or correctly identify the instance number, I would much appreciate it.

Share this post


Link to post
Share on other sites
kaotkbliss

What does controlgethandle return before and after the refresh? How about for each multiple refresh? Maybe there's a pattern you can use to predict what it will be when it refreshes?


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites
amanda089

It depends on the instance and if there is another instance in a different tab. That is the confusing part. the instance number only changes with additional websites that use plugins such as java or flash.

You can test the code out yourself by opening a flash website in both browsers, etc.

Edited by amanda089

Share this post


Link to post
Share on other sites
kaotkbliss

Just thinking out loud..

Maybe if you kept track of each PID in an array as more instances are opened, you can get the correct control for each PID and add that to the array (multi-demension array)

then you could have your code see which instance it's looking at and "look-up" the control from the array? Maybe?


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites
amanda089

Grr, I hate using arrays or more variables than I need to. Particularly since I'm already using 4 byte ptr's and having to check if they are still valid every loop

Share this post


Link to post
Share on other sites
kaotkbliss

That's the only thing I can think up right now :graduated:

I haven't really done much yet in the way of automating flash and web browsers so I'm a bit limited


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • ur
      By ur
      An application is there which is created using vc++,mostly mfc.
       
      DOn't know the details completely.
       
      WHen I try to automate the control clicks for testing the UI.
      THe below control is not detected.
      As you can see, during UI operations I can click the elements one by one.
      But all the elements is selected as a whole set, when I use the Windowinfo tool.

       
      How to click this using AutoIT.?
       
      Please suggest.
    • Pricehacker
      By Pricehacker
      Hello again!
      I have tried searching for quite some time now but couldn´t find a single working way to change the class of your GUI that doesn´t include changing it manually after its compilation.
      First or "AutoIt v3 GUI" is a pretty boring name tbh and i would like to spice it up a bit, also, and more importantly, I would like to identify my windows by something other than its title as it will change depending on some factors and im using two different programs independently as multi threading isn't supported.
      Any help is appreciated! Thank you!
    • bbProg
      By bbProg
      Hi,
       
      how can I wait activate for windows with information as in the photos attached?
      Class is not being recognized by the script.
       
      thanks in advanced.



    • nacerbaaziz
      By nacerbaaziz

      Hi dear
      This is the first include file I designed
      This work is especially directed to NVDA free screen reader users
      It contains a set of functions that enable you to control the program
      Such as forcing the program to read a custom text
      Force it to stop talking
      Find out if the program is running
      And show custom text in the Braille screen
      Available functions are
      _nvdaControllerClient_Load()
      to load the dll file
      _nvdaControllerClient_free()
      to UnLoad the dll file
      _nvdaControllerClient_SpeakText()
      to speak a custom text
      _nvdaControllerClient_brailleMessage()
      to show custom text in the Braille screen
      _nvdaControllerClient_cancelSpeech()
      to Force the NVDA  to stop talking
      _nvdaControllerClient_testIfRunning()
      to check if the NVDA is running
      important note :
      All of these functions depend on a nvdaControllerClient32.dll
      I've added it in the attachments, as well as a file for examples, and other files
      As the source and examples in other languages
      For those who wanted to download the free screen reader, this is the download link from the official website
      https://www.nvaccess.org/download/
      i hope you like this topic
      I hope you will try it and give me your opinions
      Thank you all members and administrators for their help
      now with the  Attachments
       
      nvdaControllerClient_UDF.zip
    • RHolmes
      By RHolmes
      I wrote a script a few months ago that was working at the time. When I tried it today it wouldn't retrieve any controls.  The application successfully launches, but I cannot figure out how to retrieve the control from the window that is launched. I'm on a windows 10 machine using AutoIt v3.3.14.2. The only thing I can think of that has changed is windows updates? Code is below, any help is greatly appreciated.    ; Notes: ; HandleError( handleToCheck, MsgToLogOnFailure, terminateAutoItOnFail ) : function that simply checks the handle and quits AutoIt if not present ; all of this works well FileChangeDir( $CLIENT_APPLICATION_DIR ); Run( "Client.exe" ) Local $hClient = WinWaitActive( $CLIENT_TITLE, "", 10 ) $terminateOnFail = 1 HandleError( $hClient, "LaunchClient::Error: Failed to launch client. Either timed-out or failed.", $terminateOnFail ) LogToFile( "Client launched, waiting for system to ready." ) Sleep( 5000 ) ; this part does not work ; $SYSTEM_INDICATOR is a global variable. I have tried these values: "SystemIndicatorWindow" (Text), "Qt5QWindowIcon101" (ClassNN), and ; "[CLASS:Qt5QWindowIcon; INSTANCE:101]" Local $hStatusIndicator = ControlGetHandle( $hClient, "", $SYSTEM_INDICATOR ) HandleError( $hStatusIndicator, "CheckStatus::Error: couldn't retrieve control: " & $SYSTEM_INDICATOR, $terminateOnFail ) This is what the spy reveals: 

       
      Edit: I just tried this code and it works for notepad++.
      FileChangeDir( "C:\Program Files\Notepad++\" ); Run( "notepad++.exe" ) Local $hNotePad = WinWaitActive( "new 1 - Notepad++", "", 10 ) If $hNotePad = 0 Or $hNotePad = -1 Then MsgBox( $MB_SYSTEMMODAL, "Error", "Error getting app handle." ) EndIf Sleep( 1000 ) Local $hNewFileBtn = ControlGetHandle( $hNotePad, "", "[CLASS:ToolbarWindow32; INSTANCE:1]" ) If $hNewFileBtn = 0 Or $hNewFileBtn = -1 Then MsgBox( $MB_SYSTEMMODAL, "Error", "Error getting button handle." ) EndIf MsgBox( $MB_SYSTEMMODAL, "Success", "Success." )  
×