예제 #1
0
        private void PrepareCaptureMenuAsync(ContextMenu tsmiWindow, RoutedEventHandler handlerWindow)
        {
            tsmiWindow.Items.Clear();

            WindowsList       windowsList = new WindowsList();
            List <WindowInfo> windows     = null;

            windows = windowsList.GetVisibleWindowsList();

            TaskEx.Run(() =>
            {
                windows = windowsList.GetVisibleWindowsList();
            }, () =>
            {
                if (windows != null)
                {
                    foreach (WindowInfo window in windows)
                    {
                        string title = window.Text.Truncate(40, "...");
                        MenuItem mi  = new MenuItem()
                        {
                            Header = title
                        };
                        mi.Tag    = window;
                        mi.Click += handlerWindow;
                        tsmiWindow.Items.Add(mi);
                    }
                }
            }
                       );
        }
예제 #2
0
        private void PrepareWindowsMenu(ToolStripMenuItem tsmi, EventHandler handler)
        {
            tsmi.DropDownItems.Clear();

            WindowsList       windowsList = new WindowsList();
            List <WindowInfo> windows     = windowsList.GetVisibleWindowsList();

            foreach (WindowInfo window in windows)
            {
                string        title = window.Text.Truncate(50);
                ToolStripItem tsi   = tsmi.DropDownItems.Add(title);
                tsi.Click += handler;

                try
                {
                    using (Icon icon = window.Icon)
                    {
                        if (icon != null)
                        {
                            tsi.Image = icon.ToBitmap();
                        }
                    }
                }
                catch (Exception e)
                {
                    DebugHelper.WriteException(e);
                }

                tsi.Tag = window;
            }
        }
예제 #3
0
        private void PrepareCaptureMenuAsync(ToolStripMenuItem tsmiWindow, EventHandler handlerWindow, ToolStripMenuItem tsmiMonitor, EventHandler handlerMonitor)
        {
            tsmiWindow.DropDownItems.Clear();

            WindowsList       windowsList = new WindowsList();
            List <WindowInfo> windows     = null;

            TaskEx.Run(() =>
            {
                windows = windowsList.GetVisibleWindowsList();
            },
                       () =>
            {
                if (windows != null)
                {
                    foreach (WindowInfo window in windows)
                    {
                        try
                        {
                            string title      = window.Text.Truncate(50);
                            ToolStripItem tsi = tsmiWindow.DropDownItems.Add(title);
                            tsi.Tag           = window;
                            tsi.Click        += handlerWindow;

                            using (Icon icon = window.Icon)
                            {
                                if (icon != null && icon.Width > 0 && icon.Height > 0)
                                {
                                    tsi.Image = icon.ToBitmap();
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            DebugHelper.WriteException(e);
                        }
                    }
                }

                tsmiMonitor.DropDownItems.Clear();

                Screen[] screens = Screen.AllScreens;

                for (int i = 0; i < screens.Length; i++)
                {
                    Screen screen     = screens[i];
                    string text       = string.Format("{0}. {1}x{2}", i + 1, screen.Bounds.Width, screen.Bounds.Height);
                    ToolStripItem tsi = tsmiMonitor.DropDownItems.Add(text);
                    tsi.Tag           = screen.Bounds;
                    tsi.Click        += handlerMonitor;
                }

                tsmiWindow.Invalidate();
                tsmiMonitor.Invalidate();
            });
        }
예제 #4
0
        private void UpdateWindowListMenu()
        {
            cmsWindowList.Items.Clear();

            WindowsList       windowsList = new WindowsList(Handle);
            List <WindowInfo> windows     = windowsList.GetVisibleWindowsList();

            if (windows != null && windows.Count > 0)
            {
                List <ToolStripMenuItem> items = new List <ToolStripMenuItem>();

                foreach (WindowInfo window in windows)
                {
                    try
                    {
                        string            title      = window.Text;
                        string            shortTitle = title.Truncate(50, "...");
                        ToolStripMenuItem tsmi       = new ToolStripMenuItem(shortTitle);
                        tsmi.Click += (sender, e) => txtWindowTitle.Text = title;

                        using (Icon icon = window.Icon)
                        {
                            if (icon != null && icon.Width > 0 && icon.Height > 0)
                            {
                                tsmi.Image = icon.ToBitmap();
                            }
                        }

                        items.Add(tsmi);
                    }
                    catch (Exception e)
                    {
                        DebugHelper.WriteException(e);
                    }
                }

                cmsWindowList.Items.AddRange(items.OrderBy(x => x.Text).ToArray());
            }
        }
        public override void CaptureSelectedWindowGetList()
        {
            tsddbCoreSelectedWindow.DropDownItems.Clear();

            var windowsList           = new WindowsList();
            List <WindowInfo> windows = windowsList.GetVisibleWindowsList();

            foreach (WindowInfo window in windows)
            {
                string        title             = window.Text.Truncate(50);
                ToolStripItem tsiSelectedWindow = tsddbCoreSelectedWindow.DropDownItems.Add(title);
                tsiSelectedWindow.Click += tsiSelectedWindow_Click;

                using (Icon icon = window.Icon)
                {
                    if (icon != null)
                    {
                        tsiSelectedWindow.Image = icon.ToBitmap();
                    }
                }

                tsiSelectedWindow.Tag = window;
            }
        }