Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

How to get the id of the next or previous window in Z order?


  • Please log in to reply
6 replies to this topic
yaugenka
  • Members
  • 3 posts
  • Last active: Dec 13 2009 06:11 PM
  • Joined: 27 Aug 2008
Hi, everyone

How to retrieve the id of the next or previous window in Z order?

Thanks

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

How to retrieve the id of the next or previous window in Z order?


Short answer: GetWindow Function ()

But I guess, you need to look in to the following topic: AltTab_window_list() - get a list of alt-tab windows posted by evl

:)
kWo4Lk1.png

yaugenka
  • Members
  • 3 posts
  • Last active: Dec 13 2009 06:11 PM
  • Joined: 27 Aug 2008
The script below is supposed to activate the next window in the z order when you press Esc.
Does anyone see where the mistake is?


Esc::
hwnd := WinActive("A")
hNextWindow := DllCall("GetWindow","uint",hwnd,"uint",2)
WinActivate, ahk_id %hNextWindow%
return

Thanks for reply

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

Does anyone see where the mistake is?


hNextWindow could be the ID of a hidden window.. even a Tooltip is a window. You need to filter out unneeded window IDs.

There was a reason for me to point to evl's topic.

:)
kWo4Lk1.png

yaugenka
  • Members
  • 3 posts
  • Last active: Dec 13 2009 06:11 PM
  • Joined: 27 Aug 2008
Thanks for directing me, SKAN

Here is the correct scrip:

Esc::
hwnd := WinActive("A")
Loop
{
hwnd := DllCall("GetWindow",uint,hwnd,int,2) ; 2 = GW_HWNDNEXT
; GetWindow() returns a decimal value, so we have to convert it to hex
SetFormat,integer,hex
hwnd += 0
SetFormat,integer,d
; GetWindow() processes even hidden windows, so we move down the z oder until the next visible window is found
if (DllCall("IsWindowVisible",uint,hwnd) = 1)
break
}
WinActivate,ahk_id %hwnd%
return


Serenity
  • Members
  • 1271 posts
  • Last active:
  • Joined: 07 Nov 2004
GW_HWNDFIRST = 0

GW_HWNDLAST = 1

GW_HWNDNEXT = 2

GW_HWNDPREV = 3

GW_OWNER = 4

GW_CHILD = 5

GW_ENABLEDPOPUP = 6

GW_MAX = 6

"Anything worth doing is worth doing slowly." - Mae West
Posted Image

Crash&Burn
  • Members
  • 228 posts
  • Last active: Jul 16 2014 10:10 PM
  • Joined: 02 Aug 2009
Snippet above was useful to me recently.

I was trying to figure out how to make Total Commander be accessible to input when one of it's modal dialogs was open, e.g. Find Files or the like -- without closing the dialog.

My initial attempts were really hackish and didn't work either! Searching for modify modal, change modal, or remove modal, etc just brought forth a lot of noise for the most part. This page gave me a good hint on how to proceed:
Convert modeless dialogs to modal
Here's my snippet:
TC_WinEnableParent(wID, childID="", onOFF=TRUE)
{
	if( (ownerID:=wID) && !childID )
	{
		childID:=DllCall("GetWindow", "uint", wID,    "int",3)	; 3 == GW_PREV
		ownerID:=DllCall("GetWindow", "uint", childID,"int",4)	; 4 == GW_OWNER
	}
	if( ownerID <> wID || childID == -1 )
		return -1
	WinSet, % (onOFF ? "Enable"  : "Disable"),, ahk_id %ownerID%
	WinSet, % (onOFF ? "Disable" : "Enable" ),, ahk_id %childID%
	ControlSend,, % (onOFF ? "{ESC}" : ""),  ahk_id %ownerID%
return childID
}
Initial call would provide the HWND (ahk_id) of the main window. And will Enable the main window, and disable it's child.
Example:

childID:=TC_WinEnableParent(tcHwnd, childID:="" )
;When reenabling the child, and disabling TC:
TC_WinEnableParent(wID, childID, FALSE)


It's possible one would need to verify the child window is visible, but that doesn't appear to be necessary in this case.

I also used this bit, to find the "next" window after the child, when I was initially hiding the child. I found odd behaviour on showing the child, it would also display the next window overlayed on top...

nextID:=childID, i:=0
	while( nextID:=DllCall("GetWindow", "uint", nextID,"int",2))
	{
;		TooltipMsg("while: " (++i))
		if( (nextID <> wID) && DllCall("IsWindowVisible","uint",nextID) )
			break
	}
	WinSet, Bottom,, ahk_id %nextID%
	WinSet, Disable,, ahk_id %childID%
	WinHide, ahk_id %childID%
Then when I WinShow, ahk_id %childID% later, the "next" window didn't show up.