Jump to content

Window Class & Instance help


Recommended Posts

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.

Link to comment
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!

Link to comment
Share on other sites

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
Link to comment
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!

Link to comment
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!

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

×
×
  • Create New...