Esempio n. 1
0
        /// <summary>
        /// 現在存在するすべてのトップレベルウィンドウを取得
        /// </summary>
        static public WindowHandle[] FindWindows()
        {
            if (myEnumWindowsDelegate == null)
            {
                myEnumWindowsDelegate = new WinApi.EnumWindowsDelegate(EnumCallback);
            }

            hWndList.Clear();
            //WinApi.EnumWindows(new WinApi.EnumWindowsDelegate(delegate (IntPtr hWnd, IntPtr lParam)
            WinApi.EnumWindows(myEnumWindowsDelegate, IntPtr.Zero);

            List <WindowHandle> windowList = new List <WindowHandle>();

            foreach (IntPtr hwnd in hWndList)
            {
                if (WinApi.IsWindow(hwnd))
                {
                    WindowHandle window = new WindowHandle(hwnd);
                    windowList.Add(window);
                }
            }
            return(windowList.ToArray());
        }