c# - Retrieve order of open windows as ordered in the Alt-Tab list? -
this entire code of c# application, simple goal. want retrieve open windows on system, ordered how opened, in alt-tab list. alt-tab list lists programs last opened, pressing alt-tab , releasing once take last window had opened. code windows 10. code below information need, not in right order. should information need?
using system; using system.collections.generic; using system.diagnostics; using system.linq; using system.runtime.interopservices; using system.text; using system.threading.tasks; namespace getopenwindowname { class program { static void main(string[] args) { process[] processlist = process.getprocesses(); foreach (process process in processlist) { if (!string.isnullorempty(process.mainwindowtitle)) { console.writeline("process: {0} id: {1} window title: {2}", process.processname, process.id, process.mainwindowtitle); } } console.readline(); } } }
so, best able do, of @paulf, @stuartd, , @iinspectible.
the order of windows in alt-tab list z-order of windows. @iinspectible informs window set topmost break this, part, z-order can respected. so, need z-order of open windows.
first, need bring in external function getwindow, using these 2 lines:
[dllimport("user32.dll", setlasterror = true)] private static extern intptr getwindow(intptr hwnd, int nindex);
once function exists, can create function z-order:
public static int getzorder(process p) { intptr hwnd = p.mainwindowhandle; var z = 0; // 3 getwindowtype.gw_hwndprev (var h = hwnd; h != intptr.zero; h = getwindow(h, 3)) z++; return z; }
key point: 3 in call getwindow function flag:
/// <summary> /// retrieved handle identifies window above specified window in z order. /// <para /> /// if specified window topmost window, handle identifies topmost window. /// if specified window top-level window, handle identifies top-level window. /// if specified window child window, handle identifies sibling window. /// </summary> gw_hwndprev = 3,
these building blocks finding z-order of windows process list, (for part) alt-tab order is.
Comments
Post a Comment