Click here to Skip to main content
15,881,380 members
Home / Discussions / C#
   

C#

 
AnswerRe: how to create three moving cars from different directions meeting at the junction PinPopular
OriginalGriff14-Jun-16 6:19
mveOriginalGriff14-Jun-16 6:19 
GeneralRe: how to create three moving cars from different directions meeting at the junction Pin
Kenneth Haugland14-Jun-16 6:52
mvaKenneth Haugland14-Jun-16 6:52 
GeneralRe: how to create three moving cars from different directions meeting at the junction Pin
OriginalGriff14-Jun-16 8:14
mveOriginalGriff14-Jun-16 8:14 
GeneralRe: how to create three moving cars from different directions meeting at the junction Pin
Kenneth Haugland14-Jun-16 8:30
mvaKenneth Haugland14-Jun-16 8:30 
GeneralRe: how to create three moving cars from different directions meeting at the junction Pin
OriginalGriff14-Jun-16 8:47
mveOriginalGriff14-Jun-16 8:47 
AnswerRe: how to create three moving cars from different directions meeting at the junction Pin
Pete O'Hanlon14-Jun-16 6:23
mvePete O'Hanlon14-Jun-16 6:23 
AnswerRe: how to create three moving cars from different directions meeting at the junction Pin
Matthew Hazlett15-Jun-16 9:58
Matthew Hazlett15-Jun-16 9:58 
QuestionError in listing open windows Pin
srikrishnathanthri13-Jun-16 20:08
srikrishnathanthri13-Jun-16 20:08 
Hello,

I am trying to get the list of open windows using C#, here is my code..
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace howto_list_desktop_windows
{
    static class DesktopWindowsStuff
    {
        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        private static extern bool IsWindowVisible(IntPtr hWnd);
         [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        private static extern bool IsIconic(IntPtr hWnd);
         [DllImport("user32.dll", EntryPoint = "GetWindowText",
        ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true)]
              private static extern int GetWindowText(IntPtr hWnd,
            StringBuilder lpWindowText, int nMaxCount);
        [DllImport("user32.dll", EntryPoint = "EnumDesktopWindows",
        ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true)]
        private static extern bool EnumDesktopWindows(IntPtr hDesktop,
            EnumDelegate lpEnumCallbackFunction, IntPtr lParam);
        // Define the callback delegate's type.
        private delegate bool EnumDelegate(IntPtr hWnd, int lParam);
        // Save window titles and handles in these lists.
        private static List<IntPtr> WindowHandles;
        private static List<string> WindowTitles;
        // Return a list of the desktop windows' handles and titles.
        public static void GetDesktopWindowHandlesAndTitles(
            out List<IntPtr> handles, out List<string> titles)
        {
            WindowHandles = new List<IntPtr>();
            WindowTitles = new List<string>();
            if (!EnumDesktopWindows(IntPtr.Zero, FilterCallback, IntPtr.Zero))
            {
                handles = null;
                titles = null;
            }
            else
            {
              //  handles = null;
              handles = WindowHandles;
              titles = WindowTitles;
            }
        }
        // We use this function to filter windows.
        // This version selects visible windows that have titles.
        private static bool FilterCallback(IntPtr hWnd, int lParam)
        {
            // Get the window's title.
            StringBuilder sb_title = new StringBuilder(1024);
            int length = GetWindowText(hWnd, sb_title, sb_title.Capacity);
            string title = sb_title.ToString();           
            // If the window is visible and has a title, save it.
            if (IsWindowVisible(hWnd) && string.IsNullOrEmpty(title) == false)
            {
           //exclude minimized windows
                if (IsIconic(hWnd) == false)
                { 
                    {
                        WindowHandles.Add(hWnd);
                        WindowTitles.Add(title);
                    }
                }
            }

            // Return true to indicate that we
            // should continue enumerating windows.
            return true;
        }
    }
}

But this gives some window names which are not open. For example its giving "Windows ShellExperienceHost", which running in task manager. and photos which is under suspended state in task manager.
My intention is simple to list open windows (excluding minimized windows).
How to get rid off these kind of errors ?
Please help me.
AnswerRe: Error in listing open windows Pin
Richard MacCutchan13-Jun-16 21:03
mveRichard MacCutchan13-Jun-16 21:03 
GeneralRe: Error in listing open windows Pin
srikrishnathanthri13-Jun-16 23:49
srikrishnathanthri13-Jun-16 23:49 
GeneralRe: Error in listing open windows Pin
Pete O'Hanlon14-Jun-16 0:37
mvePete O'Hanlon14-Jun-16 0:37 
AnswerRe: Error in listing open windows Pin
KumarArunR10-May-17 20:03
KumarArunR10-May-17 20:03 
QuestionRX - Creating a Retry with a timer, and catch the exceptions Pin
Kenneth Haugland13-Jun-16 8:45
mvaKenneth Haugland13-Jun-16 8:45 
QuestionSQL Server 2005 query that uses the IIF with style date bool ? Pin
Member 245846711-Jun-16 22:44
Member 245846711-Jun-16 22:44 
AnswerRe: SQL Server 2005 query that uses the IIF with style date bool ? Pin
OriginalGriff11-Jun-16 23:14
mveOriginalGriff11-Jun-16 23:14 
GeneralRe: SQL Server 2005 query that uses the IIF with style date bool ? Pin
Member 245846712-Jun-16 17:08
Member 245846712-Jun-16 17:08 
GeneralRe: SQL Server 2005 query that uses the IIF with style date bool ? Pin
OriginalGriff12-Jun-16 20:23
mveOriginalGriff12-Jun-16 20:23 
QuestionMouse click poisition vary after stretching the image c# Pin
Shithun NK10-Jun-16 23:09
Shithun NK10-Jun-16 23:09 
AnswerRe: Mouse click poisition vary after stretching the image c# Pin
OriginalGriff11-Jun-16 0:48
mveOriginalGriff11-Jun-16 0:48 
QuestionHow to know all windows are in minimized state Pin
srikrishnathanthri10-Jun-16 19:15
srikrishnathanthri10-Jun-16 19:15 
AnswerRe: How to know all windows are in minimized state Pin
OriginalGriff10-Jun-16 20:48
mveOriginalGriff10-Jun-16 20:48 
GeneralRe: How to know all windows are in minimized state Pin
srikrishnathanthri11-Jun-16 1:18
srikrishnathanthri11-Jun-16 1:18 
GeneralRe: How to know all windows are in minimized state Pin
OriginalGriff11-Jun-16 2:03
mveOriginalGriff11-Jun-16 2:03 
QuestionProblemas Na Conexão Win Forms Depois de Instalado Pin
Maylkon9-Jun-16 2:15
Maylkon9-Jun-16 2:15 
AnswerRe: Problemas Na Conexão Win Forms Depois de Instalado Pin
Chris Quinn9-Jun-16 2:28
Chris Quinn9-Jun-16 2:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.