private static bool Filter(int hwnd, int lparam, out ApplicationWindow window) { window = null; var iHwnd = new IntPtr(hwnd); var title = new StringBuilder(256); User32.GetWindowText(hwnd, title, 256); var t = title.ToString(); //Skip if the window does not have a caption. if (t.Length == 0) { return(true); } //Skip if parent is not the desktop. var parentHwnd = User32.GetParent(iHwnd); if (!parentHwnd.Equals(new IntPtr(0))) { return(true); } if (!User32.KeepWindowHandleInAltTabList(iHwnd)) { return(true); } //Skip if the window is not visible but not minimized and has SW_HIDE (0) style. var placement = new WINDOWPLACEMENT(); User32.GetWindowPlacement(iHwnd, ref placement); if (!User32.IsWindowVisible(hwnd) && !User32.IsIconic(iHwnd) && placement.flags == 0) { return(true); } var info = new WINDOWINFO(); info.cbSize = (uint)Marshal.SizeOf(info); User32.GetWindowInfo(iHwnd, ref info); //skip window if it's really small (usually an indicator it's not a alt tab candidate window. if (info.rcWindow.Width <= 10 && info.rcWindow.Height <= 10) { return(true); } window = ApplicationWindows.GetApplicationWindow(hwnd, lparam); return(true); }
private static ApplicationWindow GetApplicationWindow(int hwnd, int lparam) { var iHwnd = new IntPtr(hwnd); var title = new StringBuilder(256); User32.GetWindowText(hwnd, title, 256); var t = title.ToString(); uint processId = 0; User32.GetWindowThreadProcessId(iHwnd, out processId); var fileName = User32.GetWindowModuleFileNameFromHandle(iHwnd); var window = new ApplicationWindow(t, iHwnd, (int)processId, fileName); return(window); }
public static ApplicationWindow FindWindowByCaption(string caption) { ApplicationWindow window = null; var ewp = new User32.EnumWindowsProc((hwnd, lparam) => { var w = ApplicationWindows.GetApplicationWindow(hwnd, lparam); if (w != null && w.Title.Equals(caption, StringComparison.InvariantCulture)) { window = w; } return(window == null); //continue as long as window == null; }); User32.EnumWindows(ewp, 0); return(window); }
private static IEnumerable <ApplicationWindow> FindAltTabableWindows() { var windows = new List <ApplicationWindow>(); var ewp = new User32.EnumWindowsProc((hwnd, lparam) => { ApplicationWindow window = null; var shouldContinue = ApplicationWindows.Filter(hwnd, lparam, out window); if (window != null) { windows.Add(window); } return(shouldContinue); }); User32.EnumWindows(ewp, 0); return(windows.DistinctBy(w => w.hWnd)); }
private static ApplicationWindow GetApplicationWindow(int hwnd, int lparam) { var iHwnd = new IntPtr(hwnd); StringBuilder title = new StringBuilder(256); User32.GetWindowText(hwnd, title, 256); var t = title.ToString(); uint processId = 0; User32.GetWindowThreadProcessId(iHwnd, out processId); var fileName = User32.GetWindowModuleFileNameFromHandle(iHwnd); var window = new ApplicationWindow(t, iHwnd, (int)processId, fileName); return window; }
private static bool Filter(int hwnd, int lparam, out ApplicationWindow window) { window = null; var iHwnd = new IntPtr(hwnd); StringBuilder title = new StringBuilder(256); User32.GetWindowText(hwnd, title, 256); var t = title.ToString(); //Skip if the window does not have a caption. if (t.Length == 0) return true; //Skip if parent is not the desktop. var parentHwnd = User32.GetParent(iHwnd); if (!parentHwnd.Equals(new IntPtr(0))) return true; if (!User32.KeepWindowHandleInAltTabList(iHwnd)) return true; //Skip if the window is not visible but not minimized and has SW_HIDE (0) style. var placement = new WINDOWPLACEMENT(); User32.GetWindowPlacement(iHwnd, ref placement); if (!User32.IsWindowVisible(hwnd) && !User32.IsIconic(iHwnd) && placement.flags == 0) return true; var info = new WINDOWINFO(); info.cbSize = (uint)Marshal.SizeOf(info); User32.GetWindowInfo(iHwnd, ref info); //skip window if it's really small (usually an indicator it's not a alt tab candidate window. if (info.rcWindow.Width <= 10 && info.rcWindow.Height <= 10) return true; window = ApplicationWindows.GetApplicationWindow(hwnd, lparam); return true; }
public static ApplicationWindow GetNthApplicationWindowOnNotificationArea(IntPtr notificationAreaHwnd, int i) { TBBUTTON tbButton = new TBBUTTON(); string text = String.Empty; IntPtr ipWindowHandle = IntPtr.Zero; NotificationAreaWindow notificationAreaWindow; bool b = User32.GetTBButton(notificationAreaHwnd, i, ref tbButton, ref text, ref ipWindowHandle, out notificationAreaWindow); if (!b) return null; //if (!User32.KeepWindowHandleInAltTabList(notificationAreaWindow.MainWindowHandle)) //return null; /*if (hash.Contains(notificationAreaWindow.MainWindowHandle)) return null; hash.Add(notificationAreaWindow.MainWindowHandle);*/ uint processId = 0; User32.GetWindowThreadProcessId(notificationAreaWindow.MainWindowHandle, out processId); if (processId == 0) return null; if (processId == App.ProcessId) return null; var fileName = User32.GetWindowModuleFileNameFromHandle(notificationAreaWindow.MainWindowHandle); if (fileName.ToLower().EndsWith("explorer.exe")) return null; var window = new ApplicationWindow((int)processId, fileName, notificationAreaWindow); return window; }