Get a Z-Order Window with a Windows Python Extension

Is there a way to get the z-order of windows using Python Windows Extensions ? Or, alternatively, is there a way to do this using another module? The usual way to do this is GetTopWindow and GetNextWindow , but none of these functions appear in the win32gui module.

I am currently doing this, but it does not take into account the z-order of the windows:

 import win32gui def get_windows(): def callback(hwnd, lst): lst.append(hwnd) lst = [] win32gui.EnumWindows(callback, lst) return lst 

Ideally, I would like something like this: (this does not work)

 import win32gui import win32con def get_windows(): '''Returns windows in z-order (top first)''' lst = [] top = win32gui.GetTopWindow() if top is None: return lst lst.append(top) while True: next = win32gui.GetNextWindow(lst[-1], win32con.GW_HWNDNEXT) if next is None: break lst.append(next) return lst 

However, the GetTopWindow and GetNextWindow missing, so I cannot.

UPDATE:

I think I asked for help too quickly. I figured this out with ctypes. Hope someone finds this helpful.

 import win32con import ctypes def get_windows(): '''Returns windows in z-order (top first)''' user32 = ctypes.windll.user32 lst = [] top = user32.GetTopWindow(None) if not top: return lst lst.append(top) while True: next = user32.GetWindow(lst[-1], win32con.GW_HWNDNEXT) if not next: break lst.append(next) return lst 
+4
source share

All Articles