Jump to content

active window question


klaus.s
 Share

Recommended Posts

It's already too late to figure that out. When you click on the quick launch button focus is diverted there and there is no window focus history that you can look at.

Dale

If I start a script by click on a quick launch button, how can I know which window was active before the click?

Thanks,

-- Klaus

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

It's already too late to figure that out. When you click on the quick launch button focus is diverted there and there is no window focus history that you can look at.

Thanks for your quick reply. I thought already about sending Alt+ESC, which should reactivate the last opened window, but this would also need checking if there is any window opened at all. Maybe there is another workaround preferably without Send, just to see which was the last opened window?

Thanks,

-- Klaus

Link to comment
Share on other sites

i did it like this

Send("!{TAB}")
$var = WinList()

For $i = 1 to $var[0][0]
 ; Only display visble windows that have a title
  If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then
    ExitLoop
;MsgBox(0, "Details", "The Active Window Title = " & $var[$i][0] & "  ")
  EndIf
Next

Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 8 ) Then 
    Return 1
  Else
    Return 0
  EndIf

EndFunc

;;;;;;;;;;;; this is my script

#include <GUIConstants.au3>

GUICreate("My GUI", 500, 150) ; will create a dialog box that when displayed is centered


$widthCell=70
GUICtrlCreateLabel ( $var[$i][0],  20, 20, 400, 40); display the active window


GUISetState ()   ; will display an empty dialog box

; Run the GUI until the dialog is closed
Do
    $msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE

i also compiled it and placed a shortcut in the quick-launch and it worked

8)

NEWHeader1.png

Link to comment
Share on other sites

I stand corrected... there obviously is an active window history list since both Alt-Tab and Alt-Esc have access to it. I never noticed before that the order of windows displayed by Alt-Tab changed based upon when they were last active.

Dale

It's already too late to figure that out. When you click on the quick launch button focus is diverted there and there is no window focus history that you can look at.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

From AutoIt Help, Function Reference, WinActivate

If multiple windows match the criteria, the window that was most recently active is the one activated.

Wouldn't that mean: if I rename all windows except the current to "a" , WinActivate("a") will take me to the last active window?

-- Klaus

Link to comment
Share on other sites

Thanks for this hint. I found some more informations in

MSDN Home > MSDN Library > Win32 and COM Development > User Interface > Windows User Interface > Windowing > Windows >

For now it seems the Z-order can be accessed only via Alt+Esc and Alt-Tab.

-- Klaus

What do you mean "only via"? The site clearly states that you can use the Windows API function GetNextWindow() to retrieve the previous window in the Z-Order. Take a look at that function and you'll see that its both trivial to implement using DllCall() and also that the function has a lot more power than briefly mentioned so you can traverse the entire Z-Order if you wish.
Link to comment
Share on other sites

What do you mean "only via"?

There is no other way than ...

Take a look at that function and you'll see that its both trivial to implement using DllCall() and also that the function has a lot more power than briefly mentioned so you can traverse the entire Z-Order if you wish.

Thanks for guiding me to DllCall. I tried it now, but no luck with GetNextWindow().

But probably I am not alone ;)

AutoIt Forums > AutoIt v3 > v3 Support > Dll Call Question

Here the method I mentioned before

Func GetOpenWindow()
  Local $w, $n, $i, $t, $h, $s, $r
  
  $w= WinList()
  $n= $w[0][0]
  
  For $i=1 To $n
    $t= $w[$i][0]
    $h= $w[$i][1]
    $s= WinGetState( $h)
    If $t = "" OR $t = "SysFader" Then
    ElseIf BitAND( $s, 18) = 2 Then; visible and not minimized
      WinSetTitle( $h, "", "a")
    Else
      WinSetTitle( $h, "", "b")
    Endif  
  Next
  
  $r= WinGetHandle( "a")
  
  For $i=1 To $n
    $t= $w[$i][0]
    If $t <> "" Then WinSetTitle( $w[$i][1], "", $t)
  Next
  
  return $r
EndFunc  

$h= 0
$t0= TimerInit()
; Send( "!{ESC}"); ~ 27 ms
$h= GetOpenWindow(); ~ 20 ms
$dt= TimerDiff( $t0)

MsgBox( 0, "GetOpenWindow", WinGetTitle($h) & @LF & $dt)

I think this works for me. How about building something similar into AutoIt?

-- Klaus

Edit: I prefer now the dll method, see my next post below.

Edited by klaus.s
Link to comment
Share on other sites

There is no other way than ...

Thank you but I am quite aware of what the definition of that phrase meant. What I was pointing out was you were wrong. You used the phrase as if there were no other ways than those that you listed, however, there are multiple other ways and the page you linked to even mentioned one of them.

Thanks for guiding me to DllCall. I tried it now, but no luck with GetNextWindow().

But probably I am not alone ;)

AutoIt Forums > AutoIt v3 > v3 Support > Dll Call Question

Well, GetNextWindow() isn't real. It's a C pre-processor macro that wraps GetWindow() so just use GetWindow(). It's not very nice that MSDN doesn't mention that it's a macro, however. Replacing "GetNextWindow" with "GetWindow" in LxP's code will make his example work.
Link to comment
Share on other sites

Edit:

After I clarified my own small misperception about HWNDNEXT and HWNDPREV it really works as Valik stated.

Func IsOpenWindow( $h)

  Local $s
  
  $s= WinGetTitle( $h)
  If $s == "" Then Return 0
  
 ; capture strange windows like SysFader
  $s= WinGetClientSize( $h)
  If NOT $s[0] Then Return 0
  
  $s= WinGetState( $h)
    
  Return ( BitAND( $s, 18) == 2); visible and not minimized
EndFunc

Func GetOpenWindow()

  Local $dll, $h, $r
  
  $h= WinGetHandle( "")
  If IsOpenWindow( $h) Then return $h;
  
  $dll= DllOpen( "user32.dll"); open dll for multiple calls
  
  Do
    $r= DllCall( $dll, "hwnd", "GetWindow", "hwnd", $h, "int", 2)
    $h= $r[0]
    If NOT Dec($h) Then; null -- maybe this could be better coded
      $h= ""
      ExitLoop
    EndIf
    
  Until IsOpenWindow( $h)

  DllClose( $dll)
  Return $h
EndFunc  

$t0= TimerInit()
$h= GetOpenWindow(); 4 to 20 ms
$dt= TimerDiff( $t0)
MsgBox( 0, "GetOpenWindow", WinGetTitle($h) & @LF & $dt)

Thanks for your help.

-- Klaus

Edited by klaus.s
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

  • Recently Browsing   0 members

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