This is the entire code of my C# application, with a simple goal. I want to retrieve the open windows on the system, ordered by how they were recently opened, just like in the Alt-Tab list. The Alt-Tab list lists programs as they were last opened, so that pressing Alt-Tab and releasing only once will take you back to the last window you had opened. This code is for Windows 10. The code below does get the information I need, just not in the right order. Where should I look for the information I 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();
}
}
}
WS_EX_TOPMOST
extended window style will break the relationship between Z-order and activation history. – IInspectable