//[DllImport("user32.dll")]
        //private static extern IntPtr GetForegroundWindow();

        internal bool EnumWindowProc(IntPtr handle, IntPtr lParam)
        {
            var ws = new WindowController(handle);

            ws_list.Add(ws);
            return(true);
        }
 private static bool EnumWindowCallBack(IntPtr hWnd, IntPtr lparam)
 {
     lock (top_ws_list_lock)
     {
         if (_window_system != null)
         {
             var ws = new WindowController(hWnd);
             _window_system.top_ws_list.Add(ws);
         }
     }
     return(true);
 }
        public WindowControllerManager(string title)
        {
            _window_system = this;
            top_ws         = GetTopWindowStatusList(title); // titleが一致するウィンドウを探す

            if (top_ws == null)
            {
                return;
            }

            // 子ウィンドウをサブ含めて収集する
            {
                var ws = new WindowController(top_ws.hWnd);
                ws_list.Add(ws);
                EnumChildWindows(ws.hWnd, EnumWindowProc, default(IntPtr));
            }

            // 親子関係を把握する
            foreach (var ws in ws_list)
            {
                var top_chiled_h = GetWindow(ws.hWnd, (UInt32)GW.GW_CHILD);
                if ((uint)top_chiled_h != 0)
                {
                    var chiled_h = top_chiled_h;
                    while ((uint)chiled_h != 0)
                    {
                        foreach (var ws2 in ws_list)
                        {
                            if (ws2.hWnd == chiled_h)
                            {
                                ws2.owner = ws;
                                break;
                            }
                        }
                        chiled_h = GetWindow(chiled_h, (UInt32)GW.GW_HWNDNEXT);
                    }
                }
            }
        }