public static string GetWindowText(IntPtr hWnd, int length) { var titleStrBuild = new StringBuilder(length); User32Windows.GetWindowText(hWnd, titleStrBuild, length + 1); return(titleStrBuild.ToString()); }
public static List <DesktopWindow> GetDesktopWindows(bool visibleOnly = true, List <string> exceptNames = null, bool getIcons = true) { var collection = new List <DesktopWindow>(); Win32Callback AcquireMatchingWindows = delegate(IntPtr hWnd, IntPtr lParam) { Tuple <bool, string> isVisibleAndHasTitle = WindowVisibilityAndTitle(hWnd); var isVisible = isVisibleAndHasTitle.Item1; if (visibleOnly && (!isVisible)) { // Current window does not match, continue enumeration. return(true); } var title = isVisibleAndHasTitle.Item2; if (exceptNames != null && exceptNames.IndexOf(title) != -1) { return(true); } Icon icon = getIcons ? GetIcon(hWnd) : null; int processId; User32Windows.GetWindowThreadProcessId(hWnd, out processId); collection.Add(new DesktopWindow { Handle = hWnd, ProcessId = processId, Title = title, IsVisible = isVisible, Icon = icon }); return(true); }; EnumDesktopWindows(IntPtr.Zero, AcquireMatchingWindows, IntPtr.Zero); return(collection); }
public static void ShowForm(Form form) { form.Show(); User32Windows.ShowWindow(form.Handle, User32Windows.SW_RESTORE); User32Windows.SetForegroundWindow(form.Handle); }