Sign in to follow this  
Followers 0
amanda089

Window Class & Instance help

6 posts in this topic

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



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

#3 ·  Posted (edited)

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

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

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

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  
Followers 0

  • Similar Content

    • robcull
      By robcull
      Hello all! I have had some issues reading text from different types of windows, occasionally, specifically with controlgettext. 
      **Before I begin, I know there are better ways to do what I attempt in the example below. That's not the point of this post. The point is my issues with controlgettext. 
      I am about to cite an example with an application you may be familiar with called SpeedFan (v4.52). My problem is not specific to speedfan, it is simply the most recent and easily reproducible example I can think of. 
      So, the goal of the script below is to get a string of text containing the current fan RPMs from the highlighted control in the screenshot below (see "speedfan_control_details.png").

      Now, here's a simple script for grabbing the window handle and reading the text from that control: 
      $wintitle = "SpeedFan 4.52" $controlID = "197934" ;will be reformatted as "[ID:######]" $hwnd = wingethandle($wintitle) if @error<>0 then msgbox(0, "WinGetHandle", "FAILURE. @error="&@error) Exit EndIf $text = ControlGetText($hwnd, "", "[ID:"&$controlID&"]") if @error=1 then msgbox(0, "ControlGetText", "FAILURE. @error="&@error) ;failure returns "" and @error=1 Exit EndIf msgbox (0, "ControlGetText", "SUCCESS. @error="&@error &@CRLF& "$text="&$text) ;success returns string and @error=0 You'll see that the ControlGetText operation runs without error, however it does not capture any text from the control. If you explore the other controls in this one window, you'll find mixed results across the board. Neither the temps nor voltages can be read, while the log field and some other elements can be read. Even when you read the text from the whole window, those elements are not included in the visible nor hidden texts. 
       
      I have run into this issue many times in the past- inconsistencies in the ability of autoit to interact with certain controls. What is it which makes this text different than any other readable texts? Is there an alternate method of reading the text in the window/control which could work? Any and all info to help me solve this mystery and satisfy my curiosity would be greatly appreciated. 
      Thanks  -Rob C
      PS: Running Autoit v3.3.14.2 on Win7 Ultimate x64
    • Jibberish
      By Jibberish
      Hi,
      I am maybe an intermediate AutoIt script writer, but have no experience creating GUIs.
      I have a script with two functions. One for Checkboxes and another with radio buttons. Each function creates it's own window.
      I'd like to use one window with both checkboxes and radio buttons.
      I pulled samples from AutoIt Help and other places and worked it into this: (RadioCheck still uses the example Case and MsgBoxes. I will clean this up soon)
      Func CheckOptions() ; Create a GUI with various controls. Local $hGUI = GUICreate("SGX4CP Options", 275, 250) ; Create a checkbox control. Local $iLoopCheckbox = GUICtrlCreateCheckbox("Loop", 10, 10, 185, 25) Local $iFullScreenCheckbox = GUICtrlCreateCheckbox("Fullscreen", 10, 40, 185, 25) Local $iRestartPlaybackCheckbox = GUICtrlCreateCheckbox("Restart Playback from Sleep", 10, 70, 185, 25) GUICtrlSetState($iRestartPlaybackCheckbox, $GUI_CHECKED) Local $iDisableSleepCheckbox = GUICtrlCreateCheckbox("Disable Sleep", 10, 100, 185, 25) Local $iLogCheckbox = GUICtrlCreateCheckbox("Show Log", 10, 130, 185, 25) GUICtrlSetState($iLogCheckbox, $GUI_CHECKED) Local $idClose = GUICtrlCreateButton("Next", 110, 220, 85, 25) ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idClose ExitLoop Case $iLoopCheckbox If _IsChecked($iLoopCheckbox) Then $bLoopChecked = True Else $bLoopChecked = False EndIf Case $iFullScreenCheckbox if _IsChecked($iFullScreenCheckbox) Then $bFullScreenChecked = True Else $bFullScreenChecked = False EndIf Case $iRestartPlaybackCheckbox if _IsChecked($iRestartPlaybackCheckbox) Then $bRestartPlaybackChecked = True Else $bRestartPlaybackChecked = False EndIf Case $iDisableSleepCheckbox if _IsChecked($iDisableSleepCheckbox) Then $bDisableSleepChecked = True Else $bDisableSleepChecked = False EndIf Case $iLogCheckbox if _IsChecked($iLogCheckbox) Then $bLogChecked = True Else $bLogChecked = False EndIf EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc Func RadioCheck() GUICreate("Select Test",300,180) ; will create a dialog box that when displayed is centered Local $idRadio1 = GUICtrlCreateRadio("Loop Forever", 10, 10) Local $idRadio2 = GUICtrlCreateRadio("Play each video 3 times", 10, 40) Local $idRadio3 = GUICtrlCreateRadio("Play each video separately", 10, 70) GUICtrlSetState($idRadio1, $GUI_CHECKED) Local $idClose = GUICtrlCreateButton("Start Test", 120,100) GUISetState(@SW_SHOW) Local $idMsg ; Loop until the user exits. While 1 $idMsg = GUIGetMsg() Select Case $idMsg = $GUI_EVENT_CLOSE ExitLoop Case $idMsg = $idRadio1 And BitAND(GUICtrlRead($idRadio1), $GUI_CHECKED) = $GUI_CHECKED MsgBox($MB_SYSTEMMODAL, 'Info:', 'The app will run forever, playing each video once, then looping back to the first video.') $bTestSelectForever = True Case $idMsg = $idRadio2 And BitAND(GUICtrlRead($idRadio2), $GUI_CHECKED) = $GUI_CHECKED MsgBox($MB_SYSTEMMODAL, 'Info:', 'Each video will loop 3 times then move to the next video.') $bTestSelect3Times = True Case $idMsg = $idRadio3 And BitAND(GUICtrlRead($idRadio2), $GUI_CHECKED) = $GUI_CHECKED MsgBox($MB_SYSTEMMODAL, 'Info:', 'Player opens, first video plays, player closes. Player opens, second video plays, player closes, etc.') $bTestSelectSingleVideo = True EndSelect WEnd EndFunc I would like to combine the checkbox "Loop" and the radio button $idRadio2. Radio2 requires Loop to be checked.
      I planned to remove the Loop checkbox and only enable it if Radio2 is selected.
      Can I combine these two functions into one with one window with both Checkboxes and Radio Buttons?
      Thanks
      Jibberish
    • nacerbaaziz
      By nacerbaaziz
      Hi friends, I have a question, please.
      I have created a window containing a edit box
      I need to know how to change the keyboard language,
      e.g :
      if a user open the  script  it will be change the keyBord language   in window automatically into English
      I found more examples but didn't work with me .
      Note:  
       I use the windows 10 os
      Please help me .
      thanks in advance to all
      with my Greetings and my appreciation for all users and admins
    • Skeletor
      By Skeletor
      Hi Guys, 
      So with me working in my Virtual Machines in full screen, I often have my Host OS playing music. Now the issue I had was trying to control the Host OS without having to minimise the Guest OS.
      So I thought of this small program. I call it the Volume Control. It resides in the bottom right hand corner of your screen just above the system clock. 
      I'm still working on getting the volume buttons to increase/decrease when you hold down the button.
      Currently, you will need to tap on the volume buttons numerous times to decrease/increase the volume. 
      Any other improvements let me know. 
      The source code, icon and compiled program are already in the zip. 
       

       
      Volume Controlv1.zip
      Screenshot.bmp
    • Psyllex
      By Psyllex
      I have a super simple login screen I'm trying to access that is written in java.  My java testing tools can't access the login screen because it's a modal window.  So I figured I'd see if AutoIt can manipulate 'something' on it.  I can enter text within the text boxes for user name and password.  But I can't see to click on the login button.  I've tried just tabbing to it and hitting the enter key (as I really wouldn't have to be completely interacting with the frame).  But that didn't work.  I was hoping to throw it some coordinates and just double click in that relative area, but when I get the whole " ==> Subscript used on non-accessible variable.:" when I attempt to use ControlGetPos() I'm assuming because it can't truly interact with the Java frame.  So I'm kind of stuck here...can't use AutoIt, can't use a Java automation testing tool to do this due to the modal issues.  Does anyone have any ideas?  My code is below though I think it's less to do with code and more what AutoIt can and can't do.
      #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Local $hWnd = WinActivate("[CLASS:sunawtframe]", "Login") Local $aPos = ControlGetPos($hWnd, "[CLASS:SUNAWTFRAME]", "Login") Local $myXPos = $aPos[0] + 420 Local $myYPos = $aPos[1] + 270 Send("guest") Send("{TAB}") Send("guest") Send("{TAB}") ;Tried Control Click it failed ControlClick($hWnd, "", "Login") ;Tried Mouse Click and that failed MouseClick("Left", $myXPos, $myYPos, 2)  
      Thanks for any help!