Get window information - CSharp System

CSharp examples for System:Windows

Description

Get window information

Demo Code


using System;/*from w w  w. java  2s . co  m*/
using System.Text;
using System.Runtime.InteropServices;

class MainClass
    {
        public delegate bool CallBack(IntPtr hwnd, int lParam);

        [DllImport("user32.dll")]
        public static extern int EnumWindows(CallBack callback, int param);

        [DllImport("user32.dll")]
        public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);

        static void Main(string[] args)
        {
            EnumWindows(new CallBack(DisplayWindowInfo), 0);

        }

        public static bool DisplayWindowInfo(IntPtr hWnd, int lParam)
        {
            int chars = 100;
            StringBuilder buf = new StringBuilder(chars);
            if (GetWindowText(hWnd, buf, chars) != 0)
            {
                Console.WriteLine(buf);
            }
            return true;
        }
    }

Result


Related Tutorials