private bool ListWindows(IntPtr hWnd, int lParam) { if (!WindowsApi.IsWindowVisible(hWnd)) { return(true); } if ((WindowsApi.GetWindowLong(hWnd, GWL_EXSTYLE) & WS_EX_APPWINDOW) != WS_EX_APPWINDOW) { if (WindowsApi.GetWindow(hWnd, GW_OWNER) != IntPtr.Zero) { return(true); } if ((WindowsApi.GetWindowLong(hWnd, GWL_EXSTYLE) & WS_EX_TOOLWINDOW) == WS_EX_TOOLWINDOW) { return(true); } if ((WindowsApi.GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD) == WS_CHILD) { return(true); } } int length = WindowsApi.GetWindowTextLength(hWnd); var sb = new StringBuilder(length + 1); WindowsApi.GetWindowText(hWnd, sb, sb.Capacity); _handleList.Add(hWnd); windowList.Items.Add(sb.ToString()); return(true); }