Jump to content
Sign in to follow this  
cdDan

WinActivate not Activating when I use Handles

Recommended Posts

cdDan

Greetings,

I am continuing to develop my first complex AutoIT script and I just want to thank you all for your help so far.

I have a new problem, I can not get WinActivate function to work when I use Handles instead of Titles.

Please see my code snippets:

Global $handleBrowser = ClipGet() ; get browser window handle if any

This grabs the Handle from an Excel cell where my script previously pasted it. This works fine. For example, I now have $handleBrowser = 0x00030DB4

Later I call a function from a custom library I have included...

ElseIf $statusCurrent = $statusPlay Then ; =============Video is or was playing==============
    playToggle()

Here is the playToggle() function:

WinActivate($handleBrowser) ; Go to the browser
    sleep(10)
    ControlFocus($handleBrowser, "", "[CLASS:MacromediaFlashPlayerActiveX; INSTANCE:1]")
    Send("{SPACE}")

So the problem is the window (in this case a browser) never gets activated. I can use the AutoIT window tool to verify the handle's match (variable and actual)...but nothing happens.

I have tried adjusting the options using Opt() to allow for more window delay or to not use exact matches for the windows title search, but to no avail.

The script runs on Win7 64bit and the Browser or Windows I am trying to activate are IE8.

Any thoughts? :idea:

The only strange thing I notice is the Window info tool reports a Handle of: 0x0000000000030DB4 while WinGetHandle gives 0x00030DB4 but I don't think that would matter.

Edited by cdDan

Share this post


Link to post
Share on other sites
jfcby

Welcome to AutoitScript Forum CdDan,

From the help file WinList the following code is a work around to activate a window title from a window handle.

$var = WinList()
For $i = 1 to $var[0][0]
  ; Win handle True
  If $var[$i][1] = 0x00010522 Then
    MsgBox(0, "Details", "Title=" & $var[$i][0] & @LF & "Handle=" & $var[$i][1])
    ; Win Title Activate 
    WinActivate($var[$i][0], "")
  EndIf
Next

jfcby


Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Share this post


Link to post
Share on other sites
hawky358

This is your problem

Global $handleBrowser = ClipGet()
...
...
WinActivate($handleBrowser)

When you copy the handle from the clipboard the type is "String".

What happens then when you use WinActivate() is that it looks for a window with the title 0x.........

Do this and you'll see what I mean

ConsoleWrite(VarGetType($handleBrowser))

What you need it to be is a pointer

So the best way to do it is to store the handle in a variable from the start instead of pasting it then copying it (Seems like a roundabout method)

You'll see here the vartype is a ptr (Pointer)

Opt("WinTitleMatchMode", 2)
$hndl = WinGetHandle("Internet")
ConsoleWrite(VarGetType($hndl))
WinActivate($hndl)

If you must use the copy method (strings) then use the method suggested by jfcby (Winlist then match the handles to the strings)

Edit:Note: I added consolewrites, if you don't use Scite the change them to messageboxes.

Edited by hawky358

Share this post


Link to post
Share on other sites
hawky358

Hey

There's something else you can do as well, which will require minimal editing (If you want to keep the excel method for some reason). Just change the string into a pointer

Global $handleBrowser = ClipGet() 
$handleBrowser = Ptr($handleBrowser)

or just

Global $handleBrowser = Ptr(ClipGet())

Share this post


Link to post
Share on other sites
cdDan

Thank you everyone! I am going to try each method posted here until I get them working for good practice.

I really appreciate everyone's help here. I've been watching out for a post I can answer to try and even things out because so far I have only asked questions. It's tough to find someone newer than me though.

Thank you again.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.