public static void GetWindows() { OpenedWindows.Clear(); IntPtr shellWindow = Win32Wrapper.GetShellWindow(); Win32Wrapper.EnumWindows(delegate(IntPtr hWnd, int lParam) { if (hWnd == shellWindow) { return(true); } if (!Win32Wrapper.IsWindowVisible(hWnd)) { return(true); } int length = Win32Wrapper.GetWindowTextLength(hWnd); if (length == 0) { return(true); } Win32Wrapper.GetWindowThreadProcessId(hWnd, out IntPtr processId); Process process = Process.GetProcessById(processId.ToInt32()); if (process.ProcessName == "WindowFinder") { return(true); } StringBuilder titleBldr = new StringBuilder(length); Win32Wrapper.GetWindowText(hWnd, titleBldr, length + 1); OpenedWindows.Add(new WindowInfo(titleBldr.ToString(), process.ProcessName, process.Id, hWnd)); return(true); }, 0); }
protected override void OnSourceInitialized(EventArgs e) { var handle = new WindowInteropHelper(this).Handle; HwndSource source = HwndSource.FromHwnd(handle); source.AddHook(new HwndSourceHook(WndProc)); Win32Wrapper.RegisterHotKey(handle, HOTKEY_ID, WIN_MODIFIER, VK_ESCAPE); }
private void BringToFront() { var selected = (WindowInfo)WindowsGrid.SelectedItem; if (selected == null) { return; } var handle = selected.WindowHandle; if (Win32Wrapper.IsIconic(handle)) { Win32Wrapper.ShowWindow(handle, SW_MAXIMIZE); } Win32Wrapper.SetForegroundWindow(handle); }