Beispiel #1
0
        private void ChildWindow(WndNode parent)
        {
            Win32.EnumChildWindows(parent.hWnd, (Win32.EnumWindowsProc) delegate(IntPtr hwnd, IntPtr lParam)
            {
                processTaskCancelToken.Token.ThrowIfCancellationRequested();

                RECT rect = new RECT();
                Win32.GetWindowRect(hwnd, ref rect);
                if ((rect.right - rect.left) <= 0 || (rect.bottom - rect.top) <= 0)
                {
                    return(true);
                }
                if (Win32.IsWindowVisible(hwnd) == false)
                {
                    return(true);
                }
                if (Win32.IsIconic(hwnd) == true)
                {
                    return(false);
                }

                var text      = new StringBuilder(1024);
                var childWnd  = new WndNode();
                childWnd.PID  = 0;
                childWnd.hWnd = hwnd;
                if (Win32.GetWindowText(hwnd, text, 1024) != 0)
                {
                    childWnd.Text = text.ToString();
                }
                else if (Win32.GetClassName(hwnd, text, 1024) != 0)
                {
                    childWnd.Text = text.ToString();
                }
                else
                {
                    childWnd.Text = "<unknow>";
                }
                if (Win32.IsWindowVisible(hwnd) == true)
                {
                    this.Invoke((SimpleDelegate) delegate()
                    {
                        parent.Nodes.Add(childWnd);
                    });
                    ChildWindow(childWnd);
                }
                this.Invoke((SimpleDelegate) delegate()
                {
                    m_stLabelState.Text = text.ToString();
                });

                return(true);
            }, IntPtr.Zero);
        }
Beispiel #2
0
 private void UpdateImage(WndNode node)
 {
     if (node == null)
     {
         return;
     }
     if (previewImage != null)
     {
         previewImage.Dispose();
         previewImage = null;
     }
     previewImage = node.GetImage();
     m_pnlPreview.Refresh();
 }
Beispiel #3
0
        private void RefreshTree()
        {
            m_btnRefresh.Enabled = false;
            m_btnOK.Enabled      = false;
            m_btnCancel.Enabled  = false;
            m_treeProcess.Nodes.Clear();
            processTaskCancelToken = new CancellationTokenSource();

            processTask = new Task((Action) delegate()
            {
                processTaskCancelToken.Token.ThrowIfCancellationRequested();

                var processes = Process.GetProcesses();
                foreach (var process in processes)
                {
                    var wnd  = new WndNode();
                    wnd.PID  = process.Id;
                    wnd.hWnd = process.MainWindowHandle;
                    wnd.Text = process.ProcessName;
                    this.Invoke((SimpleDelegate) delegate()
                    {
                        m_stLabelState.Text = process.ProcessName;
                    });
                    var result = Win32.EnumWindows((Win32.EnumWindowsProc) delegate(IntPtr hwnd, IntPtr lParam)
                    {
                        RECT rect = new RECT();
                        Win32.GetWindowRect(hwnd, ref rect);
                        if ((rect.right - rect.left) <= 0 || (rect.bottom - rect.top) <= 0)
                        {
                            return(true);
                        }

                        if (Win32.IsWindowVisible(hwnd) == false)
                        {
                            return(true);
                        }

                        if (Win32.IsIconic(hwnd) == true)
                        {
                            return(true);
                        }

                        uint pid = 0;
                        Win32.GetWindowThreadProcessId(hwnd, out pid);
                        if (pid == (uint)lParam)
                        {
                            wnd.hWnd = hwnd;
                            return(false);
                        }
                        return(true);
                    }, new IntPtr(wnd.PID));

                    if (wnd.hWnd != IntPtr.Zero && Win32.IsWindowVisible(wnd.hWnd) == true)
                    {
                        // 子ウィンドウも対象する
                        ChildWindow(wnd);
                        this.Invoke((SimpleDelegate) delegate()
                        {
                            m_treeProcess.Nodes.Add(wnd);
                        });
                    }
                }
            }, processTaskCancelToken.Token);
            processTask.ContinueWith((Action <Task>) delegate(Task t)
            {
                this.Invoke((SimpleDelegate) delegate()
                {
                    m_btnRefresh.Enabled = true;
                    m_btnOK.Enabled      = true;
                    m_btnCancel.Enabled  = true;
                    if (t.IsCanceled == true)
                    {
                        m_stLabelState.Text = "キャンセルされました";
                    }
                    if (t.IsFaulted == true)
                    {
                        m_stLabelState.Text = "異常終了";
                    }
                    else
                    {
                        m_stLabelState.Text = "完了";
                    }
                });
            });
            processTask.Start();
        }