Esempio n. 1
0
        /// <summary>すべてのウィンドウを列挙します</summary>
        public static HWND[] GetWindows()
        {
            List <HWND> res = new List <HWND>();

            NativeMethod.EnumWindows(
                new EnumWindowsProc(
                    (hwnd, lParam) =>
            {
                res.Add(new HWND(hwnd));
                return(true);
            }),
                IntPtr.Zero).CheckError();
            return(res.ToArray());
        }
Esempio n. 2
0
        /// <summary>ウインドウハンドルの列挙</summary>
        public static IntPtr[] EnumWinHandle()
        {
            var handles = new List <IntPtr>();

            //ウィンドウを列挙する
            NativeMethod.EnumWindows((hWnd, lParam) =>
            {
                String name = GetWindowText(hWnd);
                if (name.Length > 0)
                {
                    handles.Add(hWnd);
                }
                return(true);
            }, IntPtr.Zero);

            return(handles.ToArray());
        }
Esempio n. 3
0
        /// <summary>
        /// ウインドウ名の列挙
        /// </summary>
        public static String[] EnumWinName()
        {
            var windowNames = new List <String>();

            //ウィンドウを列挙する
            NativeMethod.EnumWindows((hWnd, lParam) =>
            {
                String name = GetWindowText(hWnd);
                if (name.Length > 0)
                {
                    windowNames.Add(name);
                }
                return(true);
            }, IntPtr.Zero);

            return(windowNames.ToArray());
        }
Esempio n. 4
0
 private void button1_Click(object sender, EventArgs e)
 {
     listBox1.Items.Clear();
     NativeMethod.EnumWindows((wnd, param) =>
     {
         if (NativeMethod.IsWindowVisible(wnd) == NativeMethod.TRUE)
         {
             StringBuilder szClass = new StringBuilder(256);
             NativeMethod.GetClassName(wnd, szClass, 256);
             StringBuilder szTitle = new StringBuilder(256);
             NativeMethod.GetWindowText(wnd, szTitle, 256);
             ulong thread = 0;
             NativeMethod.GetWindowThreadProcessId(wnd, ref thread);
             Process p = Process.GetProcessById((int)thread);
             listBox1.Items.Add(
                 $@"{p.ProcessName}({thread}):{szTitle}:{szClass}");
         }
         return(true);
     }, 0);
 }