AutoHotkey Community

It is currently May 26th, 2012, 9:25 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: Activate Topmost Window
PostPosted: July 26th, 2005, 12:11 am 
Offline

Joined: July 25th, 2005, 10:20 pm
Posts: 139
Location: Richmond, Virginia
Of all windows listed on the taskbar, is there a way to activate the topmost? Below are two failed attempts.

Code:
^a::
GroupAdd, AllWindows, , , , Program Manager
WinActivate, ahk_group AllWindows
Return


Code:
^a::
WinGet, WindowList, List, , , Program Manager
WinActivate, ahk_id %WindowList1%
Return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 26th, 2005, 9:18 am 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
Dear Litmus Red,

This seams to work:
Code:
F2::
  WinGet, WindowList, List
  Loop %WindowList%
    {
      WinUID := WindowList%A_Index%
      WinGetTitle, WinTitle, ahk_id %WinUID%
      WinActivate, ahk_id %WinUID%
      ToolTip Window %A_Index% of %WindowList%`n%WinTitle%`n%WinUID%
      Sleep, 1500
    }
Return
Please have a look what you can use of it.

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 26th, 2005, 12:03 pm 
Offline

Joined: July 25th, 2005, 10:20 pm
Posts: 139
Location: Richmond, Virginia
Thanks for the help, Toralf. Your script helped me see how the WinGet function works in this situation. However, I haven't been able to modify your script to leave the topmost window active.

Here's an example of what I want. Supose the user has three windows open -- MSPaint, Notepad, and Internet Explorer. All three windows are visible, but none have the focus. Notepad was the last window to be active and is therefore on top. I want a script that will activate Notepad.


Last edited by Litmus Red on July 26th, 2005, 5:00 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 26th, 2005, 12:22 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
If you try this:
Code:
F2::
  WinGet, WindowList, List
  ToolTip
  List =
  Loop %WindowList%
    {
      WinUID := WindowList%A_Index%
      WinGetTitle, WinTitle, ahk_id %WinUID%
      List = %List%Window %A_Index% of %WindowList%`n%WinTitle%`n%WinUID%`n`n
    }
  ToolTip  %List%
Return
You will find the answer.

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 26th, 2005, 5:08 pm 
Offline

Joined: July 25th, 2005, 10:20 pm
Posts: 139
Location: Richmond, Virginia
Thanks again, Toralf. The second example helped.

The script below will activate the topmost, unminimized window when the user presses Ctrl + A.

Code:
^a::
WinGet, WindowList, List
WinActivate, ahk_id %WindowList2%
Return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 26th, 2005, 5:40 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
I'm not so sure. When I tried it on my machine. It was a lot of times the second in list. But once it was the 4th (I do not know what I did :). All previous windows had no title. So the savest way would be to take the first window in list that has a title. Making the beautiful 4-liner a 10-liner. :(

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 26th, 2005, 5:46 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
It might have been due to the tooltip

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 26th, 2005, 6:46 pm 
Offline

Joined: July 25th, 2005, 10:20 pm
Posts: 139
Location: Richmond, Virginia
Yeah. The tooltips are counted as windows. Your second script helped me figure this out.

There are also two invisible windows listed at all times. They might be the desktop and taskbar -- I'm not sure.

If there are no tooltips and at least one unminimized window, my last script seems to work fine on Windows 2000 and XP. However, I feel safer using your suggestion.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 26th, 2005, 11:54 pm 
Offline

Joined: July 25th, 2005, 10:20 pm
Posts: 139
Location: Richmond, Virginia
The following script accomodates tooltips and any other window objects without titles.

Code:
^a::
WinGet, WindowList, List
Loop %WindowList%
{
WinUID := WindowList%A_Index%
WinGetTitle, WinTitle, ahk_id %WinUID%
If WinTitle <>
Break
}
WinActivate, ahk_id %WinUID%
Return


Thanks so much Toralf!


Report this post
Top
 Profile  
Reply with quote  
PostPosted: December 21st, 2005, 11:04 am 
Offline

Joined: December 21st, 2005, 10:57 am
Posts: 1
Had used the script [above] by Litmus Red to activate the topmost window. Works in XP but not W98SE. Using AutoKey ver 1.0.40.11.

Is there any of the commands or syntax used not compatible with W98SE?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 21st, 2005, 2:45 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
It's probably because Windows 9x has some zero-size system window that gets activated instead. You could try examining the list of windows returned by "WinGet List" and choose a window other than the first to activate.

Example #2 on the WinGet page shows how to view the title of each window (for testing purposes).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 18th, 2006, 11:35 am 
I was trying to activate the topmpst window ONLY if the topmost window belongs to ahk_class WinDialog group.
Sounds easy but the various "successful" tries were both changing the windows order - setting the former window on top of the next window (not always thoguh) and I couldn't open start menu or other things.

Any way to find the topmost window, if belongs to my goup (ahk_class WinDialog group) and not activated to activate it????
If possible, I wanted to be able to open start menu and do other things that have nothing to do with that group.

some codes I was trying:

Code:
!F2::
WinGet, WindowList, List, ahk_class WinDialog
Loop %WindowList%
{
WinUID := WindowList%A_Index%
WinGetTitle, WinTitle, ahk_id %WinUID%
If WinTitle <>
Break
}
WinActivate, ahk_id %WinUID%
Return

on timer, I was trying:
Code:
;  IfWinExist, myprogram
  {
    WinGetTitle, Title, A
    if title =
    {   
      WinGet, WindowList, List, ahk_class WinDialog
      WinGetTitle, Title, A
      if title =     
      WinActivate, ahk_id %WindowList1%
      if title =     
      Sleep, 100     
      if title =
      WinGet, WindowList, List, ahk_class WinDialog     
      WinActivate, ahk_id %WindowList1%     
      Sleep, 600
    }
  }


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 19th, 2006, 1:28 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Rnon wrote:
Any way to find the topmost window, if belongs to my goup (ahk_class WinDialog group) and not activated to activate it?
Based on my limited understanding of the goal:

WinGet List can determine which window is at top of the stack.
WinGet ExStyle can determine which windows are set to be "always on top" (though that's probably not what you meant).
WinGetClass can get the class name of a particular window ID (such as ID would typically have been retrieved via "WinGet List").


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, Google [Bot], wolverineks and 60 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group