Find window below window.

Get help with using AutoHotkey and its commands and hotkeys
User avatar
dangerdogL2121
Posts: 173
Joined: 01 Oct 2013, 23:11

Find window below window.

13 Oct 2013, 18:40

I have looked and have not found any command to do anything with a second to active window, or a list of windows in top to bottom order or anything. I have a program that needs to find out if a window is second to top. I don't know but I hope there is a dll to do this.
thanks
User avatar
Blackholyman
Posts: 1281
Joined: 29 Sep 2013, 22:57
Facebook: socialjsz
Google: +Jszapp
Location: Denmark
Contact:

Re: Find window below window.

14 Oct 2013, 02:27

you can try this

Code: Select all

;~ http://msdn.microsoft.com/en-us/library/ms633515.aspx
DetectHiddenWindows, on

GW_HWNDNEXT=2 ; Returns a handle to the window below the given window.
GW_HWNDPREV=3 ; Returns a handle to the window above the given window.

hWnd := WinExist("A")

below := DllCall("GetWindow", "uint", hWnd, "uint", GW_HWNDNEXT)

WinGetPos, x,y,w,h, % "AHk_id " below
WinGetTitle, title, % "AHk_id " below
msgbox % X " and " y " and " w " and " h " and " title
return
This script by Lexikos also has a function that does this well...
User avatar
dangerdogL2121
Posts: 173
Joined: 01 Oct 2013, 23:11

Re: Find window below window.

14 Oct 2013, 08:55

The first thing I got was
50 and 50 and 132 and 38 and

And when I changed

Code: Select all

below := DllCall("GetWindow", "uint", hWnd, "uint", GW_HWNDNEXT)
to this

Code: Select all

below := DllCall("GetWindow", "uint", hWnd, "uint", GW_HWNDPREV)
I got this
0 and 0 and 0 and 0 and


I also tried modifying the script to this.

Code: Select all

;~ http://msdn.microsoft.com/en-us/library/ms633515.aspx
DetectHiddenWindows, on

GW_HWNDNEXT=2 ; Returns a handle to the window below the given window.
GW_HWNDPREV=3 ; Returns a handle to the window above the given window.

hWnd := WinExist("A")

Loop, 50
{
GW_HWNDNEXT=%A_Index%
below := DllCall("GetWindow", "uint", hWnd, "uint", GW_HWNDNEXT)
IfInString, below, Internet Explorer
msgbox, %below%
}

WinGetPos, x,y,w,h, % "AHk_id " below
WinGetTitle, title, % "AHk_id " below
msgbox % X " and " y " and " w " and " h " and " title
return
But it doesn't find any window with internet explorer.
Also I didn't get any message box from Lexikos's script, but I think I could modify it for me if I tried. It would be so nice if there was a simple command to do this.
thanks for your help
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Re: Find window below window.

14 Oct 2013, 10:44

i get 0 and 0 and 0 and 0 and M :lol:
guest3456
Posts: 2783
Joined: 09 Oct 2013, 10:31

Re: Find window below window.

14 Oct 2013, 12:50

WinGet,, List
http://www.autohotkey.com/docs/commands/WinGet.htm
List: Retrieves the unique ID numbers of all existing windows that match the specified WinTitle, WinText, ExcludeTitle, and ExcludeText (to retrieve all windows on the entire system, omit all four title/text parameters). Each ID number is stored in an array element whose name begins with OutputVar's own name, while OutputVar itself is set to the number of retrieved items (0 if none). For example, if OutputVar is MyArray and two matching windows are discovered, MyArray1 will be set to the ID of the first window, MyArray2 will be set to the ID of the second window, and MyArray itself will be set to the number 2. Windows are retrieved in order from topmost to bottommost (according to how they are stacked on the desktop). Hidden windows are included only if DetectHiddenWindows has been turned on. Within a function, to create an array that is global instead of local, declare MyArray as a global variable prior to using this command (the converse is true for assume-global functions).

User avatar
dangerdogL2121
Posts: 173
Joined: 01 Oct 2013, 23:11

Re: Find window below window.

14 Oct 2013, 16:24

That's it! :D :P :mrgreen:
I didn't think it would work just from looking at it because it said
Retrieves the unique ID numbers of all existing windows that match the specified WinTitle, WinText, ExcludeTitle, and ExcludeText
but I didn't realize that it finds all windows in top to bottom order and that ifleave the last four parameters blank it finds all the windows.

@Blackholyman
You probably thought I wanted something else. Thanks for your help.

@Guest3456
Thanks a million! :mrgreen:
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Re: Find window below window.

14 Oct 2013, 16:55

Apropos "but I didn't realize that it finds all windows in top to bottom order and that if leave the last four parameters blank it finds all the windows," i ran the following code, but then i got a blank message: :roll:

Code: Select all

WinGet, OutputVar, PID,
MsgBox % Outputvar
User avatar
dangerdogL2121
Posts: 173
Joined: 01 Oct 2013, 23:11

Re: Find window below window.

15 Oct 2013, 00:07

I almost posted once, but I closed the Internet Explorer window and had to restart again so this will be brief.
The problem is that you don't list a window title in your WinGet

This might be what you need

Code: Select all

WinGet, OutputVar, PID, A ;specifying "A" in the third parameter will give you the stats for the active(top) window.
MsgBox % Outputvar
I almost posted once, but I closed the Internet Explorer window and had to restart again so this will be brief.
Actually I saved some code for an example of WinGet, OutputVar, List
Try this out

Code: Select all

;A cool window list script made by dangerdogL2121
DetectHiddenWindows, Off
WinGet, OutputID, List
Loop
{
OutputID = % OutputID%A_Index%
if OutputID =
break
WinGetTitle, OutputTitle, ahk_id %OutputID%
WinGet, OutputPID, PID, ahk_id %OutputID%
text = %text%`nWindow number %A_Index%:`nWindow Name = %OutputTitle%`nWindow ID = %OutputID%`nWindow PID = %OutputPID%`n--------------------------------------
}
;next part added to show all window stats
Gui, add, edit, h500, %text%
Gui, Show, Center
Thanks again guys :mrgreen:
Last edited by dangerdogL2121 on 15 Oct 2013, 10:02, edited 1 time in total.
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Re: Find window below window.

15 Oct 2013, 08:26

not so cool :( gettin' error at line 11...

Code: Select all

;A cool window list script made by dangerdogL2121
DetectHiddenWindows, Off
WinGet, OutputID, List
Loop
{
OutputID = % OutputID%A_Index%
if OutputID =
break
WinGetTitle, OutputTitle, ahk_id %OutputID%
WinGet, OutputPID, PID, ahk_id %OutputID%
text = %text%`nWindow number %A_Index%:`nWindow Name = %OutputTitle%`nWindow ID = %OutputID%`nWindow PID = %OutputPID

%`n--------------------------------------
}
;next part added to show all window stats
Gui, add, edit, h500, %text%
Gui, Show, Center
User avatar
dangerdogL2121
Posts: 173
Joined: 01 Oct 2013, 23:11

Re: Find window below window.

15 Oct 2013, 10:04

Sorry about that. :(
I changed my code in my previous post. I think it will work now. :)

Return to “Ask For Help”

Who is online

Users browsing this forum: Google [Bot], yarsis and 199 guests