Ejemplo n.º 1
0
        /// <summary>
        /// 一番上にあるウインドウを指定された位置と大きさに配置
        /// </summary>
        /// <param name="positon"></param>
        public static void RelocateTop(Rectangle positon)
        {
            int thisProcessId = -1;// System.Diagnostics.Process.GetCurrentProcess().Id;


            WindowInformation window = null;


            WindowPlacement.EnumWindows((handle, parameter) =>
            {
                var sb = new StringBuilder(0x1024);
                if (WindowPlacement.IsWindowVisible(handle) != 0 &&
                    WindowPlacement.GetWindowText(handle, sb, sb.Capacity) != 0)
                {
                    var id = (int)WindowPlacement.GetWindowThreadProcessId(handle, IntPtr.Zero);

                    if (thisProcessId < 0)
                    {
                        thisProcessId = id;
                    }
                    else if (id != thisProcessId)
                    {
                        window = new WindowInformation()
                        {
                            Title  = sb.ToString(),
                            Handle = handle,
                            Id     = id,
                        };

                        return(0);
                    }
                }
                return(1);
            }, 0);

            if (window != null)
            {
                window.Relocate(positon);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 全ウインドウを列挙
        /// </summary>
        /// <returns></returns>
        public static List <WindowInformation> EnumerateWindows()
        {
            var windows = new List <WindowInformation>();

            WindowPlacement.EnumWindows((handle, parameter) =>
            {
                var sb = new StringBuilder(0x1024);

                if (WindowPlacement.IsWindowVisible(handle) != 0 &&
                    WindowPlacement.GetWindowText(handle, sb, sb.Capacity) != 0)
                {
                    var window = new WindowInformation()
                    {
                        Title  = sb.ToString(),
                        Handle = handle,
                        Id     = (int)WindowPlacement.GetWindowThreadProcessId(handle, IntPtr.Zero),
                    };

                    var title = sb.ToString();

                    if (windows.Count == 0 ||
                        windows.Last().Id != window.Id ||
                        windows.Last().Title != window.Title)
                    {
                        windows.Add(window);
                    }
                }
                return(1);
            }, 0);

            if (windows.Count > 0 && windows.Last().Title == "Program Manager")
            {
                windows.RemoveAt(windows.Count - 1);
            }

            return(windows);
        }