Jump to content

Recommended Posts

Posted

if i have more then one open with the same title, how do i open the last one that has been open?

You need to use the window handle which is unique for every window.

Monitor when the active window changes and save its handle if it's not your window.

This quick example might help explain.

$last = -1
$mygui = wingethandle("Title of my gui")
HotKeySet("^{F6}", "ex")

While 1

    $now = WinGetHandle("[ACTIVE]")
    If $now <> 0 And $now <> $last and $now <> $mygui Then
        ConsoleWrite(WinGetTitle($now) & " has handle " & Hex($now) & @CRLF)
        $last = $now
    EndIf

WEnd

Func ex()
    Exit
EndFunc   ;==>ex
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Posted (edited)

You need to use the window handle which is unique for every window.

Monitor when the active window changes and save its handle if it's not your window.

This quick example might help explain.

$last = -1
$mygui = wingethandle("Title of my gui")
HotKeySet("^{F6}", "ex")

While 1

    $now = WinGetHandle("[ACTIVE]")
    If $now <> 0 And $now <> $last and $now <> $mygui Then
        ConsoleWrite(WinGetTitle($now) & " has handle " & Hex($now) & @CRLF)
        $last = $now
    EndIf

WEnd

Func ex()
    Exit
EndFunc   ;==>ex

i already know how to obtain the PID and to bring up the window according to the PID i choose... but i wanted to know if you can use WinActivate() to just open the last window created with the same title (it auto opens the first one) Edited by SomeoneHere
Posted

Given a a window title, AutoIt will open the first window it finds that matches. I am not sure WinActive works but I would suspect it works something iterating through the results of WinList then making the first match found active. If you are searching by title and there are two windows that have the same title, it can't tell the difference.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Posted

but i wanted to know if you can use WinActivate() to just open the last window created with the same title

No, you can't. You must use the handle (not the PID).
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Posted

No, you can't.

Sure?

What about searching within the array returned by WinList() for the last match of the title and using that handle. (Maybe the last one started, and not the last one the user had active.)

Posted

@minimax - martin is correct, you can't. I understand your suggestion however there is no way to guarantee the order returned from WinList(). You have no way of telling which one it will be in the array and the order will change each time WinList() is called.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...